def Run(self): user_urn = aff4.ROOT_URN.Add("users").Add(self.token.username) with test_lib.FakeTime(42): with aff4.FACTORY.Create(user_urn, aff4_type=aff4_users.GRRUser, mode="w", token=self.token) as user_fd: user_fd.Set(user_fd.Schema.GUI_SETTINGS, aff4_users.GUISettings(canary_mode=True)) # Setup relational DB. data_store.REL_DB.WriteGRRUser(username=self.token.username, canary_mode=True) self.Check("GetGrrUser") # Make user an admin and do yet another request. with aff4.FACTORY.Open(user_urn, mode="rw", token=self.token) as user_fd: user_fd.SetLabel("admin", owner="GRR") data_store.REL_DB.WriteGRRUser( username=self.token.username, user_type=rdf_objects.GRRUser.UserType.USER_TYPE_ADMIN) self.Check("GetGrrUser")
def Run(self): with test_lib.FakeTime(42): with aff4.FACTORY.Create(aff4.ROOT_URN.Add("users").Add( self.token.username), aff4_type=aff4_users.GRRUser, mode="w", token=self.token) as user_fd: user_fd.Set(user_fd.Schema.GUI_SETTINGS, aff4_users.GUISettings(canary_mode=True)) self.Check("GetGrrUser")
def testSetsSettingsForUserCorrespondingToToken(self): settings = aff4_users.GUISettings(mode="ADVANCED", canary_mode=True, docs_location="REMOTE") user = user_plugin.ApiGrrUser(settings=settings) self.handler.Handle(user, token=access_control.ACLToken(username="******")) # Check that settings for user "foo" were applied. fd = aff4.FACTORY.Open("aff4:/users/foo", token=self.token) self.assertEqual(fd.Get(fd.Schema.GUI_SETTINGS), settings)
def testSetsSettingsForUserCorrespondingToToken(self): settings = aff4_users.GUISettings(mode="ADVANCED", canary_mode=True) user = user_plugin.ApiGrrUser(settings=settings) self.handler.Handle(user, token=access_control.ACLToken(username="******")) # Check that settings for user "foo" were applied. fd = aff4.FACTORY.Open("aff4:/users/foo", token=self.token) self.assertEqual(fd.Get(fd.Schema.GUI_SETTINGS), settings) # Check that settings were applied in relational db. u = data_store.REL_DB.ReadGRRUser("foo") self.assertEqual(settings.mode, u.ui_mode) self.assertEqual(settings.canary_mode, u.canary_mode)
def testRendersSettingsForUserCorrespondingToToken(self): with aff4.FACTORY.Create(aff4.ROOT_URN.Add("users").Add("foo"), aff4_type=aff4_users.GRRUser, mode="w", token=self.token) as user_fd: user_fd.Set( user_fd.Schema.GUI_SETTINGS, aff4_users.GUISettings( mode="ADVANCED", canary_mode=True, )) result = self.handler.Handle( None, token=access_control.ACLToken(username="******")) self.assertEqual(result.settings.mode, "ADVANCED") self.assertEqual(result.settings.canary_mode, True)