diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-24 12:05:08 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-24 12:05:08 +0900 |
commit | 561fd0ebb696deb0edcd07d0261cd078c4d14e77 (patch) | |
tree | 0567e8ff7807289558e513cd4c34b7c9ba65c01d | |
parent | de2a7086a710301319d170e2a75269be1de04df9 (diff) | |
download | plum-561fd0ebb696deb0edcd07d0261cd078c4d14e77.tar.gz |
test: fix
-rw-r--r-- | test/hpack_decoder_test.rb | 44 | ||||
-rw-r--r-- | test/hpack_huffman_test.rb | 8 | ||||
-rw-r--r-- | test/server_state_test.rb | 10 |
3 files changed, 34 insertions, 28 deletions
diff --git a/test/hpack_decoder_test.rb b/test/hpack_decoder_test.rb index b1532b0..399ffa5 100644 --- a/test/hpack_decoder_test.rb +++ b/test/hpack_decoder_test.rb @@ -3,52 +3,52 @@ require "test_helper" class HPACKDecoderTest < Minitest::Test # C.1.1 def test_hpack_read_integer_small - buf = [0b11001010, 0b00001111].pack("C*").b + buf = [0b11001010, 0b00001111].pack("C*") result = new_decoder.__send__(:read_integer!, buf, 5) assert_equal(10, result) - assert_equal([0b00001111].pack("C*").b, buf) + assert_equal([0b00001111].pack("C*"), buf) end # C.1.2 def test_hpack_read_integer_big - buf = [0b11011111, 0b10011010, 0b00001010, 0b00001111].pack("C*").b + buf = [0b11011111, 0b10011010, 0b00001010, 0b00001111].pack("C*") result = new_decoder.__send__(:read_integer!, buf, 5) assert_equal(1337, result) - assert_equal([0b00001111].pack("C*").b, buf) + assert_equal([0b00001111].pack("C*"), buf) end # C.1.3 def test_hpack_read_integer_8prefix - buf = [0b00101010, 0b00001111].pack("C*").b + buf = [0b00101010, 0b00001111].pack("C*") result = new_decoder.__send__(:read_integer!, buf, 8) assert_equal(42, result) - assert_equal([0b00001111].pack("C*").b, buf) + assert_equal([0b00001111].pack("C*"), buf) end # C.2.1 def test_hpack_decode_indexing - encoded = "\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0d\x63\x75\x73\x74\x6f\x6d\x2d\x68\x65\x61\x64\x65\x72".b + encoded = "\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0d\x63\x75\x73\x74\x6f\x6d\x2d\x68\x65\x61\x64\x65\x72" result = new_decoder.decode(encoded) assert_equal([["custom-key", "custom-header"]], result) end # C.2.2 def test_hpack_decode_without_indexing - encoded = "\x04\x0c\x2f\x73\x61\x6d\x70\x6c\x65\x2f\x70\x61\x74\x68".b + encoded = "\x04\x0c\x2f\x73\x61\x6d\x70\x6c\x65\x2f\x70\x61\x74\x68" result = new_decoder.decode(encoded) assert_equal([[":path", "/sample/path"]], result) end # C.2.3 def test_hpack_decode_without_indexing2 - encoded = "\x10\x08\x70\x61\x73\x73\x77\x6f\x72\x64\x06\x73\x65\x63\x72\x65\x74".b + encoded = "\x10\x08\x70\x61\x73\x73\x77\x6f\x72\x64\x06\x73\x65\x63\x72\x65\x74" result = new_decoder.decode(encoded) assert_equal([["password", "secret"]], result) end # C.2.4 def test_hpack_decode_index - encoded = "\x82".b + encoded = "\x82" result = new_decoder.decode(encoded) assert_equal([[":method", "GET"]], result) end @@ -56,7 +56,7 @@ class HPACKDecoderTest < Minitest::Test # C.3.1 def test_hpack_decode_headers_without_huffman decoder = new_decoder - encoded = "\x82\x86\x84\x41\x0f\x77\x77\x77\x2e\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d".b + encoded = "\x82\x86\x84\x41\x0f\x77\x77\x77\x2e\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -72,7 +72,7 @@ class HPACKDecoderTest < Minitest::Test # C.3.2 def test_hpack_decode_headers_without_huffman2 decoder = test_hpack_decode_headers_without_huffman - encoded = "\x82\x86\x84\xbe\x58\x08\x6e\x6f\x2d\x63\x61\x63\x68\x65".b + encoded = "\x82\x86\x84\xbe\x58\x08\x6e\x6f\x2d\x63\x61\x63\x68\x65" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -89,7 +89,7 @@ class HPACKDecoderTest < Minitest::Test # C.3.3 def test_hpack_decode_headers_without_huffman3 decoder = test_hpack_decode_headers_without_huffman2 - encoded = "\x82\x87\x85\xbf\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0c\x63\x75\x73\x74\x6f\x6d\x2d\x76\x61\x6c\x75\x65".b + encoded = "\x82\x87\x85\xbf\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0c\x63\x75\x73\x74\x6f\x6d\x2d\x76\x61\x6c\x75\x65" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -104,7 +104,7 @@ class HPACKDecoderTest < Minitest::Test # C.4.1 def test_hpack_decode_headers_with_huffman decoder = new_decoder - encoded = "\x82\x86\x84\x41\x8c\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff".b + encoded = "\x82\x86\x84\x41\x8c\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -120,7 +120,7 @@ class HPACKDecoderTest < Minitest::Test # C.4.2 def test_hpack_decode_headers_with_huffman2 decoder = test_hpack_decode_headers_with_huffman - encoded = "\x82\x86\x84\xbe\x58\x86\xa8\xeb\x10\x64\x9c\xbf".b + encoded = "\x82\x86\x84\xbe\x58\x86\xa8\xeb\x10\x64\x9c\xbf" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -137,7 +137,7 @@ class HPACKDecoderTest < Minitest::Test # C.4.3 def test_hpack_decode_headers_with_huffman3 decoder = test_hpack_decode_headers_with_huffman2 - encoded = "\x82\x87\x85\xbf\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5b\xb8\xe8\xb4\xbf".b + encoded = "\x82\x87\x85\xbf\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5b\xb8\xe8\xb4\xbf" result = decoder.decode(encoded) expected = [ [":method", "GET"], @@ -152,7 +152,7 @@ class HPACKDecoderTest < Minitest::Test # C.5.1 def test_hpack_decode_response_without_huffman decoder = new_decoder(256) - encoded = "\x48\x03\x33\x30\x32\x58\x07\x70\x72\x69\x76\x61\x74\x65\x61\x1d\x4d\x6f\x6e\x2c\x20\x32\x31\x20\x4f\x63\x74\x20\x32\x30\x31\x33\x20\x32\x30\x3a\x31\x33\x3a\x32\x31\x20\x47\x4d\x54\x6e\x17\x68\x74\x74\x70\x73\x3a\x2f\x2f\x77\x77\x77\x2e\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d".b + encoded = "\x48\x03\x33\x30\x32\x58\x07\x70\x72\x69\x76\x61\x74\x65\x61\x1d\x4d\x6f\x6e\x2c\x20\x32\x31\x20\x4f\x63\x74\x20\x32\x30\x31\x33\x20\x32\x30\x3a\x31\x33\x3a\x32\x31\x20\x47\x4d\x54\x6e\x17\x68\x74\x74\x70\x73\x3a\x2f\x2f\x77\x77\x77\x2e\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d" result = decoder.decode(encoded) expected = [ [":status", "302"], @@ -168,7 +168,7 @@ class HPACKDecoderTest < Minitest::Test # C.5.2 def test_hpack_decode_response_without_huffman2 decoder = test_hpack_decode_response_without_huffman - encoded = "\x48\x03\x33\x30\x37\xc1\xc0\xbf".b + encoded = "\x48\x03\x33\x30\x37\xc1\xc0\xbf" result = decoder.decode(encoded) expected = [ [":status", "307"], @@ -185,7 +185,7 @@ class HPACKDecoderTest < Minitest::Test # C.5.3 def test_hpack_decode_response_without_huffman3 decoder = test_hpack_decode_response_without_huffman2 - encoded = "\x88\xc1\x61\x1d\x4d\x6f\x6e\x2c\x20\x32\x31\x20\x4f\x63\x74\x20\x32\x30\x31\x33\x20\x32\x30\x3a\x31\x33\x3a\x32\x32\x20\x47\x4d\x54\xc0\x5a\x04\x67\x7a\x69\x70\x77\x38\x66\x6f\x6f\x3d\x41\x53\x44\x4a\x4b\x48\x51\x4b\x42\x5a\x58\x4f\x51\x57\x45\x4f\x50\x49\x55\x41\x58\x51\x57\x45\x4f\x49\x55\x3b\x20\x6d\x61\x78\x2d\x61\x67\x65\x3d\x33\x36\x30\x30\x3b\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x31".b + encoded = "\x88\xc1\x61\x1d\x4d\x6f\x6e\x2c\x20\x32\x31\x20\x4f\x63\x74\x20\x32\x30\x31\x33\x20\x32\x30\x3a\x31\x33\x3a\x32\x32\x20\x47\x4d\x54\xc0\x5a\x04\x67\x7a\x69\x70\x77\x38\x66\x6f\x6f\x3d\x41\x53\x44\x4a\x4b\x48\x51\x4b\x42\x5a\x58\x4f\x51\x57\x45\x4f\x50\x49\x55\x41\x58\x51\x57\x45\x4f\x49\x55\x3b\x20\x6d\x61\x78\x2d\x61\x67\x65\x3d\x33\x36\x30\x30\x3b\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x31" result = decoder.decode(encoded) expected = [ [":status", "200"], @@ -201,7 +201,7 @@ class HPACKDecoderTest < Minitest::Test # C.6.1 def test_hpack_decode_response_with_huffman decoder = new_decoder(256) - encoded = "\x48\x82\x64\x02\x58\x85\xae\xc3\x77\x1a\x4b\x61\x96\xd0\x7a\xbe\x94\x10\x54\xd4\x44\xa8\x20\x05\x95\x04\x0b\x81\x66\xe0\x82\xa6\x2d\x1b\xff\x6e\x91\x9d\x29\xad\x17\x18\x63\xc7\x8f\x0b\x97\xc8\xe9\xae\x82\xae\x43\xd3".b + encoded = "\x48\x82\x64\x02\x58\x85\xae\xc3\x77\x1a\x4b\x61\x96\xd0\x7a\xbe\x94\x10\x54\xd4\x44\xa8\x20\x05\x95\x04\x0b\x81\x66\xe0\x82\xa6\x2d\x1b\xff\x6e\x91\x9d\x29\xad\x17\x18\x63\xc7\x8f\x0b\x97\xc8\xe9\xae\x82\xae\x43\xd3" result = decoder.decode(encoded) expected = [ [":status", "302"], @@ -217,7 +217,7 @@ class HPACKDecoderTest < Minitest::Test # C.6.2 def test_hpack_decode_response_with_huffman2 decoder = test_hpack_decode_response_with_huffman - encoded = "\x48\x83\x64\x0e\xff\xc1\xc0\xbf".b + encoded = "\x48\x83\x64\x0e\xff\xc1\xc0\xbf" result = decoder.decode(encoded) expected = [ [":status", "307"], @@ -234,7 +234,7 @@ class HPACKDecoderTest < Minitest::Test # C.6.3 def test_hpack_decode_response_with_huffman3 decoder = test_hpack_decode_response_with_huffman2 - encoded = "\x88\xc1\x61\x96\xd0\x7a\xbe\x94\x10\x54\xd4\x44\xa8\x20\x05\x95\x04\x0b\x81\x66\xe0\x84\xa6\x2d\x1b\xff\xc0\x5a\x83\x9b\xd9\xab\x77\xad\x94\xe7\x82\x1d\xd7\xf2\xe6\xc7\xb3\x35\xdf\xdf\xcd\x5b\x39\x60\xd5\xaf\x27\x08\x7f\x36\x72\xc1\xab\x27\x0f\xb5\x29\x1f\x95\x87\x31\x60\x65\xc0\x03\xed\x4e\xe5\xb1\x06\x3d\x50\x07".b + encoded = "\x88\xc1\x61\x96\xd0\x7a\xbe\x94\x10\x54\xd4\x44\xa8\x20\x05\x95\x04\x0b\x81\x66\xe0\x84\xa6\x2d\x1b\xff\xc0\x5a\x83\x9b\xd9\xab\x77\xad\x94\xe7\x82\x1d\xd7\xf2\xe6\xc7\xb3\x35\xdf\xdf\xcd\x5b\x39\x60\xd5\xaf\x27\x08\x7f\x36\x72\xc1\xab\x27\x0f\xb5\x29\x1f\x95\x87\x31\x60\x65\xc0\x03\xed\x4e\xe5\xb1\x06\x3d\x50\x07" result = decoder.decode(encoded) expected = [ [":status", "200"], diff --git a/test/hpack_huffman_test.rb b/test/hpack_huffman_test.rb index ca08b14..508d3fd 100644 --- a/test/hpack_huffman_test.rb +++ b/test/hpack_huffman_test.rb @@ -2,14 +2,14 @@ require "test_helper" class HPACKHuffmanTest < Minitest::Test def test_hpack_huffman_encode - text = "\x10\x60\x2a\x1d\x94\x47\x82\x2c\x3d\x19\xbf\x8e\xd9\x24\xba\xe6\xb4\x1a\xe1\x5c\x39\x0f\x61\xf4\x3b\x08\x62\x54\x15\x0c".b - expected = "\xff\xff\xfe\xdf\xff\xbf\x3f\xff\xff\xf3\xff\xff\xdd\x8b\xff\xf9\xfe\xa0\xff\xff\xff\x5f\xff\xfe\x3f\xff\xfd\x7f\xff\xe5\xff\xcf\xff\xfc\x7f\xff\xe8\xff\xff\xdb\xff\xff\xfe\xdf\xff\xfe\x7f\xff\xc1\xff\xff\xff\xec\x1f\xff\xff\xe7\xfb\xff\xff\xfe\x88\xf7\xff\xff\xff\x97\xff\xff\xf5\x7f".b + text = "\x10\x60\x2a\x1d\x94\x47\x82\x2c\x3d\x19\xbf\x8e\xd9\x24\xba\xe6\xb4\x1a\xe1\x5c\x39\x0f\x61\xf4\x3b\x08\x62\x54\x15\x0c" + expected = "\xff\xff\xfe\xdf\xff\xbf\x3f\xff\xff\xf3\xff\xff\xdd\x8b\xff\xf9\xfe\xa0\xff\xff\xff\x5f\xff\xfe\x3f\xff\xfd\x7f\xff\xe5\xff\xcf\xff\xfc\x7f\xff\xe8\xff\xff\xdb\xff\xff\xfe\xdf\xff\xfe\x7f\xff\xc1\xff\xff\xff\xec\x1f\xff\xff\xe7\xfb\xff\xff\xfe\x88\xf7\xff\xff\xff\x97\xff\xff\xf5\x7f" assert_equal(expected, Plum::HPACK::Huffman.encode(text)) end def test_hpack_huffman_decode - encoded = "\xff\xff\xfe\xdf\xff\xbf\x3f\xff\xff\xf3\xff\xff\xdd\x8b\xff\xf9\xfe\xa0\xff\xff\xff\x5f\xff\xfe\x3f\xff\xfd\x7f\xff\xe5\xff\xcf\xff\xfc\x7f\xff\xe8\xff\xff\xdb\xff\xff\xfe\xdf\xff\xfe\x7f\xff\xc1\xff\xff\xff\xec\x1f\xff\xff\xe7\xfb\xff\xff\xfe\x88\xf7\xff\xff\xff\x97\xff\xff\xf5\x7f".b - expected = "\x10\x60\x2a\x1d\x94\x47\x82\x2c\x3d\x19\xbf\x8e\xd9\x24\xba\xe6\xb4\x1a\xe1\x5c\x39\x0f\x61\xf4\x3b\x08\x62\x54\x15\x0c".b + encoded = "\xff\xff\xfe\xdf\xff\xbf\x3f\xff\xff\xf3\xff\xff\xdd\x8b\xff\xf9\xfe\xa0\xff\xff\xff\x5f\xff\xfe\x3f\xff\xfd\x7f\xff\xe5\xff\xcf\xff\xfc\x7f\xff\xe8\xff\xff\xdb\xff\xff\xfe\xdf\xff\xfe\x7f\xff\xc1\xff\xff\xff\xec\x1f\xff\xff\xe7\xfb\xff\xff\xfe\x88\xf7\xff\xff\xff\x97\xff\xff\xf5\x7f" + expected = "\x10\x60\x2a\x1d\x94\x47\x82\x2c\x3d\x19\xbf\x8e\xd9\x24\xba\xe6\xb4\x1a\xe1\x5c\x39\x0f\x61\xf4\x3b\x08\x62\x54\x15\x0c" assert_equal(expected, Plum::HPACK::Huffman.decode(encoded)) end end diff --git a/test/server_state_test.rb b/test/server_state_test.rb index 9d3d526..0fddfca 100644 --- a/test/server_state_test.rb +++ b/test/server_state_test.rb @@ -1,13 +1,19 @@ require "test_helper" +using Plum::BinaryString + class ServerStateTest < Minitest::Test def test_server_must_repond_cprotocol_error_on_invalid_magic invalid_magic = "HELLO" * 10 start_server do start_client do |sock| sock.write(invalid_magic) - ret = Plum::BinaryString.new(sock.readpartial(1024)) - frame = Plum::Frame.parse!(ret) + frame = nil + loop do + ret = sock.readpartial(1024) + frame = Plum::Frame.parse!(ret) + break if frame.type != :settings # server connection preface + end assert_equal(:goaway, frame.type) # connection error assert_equal(0x01, frame.payload.uint32(4)) # protocol error end |