setools/tests/mixins.py
Richard Haines 3532ed2fff setools-V4: Add updates for testing V30 xen and xperms
Add updates to seinfo and sesearch to test libqpol updates
added via [1].

Also include extra tests for Xen and xperms. Note, xperms
cannot yet test the extended perms as needs more work on
libqpol.

[1] 0001-setools-V4-libqpol-policy-V30-updates-xen-xperm-stat.patch

Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
2016-03-21 10:56:37 -04:00

68 lines
2.3 KiB
Python

"""Unit test mixin classes."""
# Copyright 2015, Tresys Technology, LLC
#
# This file is part of SETools.
#
# SETools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# SETools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
# pylint: disable=too-few-public-methods
import unittest
from setools.policyrep.exception import RuleNotConditional, RuleUseError
class ValidateRule(unittest.TestCase):
"""Mixin for validating policy rules."""
def validate_rule(self, rule, ruletype, source, target, tclass, last_item, cond=None,
cond_block=None):
"""Validate a rule."""
self.assertEqual(ruletype, rule.ruletype)
self.assertEqual(source, rule.source)
self.assertEqual(target, rule.target)
self.assertEqual(tclass, rule.tclass)
try:
# This is the common case.
self.assertSetEqual(last_item, rule.perms)
except (AttributeError, RuleUseError):
self.assertEqual(last_item, rule.default)
if cond:
self.assertEqual(cond, rule.conditional)
else:
self.assertRaises(RuleNotConditional, getattr, rule, "conditional")
if cond_block is not None:
self.assertEqual(cond_block, rule.conditional_block)
class ValidateXpermRule(unittest.TestCase):
"""Mixin for validating policy xperm rules."""
def validate_xperm_rule(self, rule, ruletype, source, target, tclass):
"""Validate a rule."""
self.assertEqual(ruletype, rule.ruletype)
self.assertEqual(source, rule.source)
self.assertEqual(target, rule.target)
self.assertEqual(tclass, rule.tclass)
# try:
# # This is the common case.
# self.assertSetEqual(last_item, rule.perms)
# except (AttributeError, RuleUseError):
# self.assertEqual(last_item, rule.default)