def testHasFlaggedCert_No(self): cert = test_utils.CreateSantaCertificate(flagged=False) bundle_binaries = test_utils.CreateSantaBlockables(10, cert_key=cert.key) bundle = test_utils.CreateSantaBundle(bundle_binaries=bundle_binaries) self.assertFalse(bundle.HasFlaggedCert())
def testHasFlaggedCert_Yes(self): cert = test_utils.CreateSantaCertificate(flagged=True) bundle_binaries = test_utils.CreateSantaBlockables(10) bundle_binaries[-1].cert_key = cert.key bundle_binaries[-1].put() bundle = test_utils.CreateSantaBundle(bundle_binaries=bundle_binaries) self.assertTrue(bundle.HasFlaggedCert())
def testToDict_CertId(self): santa_certificate = test_utils.CreateSantaCertificate() blockable = test_utils.CreateSantaBlockable( cert_key=santa_certificate.key) bundle = test_utils.CreateSantaBundle( main_cert_key=santa_certificate.key, bundle_binaries=[blockable]) with self.LoggedInUser(): dict_ = bundle.to_dict() self.assertTrue(dict_['has_been_uploaded']) self.assertEqual(santa_certificate.key.id(), dict_['cert_id'])
def testResetState(self): cert = test_utils.CreateSantaCertificate( state=constants.STATE.BANNED, flagged=True) cert.ResetState() actual_cert = cert.key.get() self.assertEqual(actual_cert.state, constants.STATE.UNTRUSTED) self.assertFalse(actual_cert.flagged) self.assertBigQueryInsertion(constants.BIGQUERY_TABLE.CERTIFICATE)
def testIsVotingAllowed_Cert(self): user = test_utils.CreateUser() admin = test_utils.CreateUser(admin=True) cert = test_utils.CreateSantaCertificate() # Test for a regular user. allowed, reason = cert.IsVotingAllowed(current_user=user) self.assertFalse(allowed) self.assertIsNotNone(reason) # Test for an admin. allowed, reason = cert.IsVotingAllowed(current_user=admin) self.assertTrue(allowed) self.assertIsNone(reason)
def setUp(self): app = webapp2.WSGIApplication(routes=[votes.ROUTES]) super(VotesTest, self).setUp(wsgi_app=app) self.santa_blockable = test_utils.CreateSantaBlockable() self.other_blockable = test_utils.CreateSantaBlockable() self.santa_certificate = test_utils.CreateSantaCertificate() self.user_1 = test_utils.CreateUser() self.user_2 = test_utils.CreateUser() self.vote_1 = test_utils.CreateVote( self.santa_blockable, user_email=self.user_1.email, weight=2) self.vote_2 = test_utils.CreateVote( self.other_blockable, user_email=self.user_1.email, weight=10) self.vote_3 = test_utils.CreateVote( self.santa_certificate, user_email=self.user_1.email, weight=0, candidate_type='CERTIFICATE') self.PatchValidateXSRFToken()
def setUp(self, app): super(BlockablesTest, self).setUp(wsgi_app=app) self.bit9_blockable = test_utils.CreateBit9Binary( id='zzzzzzzzzaaa', id_type=constants.ID_TYPE.SHA256, file_name='Mac.app.exe') self.bit9_blockable2 = test_utils.CreateBit9Binary( id='zzzzzzzzzbbb', id_type=constants.ID_TYPE.SHA256, file_name='app.exe') self.generic_blockable = test_utils.CreateBlockable( file_name='Not4Mac.exe', state=constants.STATE.SUSPECT) self.santa_blockable = test_utils.CreateSantaBlockable( publisher='Arple', product_name='New Shiny', flagged=True) self.santa_certificate = test_utils.CreateSantaCertificate( id_type=constants.ID_TYPE.SHA256, common_name='Best Cert Ever', organization='Totally Legit CA') self.PatchValidateXSRFToken()
def testChangeState(self): # Verify the SantaCertificate is in the default state of UNTRUSTED. cert = test_utils.CreateSantaCertificate() blockable_hash = cert.blockable_hash cert = cert_models.SantaCertificate.get_by_id(blockable_hash) self.assertIsNotNone(cert) self.assertEqual(constants.STATE.UNTRUSTED, cert.state) # Note the state change timestamp. old_state_change_dt = cert.state_change_dt # Change the state. cert.ChangeState(constants.STATE.BANNED) # Reload, and verify the state change. cert = cert_models.SantaCertificate.get_by_id(blockable_hash) self.assertIsNotNone(cert) self.assertEqual(constants.STATE.BANNED, cert.state) self.assertBigQueryInsertion(constants.BIGQUERY_TABLE.CERTIFICATE) # And the state change timestamp should be increased. self.assertGreater(cert.state_change_dt, old_state_change_dt)
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 testIsInstance(self): cert = test_utils.CreateSantaCertificate() self.assertTrue(cert.IsInstance('Blockable')) self.assertTrue(cert.IsInstance('Certificate')) self.assertTrue(cert.IsInstance('SantaCertificate')) self.assertFalse(cert.IsInstance('SomethingElse'))