def testIsAdmin_IsFailsafe(self): self.PatchSetting('FAILSAFE_ADMINISTRATORS', [_TEST_EMAIL]) mr_failsafe = test_utils.CreateUser(email=_TEST_EMAIL, roles=[constants.USER_ROLE.USER]) self.assertTrue(mr_failsafe.is_admin)
def testIsAdmin_Nope(self): lowly_peon = test_utils.CreateUser(roles=[constants.USER_ROLE.USER]) self.assertFalse(lowly_peon.is_admin)
def testIsAdmin_HasAdminRole(self): fancy_admin = test_utils.CreateUser( roles=[constants.USER_ROLE.ADMINISTRATOR]) self.assertTrue(fancy_admin.is_admin)
def testAssociated_PrimaryUser(self): user = test_utils.CreateUser() host = test_utils.CreateSantaHost(primary_user=user.nickname) self.assertTrue(model_utils.IsSantaHostAssociatedWithUser(host, user))
def testNotAssociated_NoEvent(self): user = test_utils.CreateUser() # Create a host not owned by `user`. host = test_utils.CreateSantaHost(primary_user='******') self.assertFalse(model_utils.IsSantaHostAssociatedWithUser(host, user))
def setUp(self): super(HostTest, self).setUp() self.host = base.Host(id='bar', hostname='foo') self.blockable = test_utils.CreateBlockable() self.user1 = test_utils.CreateUser() self.user2 = test_utils.CreateUser()
def testUserGetOtherUser(self): """Normal user trying to get information on another user.""" user = test_utils.CreateUser() with self.LoggedInUser(): self.testapp.get(self.ROUTE % user.email, status=httplib.FORBIDDEN)
def testLacksPermission(self): user = test_utils.CreateUser() self.assertFalse(user.LacksPermission(constants.PERMISSIONS.VOTE)) self.assertTrue(user.LacksPermission( constants.PERMISSIONS.EDIT_ALERTS))
def testNoExemptions_WithoutStateFilter(self): user = test_utils.CreateUser() test_utils.CreateSantaHosts(4, primary_user=user.nickname) self.assertListEqual([], model_utils.GetExemptionsForUser(user.email))
def testHighestRole_Default(self): user = test_utils.CreateUser() self.assertEqual(constants.USER_ROLE.USER, user.highest_role)
def testHighestRole_NoRolesError(self): user = test_utils.CreateUser() user.roles = [] user.put() with self.assertRaises(user_models.NoRolesError): user.highest_role # pylint: disable=pointless-statement
def setUp(self): super(ChangeModeForHostsTest, self).setUp() self.user = test_utils.CreateUser()
def setUp(self): app = webapp2.WSGIApplication(routes=[events.ROUTES]) super(EventsTest, self).setUp(wsgi_app=app) self.santa_cert = test_utils.CreateSantaCertificate() self.santa_blockable1 = test_utils.CreateSantaBlockable( id='aaaabbbbccccddddeeeeffffgggg', file_name='Product.app', cert_key=self.santa_cert.key, cert_sha256=self.santa_cert.key.id()) self.santa_blockable2 = test_utils.CreateSantaBlockable( id='hhhhiiiijjjjkkkkllllmmmmnnnn', file_name='Another Product.app') self.bit9_blockable1 = test_utils.CreateBit9Binary( id='zzzzaaaayyyybbbbxxxxccccwwww', file_name='notepad++.exe') self.user_1 = test_utils.CreateUser() self.user_2 = test_utils.CreateUser() self.santa_host1 = test_utils.CreateSantaHost( id='AAAAAAAA-1111-BBBB-2222-CCCCCCCCCCCC', recorded_dt=datetime.datetime(2015, 2, 1, 1, 0, 0)) self.santa_host2 = test_utils.CreateSantaHost( id='DDDDDDDD-3333-EEEE-33333-FFFFFFFFFFFF', recorded_dt=datetime.datetime(2015, 2, 1, 1, 0, 0)) self.bit9_host1 = test_utils.CreateSantaHost( id='CHANGE-ME', recorded_dt=datetime.datetime(2015, 2, 1, 1, 0, 0)) self.bit9_host2 = test_utils.CreateSantaHost( id='CHANGE-ME2', recorded_dt=datetime.datetime(2015, 2, 1, 1, 0, 0)) self.santa_event1_from_user1 = test_utils.CreateSantaEvent( self.santa_blockable1, cert_key=self.santa_cert.key, cert_sha256=self.santa_blockable1.cert_sha256, executing_user=self.user_1.nickname, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, file_name=self.santa_blockable1.file_name, file_path='/Applications/Product.app/Contents/MacOs', host_id=self.santa_host1.key.id(), last_blocked_dt=datetime.datetime(2015, 3, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 3, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_1.key, self.santa_host1.key, self.santa_blockable1.key)) self.santa_event2_from_user1 = test_utils.CreateSantaEvent( self.santa_blockable1, cert_key=self.santa_cert.key, cert_sha256=self.santa_blockable1.cert_sha256, executing_user=self.user_1.nickname, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, file_name=self.santa_blockable1.file_name, file_path='/Applications/Product.app/Contents/MacOs', host_id=self.santa_host2.key.id(), last_blocked_dt=datetime.datetime(2015, 4, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 4, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_1.key, self.santa_host2.key, self.santa_blockable1.key)) self.santa_event3_from_user1 = test_utils.CreateSantaEvent( self.santa_blockable2, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, executing_user=self.user_1.nickname, file_name=self.santa_blockable2.file_name, file_path='/Applications/Another Product.app/Contents/MacOs', host_id=self.santa_host1.key.id(), last_blocked_dt=datetime.datetime(2015, 5, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 5, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_1.key, self.santa_host1.key, self.santa_blockable2.key)) self.santa_event1_from_user2 = test_utils.CreateSantaEvent( self.santa_blockable1, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, executing_user=self.user_2.nickname, file_name=self.santa_blockable1.file_name, file_path='/Applications/Product.app/Contents/MacOs', host_id=self.santa_host2.key.id(), last_blocked_dt=datetime.datetime(2015, 3, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 3, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_2.key, self.santa_host2.key, self.santa_blockable1.key)) self.bit9_event1_from_user1 = test_utils.CreateBit9Event( self.bit9_blockable1, executing_user=self.user_1.nickname, file_name=self.bit9_blockable1.file_name, file_path=r'c:\program files (x86)\notepad++', host_id=self.bit9_host1.key.id(), last_blocked_dt=datetime.datetime(2015, 6, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 6, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_1.key, self.bit9_host1.key, self.bit9_blockable1.key)) self.bit9_event1_from_user2 = test_utils.CreateBit9Event( self.bit9_blockable1, executing_user=self.user_2.nickname, file_name='notepad++.exe', file_path=r'c:\program files (x86)\notepad++', host_id=self.bit9_host2.key.id(), last_blocked_dt=datetime.datetime(2015, 4, 1, 1, 0, 0), first_blocked_dt=datetime.datetime(2015, 4, 1, 1, 0, 0), parent=datastore_utils.ConcatenateKeys(self.user_2.key, self.bit9_host2.key, self.bit9_blockable1.key)) self.PatchValidateXSRFToken()
def testHostIsAssociatedWithUser_PrimaryUser(self): user = test_utils.CreateUser() host = test_utils.CreateSantaHost(primary_user=user.nickname) self.assertTrue(host.IsAssociatedWithUser(user))
def testPermissions_Admin(self): admin = test_utils.CreateUser(admin=True) self.assertSetEqual(constants.PERMISSIONS.SET_ALL, admin.permissions)
def testAssociated(self): user = test_utils.CreateUser() host = test_utils.CreateBit9Host(users=[user.nickname]) self.assertTrue(model_utils.IsBit9HostAssociatedWithUser(host, user))
def testPermissions_User(self): user = test_utils.CreateUser() self.assertSetEqual(constants.PERMISSIONS.SET_USER, user.permissions)
def testNotAssociated(self): user = test_utils.CreateUser() host = test_utils.CreateBit9Host(users=['someone_else']) self.assertFalse(model_utils.IsBit9HostAssociatedWithUser(host, user))
def setUp(self): super(VoteTest, self).setUp() self.blockable = test_utils.CreateBlockable() self.user = test_utils.CreateUser()
def testGetByUserId_NotAuthorized(self): other_user_id = test_utils.CreateUser().key.id() with self.LoggedInUser(): self.testapp.get( self.USER_ID_ROUTE % other_user_id, status=httplib.FORBIDDEN)