diff options
author | Ceesjan Luiten <ceesjan@ytec.nl> | 2015-10-06 11:39:53 +0200 |
---|---|---|
committer | Ceesjan Luiten <ceesjan@ytec.nl> | 2015-10-06 12:09:22 +0200 |
commit | 5bd65546514ce02bd7d0f5fb92e7ec7c6757cb9a (patch) | |
tree | fed650b6770fd105211961592f179561a62d3e43 /tests | |
parent | 50cc65f1e402bd2e5bef58df519838819843a7d7 (diff) | |
download | websockify-5bd65546514ce02bd7d0f5fb92e7ec7c6757cb9a.tar.gz |
Verify username/password with BasicAuth plugin
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_auth_plugins.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_auth_plugins.py b/tests/test_auth_plugins.py new file mode 100644 index 0000000..4b3bfb5 --- /dev/null +++ b/tests/test_auth_plugins.py @@ -0,0 +1,28 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +""" Unit tests for Authentication plugins""" + +from websockify.auth_plugins import BasicHTTPAuth, AuthenticationError +import unittest + + +class BasicHTTPAuthTestCase(unittest.TestCase): + + def setUp(self): + self.plugin = BasicHTTPAuth('Aladdin:open sesame') + + def test_no_auth(self): + headers = {} + self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234') + + def test_invalid_password(self): + headers = {'Authorization': 'Basic QWxhZGRpbjpzZXNhbWUgc3RyZWV0'} + self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234') + + def test_valid_password(self): + headers = {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='} + self.plugin.authenticate(headers, 'localhost', '1234') + + def test_garbage_auth(self): + headers = {'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxx'} + self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234') |