summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2021-01-29 12:58:26 +0100
committerPierre Ossman <ossman@cendio.se>2021-01-29 12:58:26 +0100
commita82eb10b4856fd13af3eab2d55dfa0f6278ed0e8 (patch)
treefdf24797935c9b2312562d9189f4c21fae65a793 /tests
parentadc278657a9bb36514b15a80bb255f6878bbacbe (diff)
downloadwebsockify-a82eb10b4856fd13af3eab2d55dfa0f6278ed0e8.tar.gz
Remove Python version check
We require Python 3 now, so no need for this check.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_websocketproxy.py167
1 files changed, 83 insertions, 84 deletions
diff --git a/tests/test_websocketproxy.py b/tests/test_websocketproxy.py
index 74ed9a4..697db32 100644
--- a/tests/test_websocketproxy.py
+++ b/tests/test_websocketproxy.py
@@ -115,90 +115,89 @@ class ProxyRequestHandlerTestCase(unittest.TestCase):
self.assertEqual(self.handler.server.target_host, "somehost")
self.assertEqual(self.handler.server.target_port, "blah")
- if sys.version_info >= (2,7):
- def test_asymmetric_jws_token_plugin(self):
- key = jwt.JWK()
- private_key = open("./tests/fixtures/private.pem", "rb").read()
- key.import_from_pem(private_key)
- jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
- jwt_token.make_signed_token(key)
- self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
-
- patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
-
- self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/public.pem")
- self.handler.validate_connection()
-
- self.assertEqual(self.handler.server.target_host, "remote_host")
- self.assertEqual(self.handler.server.target_port, "remote_port")
-
- def test_asymmetric_jws_token_plugin_with_illigal_key_exception(self):
- key = jwt.JWK()
- private_key = open("./tests/fixtures/private.pem", "rb").read()
- key.import_from_pem(private_key)
- jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
- jwt_token.make_signed_token(key)
- self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
-
- patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
-
- self.handler.server.token_plugin = token_plugins.JWTTokenApi("wrong.pub")
- self.assertRaises(self.handler.server.EClose,
- self.handler.validate_connection)
-
-
- def test_symmetric_jws_token_plugin(self):
- secret = open("./tests/fixtures/symmetric.key").read()
- key = jwt.JWK()
- key.import_key(kty="oct",k=secret)
- jwt_token = jwt.JWT({"alg": "HS256"}, {'host': "remote_host", 'port': "remote_port"})
- jwt_token.make_signed_token(key)
- self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
-
- patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
-
- self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/symmetric.key")
- self.handler.validate_connection()
-
- self.assertEqual(self.handler.server.target_host, "remote_host")
- self.assertEqual(self.handler.server.target_port, "remote_port")
-
- def test_symmetric_jws_token_plugin_with_illigal_key_exception(self):
- secret = open("./tests/fixtures/symmetric.key").read()
- key = jwt.JWK()
- key.import_key(kty="oct",k=secret)
- jwt_token = jwt.JWT({"alg": "HS256"}, {'host': "remote_host", 'port': "remote_port"})
- jwt_token.make_signed_token(key)
- self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
-
- patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
-
- self.handler.server.token_plugin = token_plugins.JWTTokenApi("wrong_sauce")
- self.assertRaises(self.handler.server.EClose,
- self.handler.validate_connection)
-
- def test_asymmetric_jwe_token_plugin(self):
- private_key = jwt.JWK()
- public_key = jwt.JWK()
- private_key_data = open("./tests/fixtures/private.pem", "rb").read()
- public_key_data = open("./tests/fixtures/public.pem", "rb").read()
- private_key.import_from_pem(private_key_data)
- public_key.import_from_pem(public_key_data)
- jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
- jwt_token.make_signed_token(private_key)
- jwe_token = jwt.JWT(header={"alg": "RSA1_5", "enc": "A256CBC-HS512"},
- claims=jwt_token.serialize())
- jwe_token.make_encrypted_token(public_key)
-
- self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwe_token.serialize())
-
- patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
-
- self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/private.pem")
- self.handler.validate_connection()
-
- self.assertEqual(self.handler.server.target_host, "remote_host")
- self.assertEqual(self.handler.server.target_port, "remote_port")
+ def test_asymmetric_jws_token_plugin(self):
+ key = jwt.JWK()
+ private_key = open("./tests/fixtures/private.pem", "rb").read()
+ key.import_from_pem(private_key)
+ jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
+ jwt_token.make_signed_token(key)
+ self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
+
+ patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
+
+ self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/public.pem")
+ self.handler.validate_connection()
+
+ self.assertEqual(self.handler.server.target_host, "remote_host")
+ self.assertEqual(self.handler.server.target_port, "remote_port")
+
+ def test_asymmetric_jws_token_plugin_with_illigal_key_exception(self):
+ key = jwt.JWK()
+ private_key = open("./tests/fixtures/private.pem", "rb").read()
+ key.import_from_pem(private_key)
+ jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
+ jwt_token.make_signed_token(key)
+ self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
+
+ patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
+
+ self.handler.server.token_plugin = token_plugins.JWTTokenApi("wrong.pub")
+ self.assertRaises(self.handler.server.EClose,
+ self.handler.validate_connection)
+
+
+ def test_symmetric_jws_token_plugin(self):
+ secret = open("./tests/fixtures/symmetric.key").read()
+ key = jwt.JWK()
+ key.import_key(kty="oct",k=secret)
+ jwt_token = jwt.JWT({"alg": "HS256"}, {'host': "remote_host", 'port': "remote_port"})
+ jwt_token.make_signed_token(key)
+ self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
+
+ patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
+
+ self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/symmetric.key")
+ self.handler.validate_connection()
+
+ self.assertEqual(self.handler.server.target_host, "remote_host")
+ self.assertEqual(self.handler.server.target_port, "remote_port")
+
+ def test_symmetric_jws_token_plugin_with_illigal_key_exception(self):
+ secret = open("./tests/fixtures/symmetric.key").read()
+ key = jwt.JWK()
+ key.import_key(kty="oct",k=secret)
+ jwt_token = jwt.JWT({"alg": "HS256"}, {'host': "remote_host", 'port': "remote_port"})
+ jwt_token.make_signed_token(key)
+ self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwt_token.serialize())
+
+ patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
+
+ self.handler.server.token_plugin = token_plugins.JWTTokenApi("wrong_sauce")
+ self.assertRaises(self.handler.server.EClose,
+ self.handler.validate_connection)
+
+ def test_asymmetric_jwe_token_plugin(self):
+ private_key = jwt.JWK()
+ public_key = jwt.JWK()
+ private_key_data = open("./tests/fixtures/private.pem", "rb").read()
+ public_key_data = open("./tests/fixtures/public.pem", "rb").read()
+ private_key.import_from_pem(private_key_data)
+ public_key.import_from_pem(public_key_data)
+ jwt_token = jwt.JWT({"alg": "RS256"}, {'host': "remote_host", 'port': "remote_port"})
+ jwt_token.make_signed_token(private_key)
+ jwe_token = jwt.JWT(header={"alg": "RSA1_5", "enc": "A256CBC-HS512"},
+ claims=jwt_token.serialize())
+ jwe_token.make_encrypted_token(public_key)
+
+ self.handler.path = "https://localhost:6080/websockify?token={jwt_token}".format(jwt_token=jwe_token.serialize())
+
+ patcher = patch('websockify.websocketproxy.ProxyRequestHandler.send_auth_error').start()
+
+ self.handler.server.token_plugin = token_plugins.JWTTokenApi("./tests/fixtures/private.pem")
+ self.handler.validate_connection()
+
+ self.assertEqual(self.handler.server.target_host, "remote_host")
+ self.assertEqual(self.handler.server.target_port, "remote_port")
def test_auth_plugin(self):
class TestPlugin(auth_plugins.BasePlugin):