diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-14 19:15:04 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-14 19:15:04 +0900 |
commit | 218a0c560135ce1f8d3afe6eae0c09165ab42f2f (patch) | |
tree | 14e30c9d8566d33cf5a1c6266287ca41b1bdd079 /test/plum | |
parent | a80d386e915315e1d789c9171ccd725efc36503b (diff) | |
download | plum-218a0c560135ce1f8d3afe6eae0c09165ab42f2f.tar.gz |
http_connection: add test cases
Diffstat (limited to 'test/plum')
-rw-r--r-- | test/plum/test_http_connection.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/plum/test_http_connection.rb b/test/plum/test_http_connection.rb new file mode 100644 index 0000000..1560c96 --- /dev/null +++ b/test/plum/test_http_connection.rb @@ -0,0 +1,61 @@ +require "test_helper" + +using Plum::BinaryString + +class HTTPConnectionNegotiationTest < Minitest::Test + ## with Prior Knowledge (same as over TLS) + def test_server_must_raise_cprotocol_error_non_settings_after_magic + con = HTTPConnection.new(StringIO.new) + con << Connection::CLIENT_CONNECTION_PREFACE + assert_connection_error(:protocol_error) { + con << Frame.new(type: :window_update, stream_id: 0, payload: "".push_uint32(1)).assemble + } + end + + def test_server_accept_fragmented_magic + magic = Connection::CLIENT_CONNECTION_PREFACE + con = HTTPConnection.new(StringIO.new) + assert_no_error { + con << magic[0...5] + con << magic[5..-1] + con << Frame.new(type: :settings, stream_id: 0).assemble + } + end + + ## with HTTP/1.1 Upgrade + def test_server_accept_upgrade + io = StringIO.new + con = HTTPConnection.new(io) + heads = nil + con.on(:stream) {|stream| + stream.on(:headers) {|_h| heads = _h.to_h } + } + req = "GET / HTTP/1.1\r\n" << + "Host: rhe.jp\r\n" << + "User-Agent: nya\r\n" << + "Upgrade: h2c\r\n" << + "Connection: HTTP2-Settings, Upgrade\r\n" << + "HTTP2-Settings: \r\n" << + "\r\n" + con << req + assert(io.string.include?("HTTP/1.1 101 "), "Response is not HTTP/1.1 101: #{io.string}") + assert_no_error { + con << Connection::CLIENT_CONNECTION_PREFACE + con << Frame.new(type: :settings, stream_id: 0).assemble + } + assert_equal(:half_closed_remote, con.streams[1].state) + assert_equal({ ":method" => "GET", ":path" => "/", ":authority" => "rhe.jp", "user-agent" => "nya"}, heads) + end + + def test_server_deny_non_upgrade + io = StringIO.new + con = HTTPConnection.new(io) + req = "GET / HTTP/1.1\r\n" << + "Host: rhe.jp\r\n" << + "User-Agent: nya\r\n" << + "Connection: close\r\n" << + "\r\n" + con << req + assert(io.string.include?("HTTP/1.1 505 "), "Response is not HTTP/1.1 505: #{io.string}") + end +end |