Esempio n. 1
0
 def test_set_minimum_requirements(self, possession, inherence, knowledge,
                                   minimum_requirements):
     policy = AuthPolicy()
     policy.set_policy({
         'minimum_requirements': [{
             'possession': possession,
             'requirement': 'authenticated',
             'any': minimum_requirements,
             'inherence': inherence,
             'knowledge': knowledge
         }],
         'factors': []
     })
     self.assertEqual(policy.minimum_amount, minimum_requirements)
     if possession:
         self.assertIn('possession', policy.minimum_requirements)
     else:
         self.assertNotIn('possession', policy.minimum_requirements)
     if inherence:
         self.assertIn('inherence', policy.minimum_requirements)
     else:
         self.assertNotIn('inherence', policy.minimum_requirements)
     if knowledge:
         self.assertIn('knowledge', policy.minimum_requirements)
     else:
         self.assertNotIn('knowledge', policy.minimum_requirements)
 def test_set_minimum_requirements(self, possession, inherence, knowledge, minimum_requirements):
     policy = AuthPolicy()
     policy.set_policy(
         {
             'minimum_requirements': [
                 {
                     'possession': possession,
                     'requirement': 'authenticated',
                     'any': minimum_requirements,
                     'inherence': inherence,
                     'knowledge': knowledge
                 }
             ],
             'factors': []
         }
     )
     self.assertEqual(policy.minimum_amount, minimum_requirements)
     if possession:
         self.assertIn('possession', policy.minimum_requirements)
     else:
         self.assertNotIn('possession', policy.minimum_requirements)
     if inherence:
         self.assertIn('inherence', policy.minimum_requirements)
     else:
         self.assertNotIn('inherence', policy.minimum_requirements)
     if knowledge:
         self.assertIn('knowledge', policy.minimum_requirements)
     else:
         self.assertNotIn('knowledge', policy.minimum_requirements)
Esempio n. 3
0
 def test_set_policy_geofence(self):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy({
         'minimum_requirements': [],
         'factors': [{
             'quickfail': False,
             'priority': 1,
             'requirement': 'forced requirement',
             'attributes': {
                 'locations': [{
                     'latitude': 1.0,
                     'radius': 3.0,
                     'name': '123',
                     'longitude': 2.0
                 }]
             },
             'factor': 'geofence'
         }]
     })
     self.assertEqual(len(policy.geofences), 1)
     self.assertEqual(policy.geofences[0].latitude, 1.0)
     self.assertEqual(policy.geofences[0].longitude, 2.0)
     self.assertEqual(policy.geofences[0].radius, 3.0)
     self.assertEqual(policy.geofences[0].name, '123')\
Esempio n. 4
0
 def test_set_minimum_requirments_all(self):
     policy = AuthPolicy()
     policy.set_policy({
         'minimum_requirements': [{
             'possession': 1,
             'requirement': 'authenticated',
             'all': 1,
             'inherence': 1,
             'knowledge': 1
         }],
         'factors': []
     })
     self.assertEqual(policy.minimum_amount, 1)
     self.assertIn('possession', policy.minimum_requirements)
     self.assertIn('inherence', policy.minimum_requirements)
     self.assertIn('knowledge', policy.minimum_requirements)
Esempio n. 5
0
 def test_set_policy_jailbreak(self, enabled):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy({
         'minimum_requirements': [],
         'factors': [{
             'quickfail': False,
             'priority': 1,
             'requirement': 'forced requirement',
             'attributes': {
                 'factor enabled': enabled
             },
             'factor': 'device integrity'
         }]
     })
     self.assertEqual(policy.jailbreak_protection,
                      True if enabled else False)
 def test_set_policy_jailbreak(self, enabled):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy(
         {
             'minimum_requirements': [],
             'factors': [
                 {
                     'quickfail': False,
                     'priority': 1,
                     'requirement': 'forced requirement',
                     'attributes': {'factor enabled': enabled},
                     'factor': 'device integrity'
                 }
             ]
         }
     )
     self.assertEqual(policy.jailbreak_protection, True if enabled else False)
 def test_set_minimum_requirments_all(self):
     policy = AuthPolicy()
     policy.set_policy(
         {
             'minimum_requirements': [
                 {
                     'possession': 1,
                     'requirement': 'authenticated',
                     'all': 1,
                     'inherence': 1,
                     'knowledge': 1
                 }
             ],
             'factors': []
         }
     )
     self.assertEqual(policy.minimum_amount, 1)
     self.assertIn('possession', policy.minimum_requirements)
     self.assertIn('inherence', policy.minimum_requirements)
     self.assertIn('knowledge', policy.minimum_requirements)
 def test_set_policy_geofence(self):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy(
         {
             'minimum_requirements': [],
             'factors': [
                 {
                     'quickfail': False,
                     'priority': 1,
                     'requirement': 'forced requirement',
                     'attributes': {
                         'locations': [
                             {'latitude': 1.0, 'radius': 3.0, 'name': '123', 'longitude': 2.0}]},
                     'factor': 'geofence'
                 }
             ]
         }
     )
     self.assertEqual(len(policy.geofences), 1)
     self.assertEqual(policy.geofences[0].latitude, 1.0)
     self.assertEqual(policy.geofences[0].longitude, 2.0)
     self.assertEqual(policy.geofences[0].radius, 3.0)
     self.assertEqual(policy.geofences[0].name, '123')\
Esempio n. 9
0
 def test_set_policy_json(self):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy(dumps({'minimum_requirements': [], 'factors': []}))
Esempio n. 10
0
 def test_eq_match(self):
     policy = AuthPolicy()
     policy.add_geofence(1, 2, 3, '123')
     policy2 = AuthPolicy()
     policy2.set_policy(policy.get_policy())
     self.assertEqual(policy, policy2)
 def test_set_policy_json(self):
     policy = AuthPolicy()
     self.assertEqual(len(policy.geofences), 0)
     policy.set_policy(dumps({'minimum_requirements': [], 'factors': []}))
 def test_eq_match(self):
     policy = AuthPolicy()
     policy.add_geofence(1, 2, 3, '123')
     policy2 = AuthPolicy()
     policy2.set_policy(policy.get_policy())
     self.assertTrue(policy == policy2)