def test_save_and_retrieve_user(self): s = LocalStorage(dir_name + "/test_database.db") u = User("bob", b"anHashedPassword", True) s.save_user(u) self.assertEqual(s.users()["bob"].username, "bob") self.assertEqual(s.users()["bob"].admin, True)
def test_reject_duplicate_user(self): s = LocalStorage(dir_name + "/test_database.db") u1 = User("user1", b"anHashedPassword", True) u2 = User("user1", b"anotherHashedPassword", True) s.save_user(u1) with self.assertRaises(DuplicateUserException) as e: s.save_user(u2)
def test_remove_user(self): s = LocalStorage(dir_name + "/test_database.db") u = User("martin", b"anHashedPassword", True) s.save_user(u) s.remove_user(u.username) with self.assertRaises(KeyError): _ = s.users()["martin"]
def test_update_user(self): s = LocalStorage(dir_name + "/test_database.db") u = User("neil", b"anHashedPassword", True) s.save_user(u) u.admin = False s.update_user(u) self.assertFalse(s.users()["neil"].admin)
def test_auth_user(self): s = LocalStorage(dir_name + "/test_database.db") u = User("bob", b'$2b$10$RakMb.3n/tl76sK7iVahJuklNYkR7f2Y4dsf73tPANwYBkp4VuJ7.', True) s.save_user(u) self.assertTrue(s.auth_user("bob", "test")) self.assertFalse(s.auth_user("bob", "wrong")) pass
def test_set_access(self): s = LocalStorage(dir_name + "/test_database.db") dir_id = s.save_directory(Directory("/some/dir", True, [], "my dir")) dir_id2 = s.save_directory(Directory("/some/dir2", True, [], "my dir2")) dir_id3 = s.save_directory(Directory("/some/dir3", True, [], "my dir3")) s.save_user(User("bob", b"", False)) s.set_access("bob", dir_id, True) s.set_access("bob", dir_id2, True) s.set_access("bob", dir_id3, True) s.set_access("bob", dir_id3, False) self.assertEqual(s.get_access("bob"), [dir_id, dir_id2])