Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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"))
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
  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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
  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)
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
 def testGetEmail_customEmailEnabled(self):
     u = rdf_objects.GRRUser(username="******", email="*****@*****.**")
     with test_lib.ConfigOverrider(
         {"Email.enable_custom_email_address": True}):
         self.assertEqual("*****@*****.**", u.GetEmail())
Ejemplo n.º 13
0
 def testGetEmail_customEmailDisabled(self):
     u = rdf_objects.GRRUser(username="******", email="*****@*****.**")
     self.assertEqual("foo@localhost", u.GetEmail())
Ejemplo n.º 14
0
 def testGetEmail(self):
     u = rdf_objects.GRRUser(username="******")
     self.assertEqual("foo@localhost", u.GetEmail())