diff options
Diffstat (limited to 'test/test_pathoc.py')
-rw-r--r-- | test/test_pathoc.py | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/test/test_pathoc.py b/test/test_pathoc.py index c00c7d53..28514378 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -1,8 +1,9 @@ import json import cStringIO import re +from mock import Mock -from netlib import tcp, http +from netlib import tcp, http, http2 from libpathod import pathoc, test, version, pathod, language import tutils @@ -86,8 +87,9 @@ class _TestDaemon: class TestDaemonSSL(_TestDaemon): ssl = True ssloptions = pathod.SSLOptions( - request_client_cert=True, - sans = ["test1.com", "test2.com"] + request_client_cert = True, + sans = ["test1.com", "test2.com"], + alpn_select = http2.HTTP2Protocol.ALPN_PROTO_H2, ) def test_sni(self): @@ -119,6 +121,14 @@ class TestDaemonSSL(_TestDaemon): d = json.loads(r.content) assert d["log"][0]["request"]["clientcert"]["keyinfo"] + def test_http2_without_ssl(self): + c = pathoc.Pathoc( + ("127.0.0.1", self.d.port), + use_http2 = True, + ssl = False, + ) + tutils.raises(NotImplementedError, c.connect) + class TestDaemon(_TestDaemon): ssl = False @@ -216,3 +226,49 @@ class TestDaemon(_TestDaemon): "HTTP/1.1 200 OK\r\n" ) c.http_connect(to) + + +class TestDaemonHTTP2(_TestDaemon): + ssl = True + ssloptions = pathod.SSLOptions( + alpn_select = http2.HTTP2Protocol.ALPN_PROTO_H2, + ) + + def test_http2(self): + c = pathoc.Pathoc( + ("127.0.0.1", self.d.port), + use_http2 = True, + ssl = True, + ) + assert isinstance(c.protocol, http2.HTTP2Protocol) + + c = pathoc.Pathoc( + ("127.0.0.1", self.d.port), + ) + assert c.protocol == None # TODO: change if other protocols get implemented + + def test_http2_alpn(self): + c = pathoc.Pathoc( + ("127.0.0.1", self.d.port), + ssl = True, + use_http2 = True, + http2_skip_connection_preface = True, + ) + + tmp_convert_to_ssl = c.convert_to_ssl + c.convert_to_ssl = Mock() + c.convert_to_ssl.side_effect = tmp_convert_to_ssl + c.connect() + + _, kwargs = c.convert_to_ssl.call_args + assert set(kwargs['alpn_protos']) == set([b'http1.1', b'h2']) + + def test_request(self): + c = pathoc.Pathoc( + ("127.0.0.1", self.d.port), + ssl = True, + use_http2 = True, + ) + c.connect() + resp = c.request("get:/api/info") + assert tuple(json.loads(resp.content)["version"]) == version.IVERSION |