aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/http2/test_http2_protocol.py17
-rw-r--r--test/test_tcp.py41
2 files changed, 42 insertions, 16 deletions
diff --git a/test/http2/test_http2_protocol.py b/test/http2/test_http2_protocol.py
index 34c69fa9..9b49acd3 100644
--- a/test/http2/test_http2_protocol.py
+++ b/test/http2/test_http2_protocol.py
@@ -222,14 +222,14 @@ class TestCreateRequest():
def test_create_request_simple(self):
bytes = http2.HTTP2Protocol(self.c).create_request('GET', '/')
assert len(bytes) == 1
- assert bytes[0] == '00000c0105000000018284874187089d5c0b8170ff'.decode('hex')
+ assert bytes[0] == '00000d0105000000018284874188089d5c0b8170dc07'.decode('hex')
def test_create_request_with_body(self):
bytes = http2.HTTP2Protocol(self.c).create_request(
'GET', '/', [(b'foo', b'bar')], 'foobar')
assert len(bytes) == 2
assert bytes[0] ==\
- '0000140104000000018284874187089d5c0b8170ff408294e7838c767f'.decode('hex')
+ '0000150104000000018284874188089d5c0b8170dc07408294e7838c767f'.decode('hex')
assert bytes[1] ==\
'000006000100000001666f6f626172'.decode('hex')
@@ -300,8 +300,9 @@ class TestReadRequest(test.ServerTestBase):
c.convert_to_ssl()
protocol = http2.HTTP2Protocol(c, is_server=True)
- headers, body = protocol.read_request()
+ stream_id, headers, body = protocol.read_request()
+ assert stream_id
assert headers == {':method': 'GET', ':path': '/', ':scheme': 'https'}
assert body == b'foobar'
@@ -309,17 +310,17 @@ class TestReadRequest(test.ServerTestBase):
class TestCreateResponse():
c = tcp.TCPClient(("127.0.0.1", 0))
- def test_create_request_simple(self):
+ def test_create_response_simple(self):
bytes = http2.HTTP2Protocol(self.c, is_server=True).create_response(200)
assert len(bytes) == 1
assert bytes[0] ==\
'00000101050000000288'.decode('hex')
- def test_create_request_with_body(self):
+ def test_create_response_with_body(self):
bytes = http2.HTTP2Protocol(self.c, is_server=True).create_response(
- 200, [(b'foo', b'bar')], 'foobar')
+ 200, 1, [(b'foo', b'bar')], 'foobar')
assert len(bytes) == 2
assert bytes[0] ==\
- '00000901040000000288408294e7838c767f'.decode('hex')
+ '00000901040000000188408294e7838c767f'.decode('hex')
assert bytes[1] ==\
- '000006000100000002666f6f626172'.decode('hex')
+ '000006000100000001666f6f626172'.decode('hex')
diff --git a/test/test_tcp.py b/test/test_tcp.py
index 0cecaaa2..122c1f0f 100644
--- a/test/test_tcp.py
+++ b/test/test_tcp.py
@@ -41,6 +41,18 @@ class HangHandler(tcp.BaseHandler):
time.sleep(1)
+class ALPNHandler(tcp.BaseHandler):
+ sni = None
+
+ def handle(self):
+ alp = self.get_alpn_proto_negotiated()
+ if alp:
+ self.wfile.write("%s" % alp)
+ else:
+ self.wfile.write("NONE")
+ self.wfile.flush()
+
+
class TestServer(test.ServerTestBase):
handler = EchoHandler
@@ -416,30 +428,43 @@ class TestTimeOut(test.ServerTestBase):
tutils.raises(tcp.NetLibTimeout, c.rfile.read, 10)
-class TestALPN(test.ServerTestBase):
- handler = EchoHandler
+class TestALPNClient(test.ServerTestBase):
+ handler = ALPNHandler
ssl = dict(
- alpn_select="foobar"
+ alpn_select="bar"
)
if OpenSSL._util.lib.Cryptography_HAS_ALPN:
def test_alpn(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
c.connect()
- c.convert_to_ssl(alpn_protos=["foobar"])
- assert c.get_alpn_proto_negotiated() == "foobar"
+ c.convert_to_ssl(alpn_protos=["foo", "bar", "fasel"])
+ assert c.get_alpn_proto_negotiated() == "bar"
+ assert c.rfile.readline().strip() == "bar"
def test_no_alpn(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
c.connect()
- assert c.get_alpn_proto_negotiated() == None
+ c.convert_to_ssl()
+ assert c.get_alpn_proto_negotiated() == ""
+ assert c.rfile.readline().strip() == "NONE"
else:
def test_none_alpn(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
c.connect()
- c.convert_to_ssl(alpn_protos=["foobar"])
- assert c.get_alpn_proto_negotiated() == None
+ c.convert_to_ssl(alpn_protos=["foo", "bar", "fasel"])
+ assert c.get_alpn_proto_negotiated() == ""
+ assert c.rfile.readline() == "NONE"
+
+class TestNoSSLNoALPNClient(test.ServerTestBase):
+ handler = ALPNHandler
+
+ def test_no_ssl_no_alpn(self):
+ c = tcp.TCPClient(("127.0.0.1", self.port))
+ c.connect()
+ assert c.get_alpn_proto_negotiated() == ""
+ assert c.rfile.readline().strip() == "NONE"
class TestSSLTimeOut(test.ServerTestBase):