def test_change_password(self): """ Testing changing password """ users.add("test", "test") self.assertTrue(users.change_password("test", "coucou")) self.assertTrue(users.is_authorized("test", "coucou")) self.assertFalse(users.is_authorized("test", "test"))
def make_me_admin(current): """Makes the current user into an admin.""" users.add(current, utils.get_current_username(current), "/", "Administrator") users.add(current, utils.get_current_username(current), "/", "Viewer") return {}
def test_is_authorized(self): """ Testing authorization """ users.add("test", "test") self.assertTrue(users.is_authorized("test", "test")) self.assertFalse(users.is_authorized("test2", "test")) self.assertFalse(users.is_authorized("test", "test2"))
def test_get_list_wrong_value(self): users.add("test", "test") users.set_rights("test", {'manage_users': True, 'manage_notes': True, 'manage_products': True}) self.assertEqual(list(users.get_list(bla=True)), [])
def test_add_user(self): """ Test adding an user """ self.assertTrue(users.add("test", "test")) self.assertTrue(users.add("test2", "test")) self.assertFalse(users.add("test", "test")) self.assertFalse(users.add("", "test")) self.assertFalse(users.add("aaa", "")) self.assertEqual(self.count_admins(), 2)
def approve_request(current, client_id, user, role): """Grant the approval for the client.""" # Validate the client_id. if (client_id.startswith("C.") and len(client_id.split("/")) == 1 and role in ["Examiner", "Investigator"]): users.add(current, user, "/" + client_id, role) audit.log(current, "ApprovalGranted", client_id=client_id, approvee=user, role=role) return dict()
def grant_approval(current, hunt_id, user): db = current.db row = db(db.hunts.hunt_id == hunt_id).select().first() if row and row.state == "Proposed": row.update_record(state="Started", timestamp=time.time()) # Give the user permission over this hunt. users.add(current, user, "/" + hunt_id, "Examiner") return dict(data="ok") audit.log(current, "HuntApproval", hunt_id=hunt_id) return {}
def accept(self): """ Callback to create user when validation button is pressed """ if users.add(self.username_input.text(), self.password_input.text()): super().accept() else: gui.utils.error("Impossible d'ajouter cet utilisateur.", "Le nom d'utilisateur est peut être déjà pris.")
def test_rights(self): """ Testing rights """ users.add("test", "test") users.add("test2", "test") self.assertTrue(users.set_rights("test", {'manage_users': True, 'manage_notes': False, 'manage_products': False})) self.assertEqual(users.get_rights("test"), {'manage_users': True, 'manage_notes': False, 'manage_products': False}) self.assertEqual(users.get_rights("test2"), {'manage_users': False, 'manage_notes': False, 'manage_products': False}) # Non existant user has no rights. self.assertEqual(users.get_rights("test3"), {'manage_users': False, 'manage_notes': False, 'manage_products': False})
def test_get_lit(self): """ Testing users.get_list """ users.add("test", "test") users.add("test1", "test") users.add("test2", "test") self.assertEqual(list(users.get_list()), ["test", "test1", "test2"])
def test_issue_24(self): """ Testing issue #24 regression. """ users.add("test", "test") users.add("test2", "test") users.add("test3", "test") users.set_rights("test", {'manage_users': True, 'manage_notes': False, 'manage_products': False}) users.set_rights("test2", {'manage_users': True, 'manage_notes': False, 'manage_products': False}) self.assertTrue(users.remove("test")) users.remove("test2") self.assertEqual(list(users.get_list()), ["test2", "test3"]) users.remove("test3") self.assertEqual(list(users.get_list()), ["test2"])
def test_issue_69(self): """ Testing issue #69 regression. """ users.add("test", "test") users.add("test2", "test") users.add("test3", "test") users.set_rights("test", {'manage_users': True, 'manage_notes': False, 'manage_products': False}) users.set_rights("test2", {'manage_users': False, 'manage_notes': False, 'manage_products': False}) users.set_rights("test", {'manage_users': True, 'manage_notes': True, 'manage_products': False}) self.assertEqual(users.get_rights("test"), {'manage_users': 1, 'manage_notes': 1, 'manage_products': 0})
def test_issue_43(self): """ Testing issue #43 regression. """ users.add("test", "test") users.add("test2", "test") users.add("test3", "test") self.assertTrue(users.set_rights("test", {'manage_users': True, 'manage_notes': False, 'manage_products': False})) users.set_rights("test", {'manage_users': False, 'manage_notes': False, 'manage_products': False}) self.assertEqual(users.get_rights("test")["manage_users"], 1) self.assertTrue(users.set_rights("test2", {'manage_users': True, 'manage_notes': False, 'manage_products': False})) users.set_rights("test", {'manage_users': False, 'manage_notes': False, 'manage_products': False}) self.assertEqual(users.get_rights("test")["manage_users"], 0)
def test_remove_user(self): """ Test removing an user """ users.add("test", "test") self.assertTrue(users.remove("test")) self.assertEqual(self.count_admins(), 0)