def testSuccess(self): host_id = test_utils.CreateSantaHost().key.id() other_host_id = test_utils.CreateSantaHost().key.id() blockable = test_utils.CreateSantaBlockable() # Same Blockable, but wrong Host. test_utils.CreateSantaEvent(blockable, host_id=other_host_id, executing_user='******') # Correct Host. test_utils.CreateSantaEvent(blockable, host_id=host_id, executing_user='******') # Multiple Events for one user. for _ in range(3): test_utils.CreateSantaEvent(blockable, host_id=host_id, executing_user='******') # Correct Host, but local admin. test_utils.CreateSantaEvent(blockable, host_id=host_id, executing_user=constants.LOCAL_ADMIN.MACOS) expected_users = ['user2', 'user3'] actual_users = sorted( model_utils.GetUsersAssociatedWithSantaHost(host_id)) self.assertEqual(expected_users, actual_users)
def testUserGetOwnEventWithContext_Bundle(self): """Getting an event of the requesting user's by id.""" bundle = test_utils.CreateSantaBundle( bundle_binaries=[self.santa_blockable1]) event = test_utils.CreateSantaEvent( self.santa_blockable1, bundle_key=bundle.key, executing_user=self.user_1.nickname, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, 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=utils.ConcatenateKeys(self.user_1.key, self.santa_host1.key, bundle.key)) test_utils.CreateVote(bundle, user_email=self.user_1.email) params = {'withContext': 'true'} with self.LoggedInUser(user=self.user_1): response = self.testapp.get(self.ROUTE % event.key.urlsafe(), params) output = response.json self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output, dict) self.assertEqual(output['event']['id'], event.key.id()) self.assertEqual(output['host']['id'], output['event']['hostId']) bundle_key = ndb.Key(urlsafe=output['event']['bundleKey']) self.assertEqual(output['blockable']['id'], bundle_key.id()) self.assertIsNotNone(output['vote'])
def testUser_GetOwnEvent_SantaBundle(self): bundle = test_utils.CreateSantaBundle( bundle_binaries=[self.santa_blockable1]) event = test_utils.CreateSantaEvent( self.santa_blockable1, bundle_key=bundle.key, executing_user=self.user_1.nickname, event_type=constants.EVENT_TYPE.BLOCK_UNKNOWN, 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=utils.ConcatenateKeys(self.user_1.key, self.santa_host1.key, bundle.key)) with self.LoggedInUser(user=self.user_1): response = self.testapp.get(self.ROUTE % bundle.key.id()) output = response.json self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output, dict) self.assertEqual(output['id'], event.key.id()) self.assertEqual(output['hostId'], event.host_id)
def testBinary_Normal(self): test_utils.CreateSantaEvent(self.santa_blockable) with self.LoggedInUser(): response = self.testapp.get('/%s' % self.santa_blockable.key.id()) output = response.json self.assertEqual(1, output)
def testGiantQuarantineUrl(self): # Ensure URLs that exceed the NDB size limit for indexed properties (1500 # bytes) may be set on QuarantineMetadata URL fields. huge_url = 'http://3vil.com/' + 'a' * 1500 blockable = test_utils.CreateSantaBlockable() quarantine = event_models.QuarantineMetadata(data_url=huge_url) event = test_utils.CreateSantaEvent(blockable, quarantine=quarantine) event.put()
def testGetAssociatedHostIds_Overlap(self): """User is primary_user of a Host and has an Event on that Host.""" user = test_utils.CreateUser() host = test_utils.CreateSantaHost(primary_user=user.nickname) blockable = test_utils.CreateSantaBlockable() test_utils.CreateSantaEvent(blockable, host_id=host.key.id()) self.assertListEqual([host.key.id()], santa.SantaHost.GetAssociatedHostIds(user))
def testGet_Cert_Normal(self): test_utils.CreateSantaEvent( self.santa_blockable, cert_sha256=self.santa_certificate.key.id()) with self.LoggedInUser(): response = self.testapp.get(self.ROUTE % self.santa_certificate.key.id()) output = response.json self.assertEqual(1, output)
def CreateTestEntities(email_addr): """Create some test Datastore data if specified, but only if running locally. Note that this code doesn't (and shouldn't) delete any existing entities. The risk of such code being accidentally triggered in prod is too great, so if local entities need to be deleted, use the local Datastore viewer (e.g. http://127.0.0.1:8000/datastore). Args: email_addr: Email address of the local users for whom test data should be created. Raises: NotRunningLocally: if called anywhere other than a local deployment. """ if not utils.RunningLocally(): raise NotRunningLocally # Create a user entity with all available roles. user = base.User.GetOrInsert(email_addr=email_addr) base.User.SetRoles(email_addr, constants.USER_ROLE.SET_ALL) username = user_map.EmailToUsername(email_addr) # Create associated SantaHosts for the user. santa_hosts = test_utils.CreateSantaHosts(2, primary_user=username) # For each SantaHost, create some SantaEvents. for santa_host in santa_hosts: for santa_blockable in test_utils.CreateSantaBlockables(5): parent_key = model_utils.ConcatenateKeys(user.key, santa_host.key, santa_blockable.key) test_utils.CreateSantaEvent( santa_blockable, executing_user=username, event_type=constants.EVENT_TYPE.BLOCK_BINARY, host_id=santa_host.key.id(), parent=parent_key) # Create associated Bit9Hosts for the user. bit9_hosts = test_utils.CreateBit9Hosts(2, users=[username]) # For each Bit9Host, create some Bit9Events. for bit9_host in bit9_hosts: for bit9_binary in test_utils.CreateBit9Binaries(5): parent_key = model_utils.ConcatenateKeys(user.key, bit9_host.key, bit9_binary.key) test_utils.CreateBit9Event( bit9_binary, executing_user=username, event_type=constants.EVENT_TYPE.BLOCK_BINARY, host_id=bit9_host.key.id(), parent=parent_key)
def testHostIsAssociatedWithUser_HasEvent(self): user = test_utils.CreateUser() other_user = test_utils.CreateUser() # Create a host not owned by `user`. host = test_utils.CreateSantaHost(primary_user=other_user.nickname) # Create an Event which was generated by `user`. parent_key = utils.ConcatenateKeys(user.key, host.key, self.santa_blockable.key) test_utils.CreateSantaEvent(self.santa_blockable, host_id=host.key.id(), parent=parent_key) self.assertTrue(host.IsAssociatedWithUser(user))
def testAssociated_HasEvent(self): user = test_utils.CreateUser() other_user = test_utils.CreateUser() # Create a host not owned by `user`. host = test_utils.CreateSantaHost(primary_user=other_user.nickname) # Create an Event which was generated by `user`. blockable = test_utils.CreateSantaBlockable() parent_key = datastore_utils.ConcatenateKeys( user.key, host.key, blockable.key) test_utils.CreateSantaEvent( blockable, host_id=host.key.id(), parent=parent_key) self.assertTrue(model_utils.IsSantaHostAssociatedWithUser(host, user))
def testUserGetOwnBlockables(self): user_1 = test_utils.CreateUser() user_2 = test_utils.CreateUser() # Create two events for this user. test_utils.CreateBit9Event(self.bit9_blockable, executing_user=user_2.nickname, host_id='a_host_id', parent=datastore_utils.ConcatenateKeys( user_2.key, ndb.Key('Host', 'a_host_id'), self.santa_blockable.key)) host_id = 'AAAAAAAA-1111-BBBB-2222-CCCCCCCCCCCC' test_utils.CreateSantaEvent( self.santa_blockable, executing_user=user_2.nickname, event_type=constants.EVENT_TYPE.ALLOW_UNKNOWN, file_name='Product.app', file_path='/Applications/Product.app/Contents/MacOs', host_id=host_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(user_2.key, ndb.Key('Host', host_id), self.santa_blockable.key)) # Create one event for another user. This should not be included in # the results when fetching blockables for user_2. test_utils.CreateBit9Event( self.bit9_blockable2, executing_user=user_1.nickname, file_name='notepad++.exe', file_path=r'c:\program files (x86)\notepad++', host_id='a_host_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( user_1.key, ndb.Key('Host', 'a_host_id'), self.santa_blockable.key)) params = {'filter': 'own'} with self.LoggedInUser(user=user_2): response = self.testapp.get('/blockables/all/all', params) output = response.json # Verify that only two blockables (from the two events) are returned to # this user. self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output['content'], list) self.assertLen(output['content'], 2)
def setUp(self): app = webapp2.WSGIApplication( [webapp2.Route(r'/<host_id>', handler=hosts.HostEventRateHandler)]) super(HostEventRateHandlerTest, self).setUp(app) self.user = test_utils.CreateUser() self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_1.key.id(), last_blocked_dt=datetime.datetime.utcnow(), parent=utils.ConcatenateKeys(self.user.key, self.santa_host_1.key, self.santa_blockable.key))
def setUp(self): super(AssociatedHostHandlerTest, self).setUp() self.user = test_utils.CreateUser() self.admin = test_utils.CreateUser(admin=True) self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_1.key.id(), executing_user=self.user.nickname, parent=utils.ConcatenateKeys(self.user.key, self.santa_host_1.key, self.santa_blockable.key)) self.bit9_host_1.users = [self.user.nickname] self.bit9_host_1.put()
def testAssociatedUserGet(self): """Normal user associated with a host gets it by ID.""" blockable = test_utils.CreateBlockable() with self.LoggedInUser() as user: test_utils.CreateSantaEvent(blockable, host_id=self.santa_host_1.key.id(), executing_user=user.nickname, parent=utils.ConcatenateKeys( user.key, self.santa_host_1.key, blockable.key)) self.assertTrue(self.santa_host_1.IsAssociatedWithUser(user)) response = self.testapp.get('/' + self.santa_host_1.key.id()) output = response.json self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output, dict)
def setUp(self): super(HostExceptionHandlerTest, self).setUp() self.user = test_utils.CreateUser(admin=True) self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_3.key.id(), executing_user=self.user.nickname, parent=utils.ConcatenateKeys(self.user.key, self.santa_host_3.key, self.santa_blockable.key)) self.santa_blockable.put() self.santa_event.put() self.PatchEnv(settings.ProdEnv, ENABLE_BIGQUERY_STREAMING=True)
def setUp(self): super(LockdownHandlerTest, self).setUp() self.user = test_utils.CreateUser() self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_3.key.id(), parent=utils.ConcatenateKeys(self.user.key, self.santa_host_3.key, self.santa_blockable.key)) self.santa_blockable.put() self.santa_event.put() self.santa_host_3.client_mode = constants.SANTA_CLIENT_MODE.MONITOR self.santa_host_3.put()
def setUp(self): app = webapp2.WSGIApplication( [webapp2.Route(r'/<host_id>', handler=hosts.LockdownHandler)]) super(LockdownHandlerTest, self).setUp(app) self.user = test_utils.CreateUser() self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_3.key.id(), parent=utils.ConcatenateKeys(self.user.key, self.santa_host_3.key, self.santa_blockable.key)) self.santa_blockable.put() self.santa_event.put() self.santa_host_3.client_mode = constants.SANTA_CLIENT_MODE.MONITOR self.santa_host_3.put()
def setUp(self): app = webapp2.WSGIApplication( [webapp2.Route(r'/<host_id>', handler=hosts.HostExceptionHandler)]) super(HostExceptionHandlerTest, self).setUp(app) self.user = test_utils.CreateUser(admin=True) self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_3.key.id(), executing_user=self.user.nickname, parent=utils.ConcatenateKeys(self.user.key, self.santa_host_3.key, self.santa_blockable.key)) self.santa_blockable.put() self.santa_event.put() self.PatchEnv(settings.ProdEnv, ENABLE_BIGQUERY_STREAMING=True)
def testGet_AssociatedUser(self): user = test_utils.CreateUser() host = test_utils.CreateSantaHost(primary_user=user.nickname) test_utils.CreateExemption(host.key.id()) blockable = test_utils.CreateBlockable() test_utils.CreateSantaEvent( blockable, host_id=host.key.id(), executing_user=user.nickname, parent=datastore_utils.ConcatenateKeys( user.key, host.key, blockable.key)) self.assertTrue(model_utils.IsHostAssociatedWithUser(host, user)) with self.LoggedInUser(user=user): response = self.testapp.get(self.ROUTE % host.key.id()) output = response.json self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output, dict) self.assertIn('exemption', output)
def testSuccess(self): user = test_utils.CreateUser() other_user = test_utils.CreateUser() santa_host_key_1 = test_utils.CreateSantaHost( primary_user=user.nickname).key santa_host_key_2 = test_utils.CreateSantaHost( primary_user=other_user.nickname).key test_utils.CreateSantaHost(primary_user=other_user.nickname) blockable = test_utils.CreateSantaBlockable() parent_key = datastore_utils.ConcatenateKeys( user.key, santa_host_key_2, blockable.key) test_utils.CreateSantaEvent( blockable, host_id=santa_host_key_2.id(), parent=parent_key) expected_host_ids = sorted([santa_host_key_1.id(), santa_host_key_2.id()]) actual_host_ids = sorted(model_utils.GetSantaHostIdsForUser(user)) self.assertListEqual(expected_host_ids, actual_host_ids)
def testGetByUserId_IsAdmin(self): user = test_utils.CreateUser() bit9_host_id = test_utils.CreateBit9Host(users=[user.nickname]).key.id() santa_host_key = test_utils.CreateSantaHost( primary_user=user.nickname).key santa_host_id = santa_host_key.id() blockable = test_utils.CreateSantaBlockable() event_parent_key = datastore_utils.ConcatenateKeys( user.key, santa_host_key, blockable.key) test_utils.CreateSantaEvent( blockable, host_id=santa_host_id, parent=event_parent_key) with self.LoggedInUser(admin=True): response = self.testapp.get(self.USER_ID_ROUTE % user.key.id()) output = response.json self.assertLen(output, 2) actual_ids = set(host['id'] for host in output) self.assertSetEqual(set([santa_host_id, bit9_host_id]), actual_ids)
def testUser_GetOwnEvent_CaseMismatch(self): user = test_utils.CreateUser() host = test_utils.CreateSantaHost() blockable = test_utils.CreateSantaBlockable() event_parent_key = datastore_utils.ConcatenateKeys( user.key, host.key, blockable.key) event = test_utils.CreateSantaEvent(blockable, executing_user=user.nickname, parent=event_parent_key) with self.LoggedInUser(user=user): response = self.testapp.get(self.ROUTE % blockable.key.id().upper()) output = response.json self.assertIn('application/json', response.headers['Content-type']) self.assertIsInstance(output, dict) self.assertEqual(output['id'], event.key.id()) self.assertEqual(output['hostId'], event.host_id) self.assertIn('Event', output['class_'])
def testGetAssociatedHostIds(self): """User is primary_user of a Host and has an Event on that Host.""" user = test_utils.CreateUser() other_user = test_utils.CreateUser() host = test_utils.CreateSantaHost(primary_user=user.nickname) host_not_primary1 = (test_utils.CreateSantaHost( primary_user=other_user.nickname)) host_not_primary2 = (test_utils.CreateSantaHost( primary_user=other_user.nickname)) blockable = test_utils.CreateSantaBlockable() parent_key = utils.ConcatenateKeys(user.key, host_not_primary1.key, blockable.key) test_utils.CreateSantaEvent(blockable, host_id=host_not_primary1.key.id(), parent=parent_key) associated_ids = santa.SantaHost.GetAssociatedHostIds(user) self.assertIn(host.key.id(), associated_ids) self.assertIn(host_not_primary1.key.id(), associated_ids) self.assertNotIn(host_not_primary2.key.id(), associated_ids)
def testDedupe_AddNewerQuarantineData(self): blockable = test_utils.CreateSantaBlockable() quarantine = event_models.QuarantineMetadata( data_url='http://notbad.com', referer_url='http://sourceforge.com', downloaded_dt=datetime.datetime.utcnow(), agent_bundle_id='123456') now = datetime.datetime.utcnow() event = test_utils.CreateSantaEvent(blockable, quarantine=quarantine, last_blocked_dt=now) new_quarantine = datastore_utils.CopyEntity(event.quarantine, data_url='http://3vil.com') later_dt = event.last_blocked_dt + datetime.timedelta(seconds=1) later_event = datastore_utils.CopyEntity(event, quarantine=new_quarantine, last_blocked_dt=later_dt) event.Dedupe(later_event) self.assertEqual('http://3vil.com', event.quarantine.data_url)
def testDedupe_AddOldQuarantineData(self): blockable = test_utils.CreateSantaBlockable() now = datetime.datetime.utcnow() event = test_utils.CreateSantaEvent(blockable, quarantine=None, first_blocked_dt=now) quarantine = event_models.QuarantineMetadata( data_url='http://notbad.com', referer_url='http://sourceforge.com', downloaded_dt=datetime.datetime.utcnow(), agent_bundle_id='123456') earlier_dt = event.first_blocked_dt - datetime.timedelta(seconds=1) earlier_event = datastore_utils.CopyEntity( event, quarantine=quarantine, event_type=constants.EVENT_TYPE.BLOCK_CERTIFICATE, first_blocked_dt=earlier_dt) event.Dedupe(earlier_event) self.assertNotEqual(constants.EVENT_TYPE.BLOCK_CERTIFICATE, event.event_type) self.assertIsNotNone(event.quarantine)
def setUp(self): app = webapp2.WSGIApplication([ webapp2.Route(r'/', handler=hosts.AssociatedHostHandler, handler_method='GetSelf'), webapp2.Route(r'/<user_id:.*>', handler=hosts.AssociatedHostHandler, handler_method='GetByUserId') ]) super(AssociatedHostHandlerTest, self).setUp(app) self.user = test_utils.CreateUser() self.admin = test_utils.CreateUser(admin=True) self.santa_blockable = test_utils.CreateSantaBlockable() self.santa_event = test_utils.CreateSantaEvent( self.santa_blockable, host_id=self.santa_host_1.key.id(), executing_user=self.user.nickname, parent=utils.ConcatenateKeys(self.user.key, self.santa_host_1.key, self.santa_blockable.key)) self.bit9_host_1.users = [self.user.nickname] self.bit9_host_1.put()
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=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=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=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=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=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=utils.ConcatenateKeys(self.user_2.key, self.bit9_host2.key, self.bit9_blockable1.key)) self.PatchValidateXSRFToken()
def testRunByLocalAdmin_False(self): blockable = test_utils.CreateSantaBlockable() event = test_utils.CreateSantaEvent(blockable, executing_user='******') self.assertFalse(event.run_by_local_admin)
def testRunByLocalAdmin_True(self): blockable = test_utils.CreateSantaBlockable() event = test_utils.CreateSantaEvent( blockable, executing_user=constants.LOCAL_ADMIN.MACOS) self.assertTrue(event.run_by_local_admin)