Ejemplo n.º 1
0
 def test_040(self):
     """Subject added with invalid permission raises exception InvalidArguments"""
     a = access_control.AccessControl()
     self.assertRaises(cli_exceptions.InvalidArguments,
                       a.add_allowed_subject, 'subject_1',
                       'invalid_permission')
     self.assertEqual(len(a.allow), 0)
Ejemplo n.º 2
0
 def test_020(self):
     """Single subject added without specified permission is retained and defaults to read"""
     a = access_control.AccessControl()
     a.add_allowed_subject('subject_1', None)
     self.assertEqual(len(a.allow), 1)
     self.assertTrue('subject_1' in a.allow)
     self.assertEqual(a.allow['subject_1'], 'read')
Ejemplo n.º 3
0
 def test_015(self):
     """clear() removes all allowed subjects"""
     a = access_control.AccessControl()
     a.add_allowed_subject('subject_1', None)
     a.add_allowed_subject('subject_2', None)
     a.add_allowed_subject('subject_3', None)
     a.clear()
     self.assertEqual(len(a.allow), 0)
Ejemplo n.º 4
0
 def test_030(self):
     """Adding subject that already exists updates its permission"""
     a = access_control.AccessControl()
     a.add_allowed_subject('subject_1', None)
     self.assertEqual(len(a.allow), 1)
     self.assertTrue('subject_1' in a.allow)
     self.assertEqual(a.allow['subject_1'], 'read')
     a.add_allowed_subject('subject_1', 'write')
     self.assertEqual(len(a.allow), 1)
     self.assertTrue('subject_1' in a.allow)
     self.assertEqual(a.allow['subject_1'], 'write')
Ejemplo n.º 5
0
 def test_050(self):
     """Multiple subjects with different permissions are correctly retained"""
     a = access_control.AccessControl()
     a.add_allowed_subject('subject_1', None)
     a.add_allowed_subject('subject_2', 'write')
     a.add_allowed_subject('subject_3', 'changePermission')
     self.assertEqual(len(a.allow), 3)
     self.assertTrue('subject_1' in a.allow)
     self.assertEqual(a.allow['subject_1'], 'read')
     self.assertTrue('subject_2' in a.allow)
     self.assertEqual(a.allow['subject_2'], 'write')
     self.assertTrue('subject_3' in a.allow)
     self.assertEqual(a.allow['subject_3'], 'changePermission')
Ejemplo n.º 6
0
 def test_200(self):
     """str() returns formatted string representation"""
     a = access_control.AccessControl()
     a.add_allowed_subject('subject_1', None)
     a.add_allowed_subject('subject_2', 'write')
     a.add_allowed_subject('subject_3', 'changePermission')
     actual = []
     for s in str(a).split('\n'):
         actual.append(s.strip())
     self.assertEquals(actual[1],
                       'read                          "subject_1"')
     self.assertEquals(actual[2],
                       'write                         "subject_2"')
     self.assertEquals(actual[3],
                       'changePermission              "subject_3"')
Ejemplo n.º 7
0
 def reset(self):
     self._variables = self._create_default_variables()
     self._access_control = access_control.AccessControl()
     self._replication_policy = replication_policy.ReplicationPolicy()
Ejemplo n.º 8
0
 def test_010(self):
     """The access_control object can be instantiated"""
     a = access_control.AccessControl()
     self.assertEqual(len(a.allow), 0)