MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / AuthTest

Class AuthTest

app/auth_test.py:33–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33class AuthTest(unittest.TestCase):
34
35 @mock.patch.object(video_service, 'restart', do_nothing)
36 @mock.patch.object(db.users.db_connection, 'get')
37 def test_can_authenticate_with_valid_credentials(self, mock_get_db):
38 with tempfile.NamedTemporaryFile() as temp_file:
39 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
40
41 auth.register('pilot', 'p4ssw0rd', auth.Role.ADMIN)
42 self.assertTrue(auth.can_authenticate('pilot', 'p4ssw0rd'))
43
44 @mock.patch.object(video_service, 'restart', do_nothing)
45 @mock.patch.object(db.users.db_connection, 'get')
46 def test_cannot_register_duplicate_users(self, mock_get_db):
47 with tempfile.NamedTemporaryFile() as temp_file:
48 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
49
50 auth.register('pilot', '12345', auth.Role.ADMIN)
51 with self.assertRaises(db.users.UserAlreadyExistsError):
52 auth.register('pilot', 'p4ssw0rd', auth.Role.ADMIN)
53
54 @mock.patch.object(video_service, 'restart', do_nothing)
55 @mock.patch.object(db.users.db_connection, 'get')
56 def test_fails_if_first_user_is_not_admin(self, mock_get_db):
57 with tempfile.NamedTemporaryFile() as temp_file:
58 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
59
60 with self.assertRaises(auth.OneAdminRequiredError):
61 auth.register('pilot', '12345', auth.Role.OPERATOR)
62
63 @mock.patch.object(video_service, 'restart', do_nothing)
64 @mock.patch.object(db.users.db_connection, 'get')
65 def test_cannot_authenticate_with_wrong_password(self, mock_get_db):
66 with tempfile.NamedTemporaryFile() as temp_file:
67 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
68
69 auth.register('pilot', 'p4ssw0rd', auth.Role.ADMIN)
70 self.assertFalse(auth.can_authenticate('pilot', '12345'))
71
72 @mock.patch.object(db.users.db_connection, 'get')
73 def test_cannot_authenticate_when_no_user_is_registered(self, mock_get_db):
74 with tempfile.NamedTemporaryFile() as temp_file:
75 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
76
77 self.assertFalse(auth.can_authenticate('pilot', '12345'))
78
79 @mock.patch.object(video_service, 'restart', do_nothing)
80 @mock.patch.object(db.users.db_connection, 'get')
81 def test_cannot_authenticate_with_unknown_user(self, mock_get_db):
82 with tempfile.NamedTemporaryFile() as temp_file:
83 mock_get_db.return_value = db.store.create_or_open(temp_file.name)
84
85 auth.register('pilot', 'p4ssw0rd', auth.Role.ADMIN)
86 self.assertFalse(auth.can_authenticate('someone-else', 'p4ssw0rd'))
87
88 @mock.patch.object(video_service, 'restart', do_nothing)
89 @mock.patch.object(db.users.db_connection, 'get')
90 def test_cannot_authenticate_after_account_deletion(self, mock_get_db):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected