test_auth_plugins.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  2. """ Unit tests for Authentication plugins"""
  3. from websockify.auth_plugins import BasicHTTPAuth, AuthenticationError
  4. import unittest
  5. class BasicHTTPAuthTestCase(unittest.TestCase):
  6. def setUp(self):
  7. self.plugin = BasicHTTPAuth('Aladdin:open sesame')
  8. def test_no_auth(self):
  9. headers = {}
  10. self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234')
  11. def test_invalid_password(self):
  12. headers = {'Authorization': 'Basic QWxhZGRpbjpzZXNhbWUgc3RyZWV0'}
  13. self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234')
  14. def test_valid_password(self):
  15. headers = {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
  16. self.plugin.authenticate(headers, 'localhost', '1234')
  17. def test_garbage_auth(self):
  18. headers = {'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
  19. self.assertRaises(AuthenticationError, self.plugin.authenticate, headers, 'localhost', '1234')