Example #1
0
    def mock_user_factory(self, name, roles, level=None, range_=None):
        """Factory function for User objects, using a mock qpol object."""
        assert (level and range_) or (not level and not range_)

        # inject object_r, like the compiler does
        roles_with_objr = roles
        roles_with_objr.append('object_r')

        mock_user = Mock(qpol.qpol_user_t)
        mock_user.name.return_value = name
        mock_user.role_iter = lambda x: iter(roles_with_objr)
        mock_user.dfltlevel.return_value = level
        mock_user.range.return_value = range_

        return user_factory(self.p.policy, mock_user)
Example #2
0
    def mock_user_factory(self, name, roles, level=None, range_=None):
        """Factory function for User objects, using a mock qpol object."""
        assert (level and range_) or (not level and not range_)

        # inject object_r, like the compiler does
        roles_with_objr = roles
        roles_with_objr.append('object_r')

        mock_user = Mock(qpol.qpol_user_t)
        mock_user.name.return_value = name
        mock_user.role_iter = lambda x: iter(roles_with_objr)
        mock_user.dfltlevel.return_value = level
        mock_user.range.return_value = range_

        return user_factory(self.p.policy, mock_user)
Example #3
0
 def test_003_lookup_object(self):
     """User factory policy lookup of User object."""
     user1 = user_factory(self.p.policy, "user10")
     user2 = user_factory(self.p.policy, user1)
     self.assertIs(user2, user1)
Example #4
0
 def test_002_lookup_invalid(self):
     """User factory policy invalid lookup."""
     with self.assertRaises(InvalidUser):
         user_factory(self.p.policy, "INVALID")
Example #5
0
 def test_001_lookup(self):
     """User factory policy lookup."""
     user = user_factory(self.p.policy, "user10")
     self.assertEqual("user10", user.qpol_symbol.name(self.p.policy))
Example #6
0
 def test_003_lookup_object(self):
     """User factory policy lookup of User object."""
     user1 = user_factory(self.p.policy, "user10")
     user2 = user_factory(self.p.policy, user1)
     self.assertIs(user2, user1)
Example #7
0
 def test_002_lookup_invalid(self):
     """User factory policy invalid lookup."""
     with self.assertRaises(InvalidUser):
         user_factory(self.p.policy, "INVALID")
Example #8
0
 def test_001_lookup(self):
     """User factory policy lookup."""
     user = user_factory(self.p.policy, "user10")
     self.assertEqual("user10", user.qpol_symbol.name(self.p.policy))