def testEmptyGRRUserReadWrite(self): d = self.db d.WriteGRRUser("f🧙oo") u = d.ReadGRRUser("f🧙oo") u_expected = rdf_objects.GRRUser(username="******") self.assertEqual(u_expected, u)
def ReadAllGRRUsers(self): """Reads all GRR users.""" for u in itervalues(self.users): yield rdf_objects.GRRUser(username=u["username"], password=u.get("password"), ui_mode=u.get("ui_mode"), canary_mode=u.get("canary_mode"), user_type=u.get("user_type"))
def testReadingMultipleGRRUsersEntriesWorks(self): d = self.db u_foo = rdf_objects.GRRUser( username="******", ui_mode="ADVANCED", canary_mode=True, user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) d.WriteGRRUser(u_foo.username, ui_mode=u_foo.ui_mode, canary_mode=u_foo.canary_mode, user_type=u_foo.user_type) u_bar = rdf_objects.GRRUser(username="******") d.WriteGRRUser(u_bar.username) users = d.ReadGRRUsers() self.assertEqual(users[0], u_bar) self.assertEqual(users[1], u_foo)
def testInsertUserTwice(self): d = self.db d.WriteGRRUser("foo") d.WriteGRRUser("foo") u = d.ReadGRRUser("foo") u_expected = rdf_objects.GRRUser(username="******") self.assertEqual(u_expected, u)
def _RowToGRRUser(self, row): """Creates a GRR user object from a database result row.""" username, password, ui_mode, canary_mode, user_type = row result = rdf_objects.GRRUser(username=username, ui_mode=ui_mode, canary_mode=canary_mode, user_type=user_type) if password: result.password.ParseFromString(password) return result
def ReadGRRUser(self, username): """Reads a user object corresponding to a given name.""" try: u = self.users[username] return rdf_objects.GRRUser(username=u["username"], password=u.get("password"), ui_mode=u.get("ui_mode"), canary_mode=u.get("canary_mode"), user_type=u.get("user_type")) except KeyError: raise db.UnknownGRRUserError("Can't find user with name: %s" % username)
def testUpdateUserTwice(self): d = self.db d.WriteGRRUser( "foo", user_type=rdf_objects.GRRUser.UserType.USER_TYPE_STANDARD) d.WriteGRRUser( "foo", user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) u = d.ReadGRRUser("foo") u_expected = rdf_objects.GRRUser( username="******", user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) self.assertEqual(u_expected, u)
def _RowToGRRUser(self, row): """Creates a GRR user object from a database result row.""" username, password, ui_mode, canary_mode, user_type, email = row result = rdf_objects.GRRUser(username=username, ui_mode=ui_mode, canary_mode=canary_mode, user_type=user_type, email=email) if password: result.password = rdf_crypto.Password.FromSerializedBytes(password) return result
def WriteGRRUser(self, username, password=None, ui_mode=None, canary_mode=None, user_type=None): """Writes user object for a user with a given name.""" u = self.users.setdefault(username, rdf_objects.GRRUser(username=username)) if password is not None: u.password = password if ui_mode is not None: u.ui_mode = ui_mode if canary_mode is not None: u.canary_mode = canary_mode if user_type is not None: u.user_type = user_type
def testFilledGRRUserReadWrite(self): d = self.db u_expected = rdf_objects.GRRUser( username="******", ui_mode="ADVANCED", canary_mode=True, user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) u_expected.password.SetPassword("blah") d.WriteGRRUser("foo", password=u_expected.password, ui_mode=u_expected.ui_mode, canary_mode=u_expected.canary_mode, user_type=u_expected.user_type) u = d.ReadGRRUser("foo") self.assertEqual(u_expected, u)
def testFilledGRRUserReadWrite(self): d = self.db u_expected = rdf_objects.GRRUser( username="******", ui_mode="ADVANCED", canary_mode=True, user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) # TODO(hanuszczak): Passwords should be required to be unicode strings. u_expected.password.SetPassword(b"blah") d.WriteGRRUser("foo", password=u_expected.password, ui_mode=u_expected.ui_mode, canary_mode=u_expected.canary_mode, user_type=u_expected.user_type) u = d.ReadGRRUser("foo") self.assertEqual(u_expected, u)
def testGetEmail_customEmailEnabled(self): u = rdf_objects.GRRUser(username="******", email="*****@*****.**") with test_lib.ConfigOverrider( {"Email.enable_custom_email_address": True}): self.assertEqual("*****@*****.**", u.GetEmail())
def testGetEmail_customEmailDisabled(self): u = rdf_objects.GRRUser(username="******", email="*****@*****.**") self.assertEqual("foo@localhost", u.GetEmail())
def testGetEmail(self): u = rdf_objects.GRRUser(username="******") self.assertEqual("foo@localhost", u.GetEmail())