Exemple #1
0
    def mock_terule_factory(self, ruletype, source, target, tclass, default, cond=None,
                            filename=None):

        if filename:
            assert not cond
            mock_rule = Mock(qpol_filename_trans_t)
            mock_rule.filename.return_value = filename

        else:
            mock_rule = Mock(qpol_terule_t)

            if cond:
                mock_rule.cond.return_value = cond
            else:
                # this actually comes out of condexpr_factory
                # but it's simpler to have here
                mock_rule.cond.side_effect = AttributeError

        mock_rule.rule_type.return_value = ruletype
        mock_rule.source_type.return_value = source
        mock_rule.target_type.return_value = target
        mock_rule.object_class.return_value = tclass
        mock_rule.default_type.return_value = default

        return te_rule_factory(self.p, mock_rule)
Exemple #2
0
    def mock_avrule_factory(self, ruletype, source, target, tclass, xperm, perms):
        mock_rule = Mock(qpol_avrule_t)
        mock_rule.is_extended.return_value = True
        mock_rule.rule_type.return_value = ruletype
        mock_rule.source_type.return_value = source
        mock_rule.target_type.return_value = target
        mock_rule.object_class.return_value = tclass
        mock_rule.xperm_type.return_value = xperm
        mock_rule.xperm_iter = lambda x: iter(perms)

        # this actually comes out of condexpr_factory
        # but it's simpler to have here
        mock_rule.cond.side_effect = AttributeError

        return te_rule_factory(self.p, mock_rule)
Exemple #3
0
    def mock_avrule_factory(self, ruletype, source, target, tclass, perms, cond=None):
        mock_rule = Mock(qpol_avrule_t)
        mock_rule.rule_type.return_value = ruletype
        mock_rule.source_type.return_value = source
        mock_rule.target_type.return_value = target
        mock_rule.object_class.return_value = tclass
        mock_rule.perm_iter = lambda x: iter(perms)

        if cond:
            mock_rule.cond.return_value = cond
        else:
            # this actually comes out of condexpr_factory
            # but it's simpler to have here
            mock_rule.cond.side_effect = ValueError

        return te_rule_factory(self.p, mock_rule)
    def mock_avrule_factory(self,
                            ruletype,
                            source,
                            target,
                            tclass,
                            perms,
                            cond=None):
        mock_rule = Mock(qpol_avrule_t)
        mock_rule.is_extended.return_value = False
        mock_rule.rule_type.return_value = TERuletype.lookup(ruletype)
        mock_rule.source_type.return_value = source
        mock_rule.target_type.return_value = target
        mock_rule.object_class.return_value = tclass
        mock_rule.perm_iter = lambda x: iter(perms)

        if cond:
            mock_rule.cond.return_value = cond
        else:
            # this actually comes out of condexpr_factory
            # but it's simpler to have here
            mock_rule.cond.side_effect = AttributeError

        return te_rule_factory(self.p, mock_rule)
Exemple #5
0
 def test_000_factory(self):
     """AVRule factory lookup."""
     with self.assertRaises(TypeError):
         te_rule_factory(self.p, "INVALID")