File: test_auth_plugins.py

package info (click to toggle)
websockify 0.8.0%2Bdfsg1-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 916 kB
  • sloc: python: 1,951; ansic: 1,037; ruby: 533; cs: 142; sh: 142; makefile: 41
file content (28 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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')