Esempio n. 1
0
    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)
Esempio n. 2
0
 def testIsAdmin_Nope(self):
     lowly_peon = test_utils.CreateUser(roles=[constants.USER_ROLE.USER])
     self.assertFalse(lowly_peon.is_admin)
Esempio n. 3
0
 def testIsAdmin_HasAdminRole(self):
     fancy_admin = test_utils.CreateUser(
         roles=[constants.USER_ROLE.ADMINISTRATOR])
     self.assertTrue(fancy_admin.is_admin)
Esempio n. 4
0
 def testAssociated_PrimaryUser(self):
   user = test_utils.CreateUser()
   host = test_utils.CreateSantaHost(primary_user=user.nickname)
   self.assertTrue(model_utils.IsSantaHostAssociatedWithUser(host, user))
Esempio n. 5
0
 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))
Esempio n. 6
0
 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()
Esempio n. 7
0
 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)
Esempio n. 8
0
 def testLacksPermission(self):
     user = test_utils.CreateUser()
     self.assertFalse(user.LacksPermission(constants.PERMISSIONS.VOTE))
     self.assertTrue(user.LacksPermission(
         constants.PERMISSIONS.EDIT_ALERTS))
Esempio n. 9
0
  def testNoExemptions_WithoutStateFilter(self):

    user = test_utils.CreateUser()
    test_utils.CreateSantaHosts(4, primary_user=user.nickname)

    self.assertListEqual([], model_utils.GetExemptionsForUser(user.email))
Esempio n. 10
0
 def testHighestRole_Default(self):
     user = test_utils.CreateUser()
     self.assertEqual(constants.USER_ROLE.USER, user.highest_role)
Esempio n. 11
0
 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
Esempio n. 12
0
  def setUp(self):
    super(ChangeModeForHostsTest, self).setUp()

    self.user = test_utils.CreateUser()
Esempio n. 13
0
    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()
Esempio n. 14
0
    def testHostIsAssociatedWithUser_PrimaryUser(self):
        user = test_utils.CreateUser()
        host = test_utils.CreateSantaHost(primary_user=user.nickname)

        self.assertTrue(host.IsAssociatedWithUser(user))
Esempio n. 15
0
 def testPermissions_Admin(self):
     admin = test_utils.CreateUser(admin=True)
     self.assertSetEqual(constants.PERMISSIONS.SET_ALL, admin.permissions)
Esempio n. 16
0
 def testAssociated(self):
   user = test_utils.CreateUser()
   host = test_utils.CreateBit9Host(users=[user.nickname])
   self.assertTrue(model_utils.IsBit9HostAssociatedWithUser(host, user))
Esempio n. 17
0
 def testPermissions_User(self):
     user = test_utils.CreateUser()
     self.assertSetEqual(constants.PERMISSIONS.SET_USER, user.permissions)
Esempio n. 18
0
 def testNotAssociated(self):
   user = test_utils.CreateUser()
   host = test_utils.CreateBit9Host(users=['someone_else'])
   self.assertFalse(model_utils.IsBit9HostAssociatedWithUser(host, user))
Esempio n. 19
0
 def setUp(self):
     super(VoteTest, self).setUp()
     self.blockable = test_utils.CreateBlockable()
     self.user = test_utils.CreateUser()
Esempio n. 20
0
 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)