Beispiel #1
0
 def check_err(self, input_string, unsafe_lit_strings, msg):
     rule = compile.parse1(input_string)
     try:
         compile.reorder_for_safety(rule)
         self.fail("Failed to raise exception for " + input_string)
     except exception.PolicyException as e:
         errmsg = str(e)
         # parse then print to string so string rep same in err msg
         unsafe_lits = [str(compile.parse1(x)) for x in unsafe_lit_strings]
         missing_lits = [m for m in unsafe_lits
                         if m + " (vars" not in errmsg]
         if len(missing_lits) > 0:
             self.fail(
                 "Unsafe literals {} not reported in error: {}".format(
                     ";".join(missing_lits), errmsg))
Beispiel #2
0
 def check_err(self, input_string, unsafe_lit_strings, msg):
     rule = compile.parse1(input_string)
     try:
         compile.reorder_for_safety(rule)
         self.fail("Failed to raise exception for " + input_string)
     except PolicyException as e:
         errmsg = str(e)
         # parse then print to string so string rep same in err msg
         unsafe_lits = [str(compile.parse1(x)) for x in unsafe_lit_strings]
         missing_lits = [m for m in unsafe_lits
                         if m + " (vars" not in errmsg]
         if len(missing_lits) > 0:
             self.fail(
                 "Unsafe literals {} not reported in error: {}".format(
                     ";".join(missing_lits), errmsg))
Beispiel #3
0
    def update(self, events):
        """Apply EVENTS.

           And return the list of EVENTS that actually
           changed the theory.  Each event is the insert or delete of
           a policy statement.
           """
        changes = []
        self.log(None, "Update %s", utility.iterstr(events))
        try:
            for event in events:
                schema_changes = self.update_rule_schema(
                    event.formula, event.insert)
                formula = compile.reorder_for_safety(event.formula)
                if event.insert:
                    if self._insert_actual(formula):
                        changes.append(event)
                    else:
                        self.revert_schema(schema_changes)
                else:
                    if self._delete_actual(formula):
                        changes.append(event)
                    else:
                        self.revert_schema(schema_changes)
        except Exception:
            LOG.exception("runtime caught an exception")
            raise

        return changes
Beispiel #4
0
    def update(self, events):
        """Apply EVENTS.

           And return the list of EVENTS that actually
           changed the theory.  Each event is the insert or delete of
           a policy statement.
           """
        changes = []
        self.log(None, "Update %s", utility.iterstr(events))
        try:
            for event in events:
                schema_changes = self.update_rule_schema(
                    event.formula, event.insert)
                formula = compile.reorder_for_safety(event.formula)
                if event.insert:
                    if self._insert_actual(formula):
                        changes.append(event)
                    else:
                        self.revert_schema(schema_changes)
                else:
                    if self._delete_actual(formula):
                        changes.append(event)
                    else:
                        self.revert_schema(schema_changes)
        except Exception:
            LOG.exception("runtime caught an exception")
            raise

        return changes
Beispiel #5
0
 def check(self, input_string, correct_string, msg):
     rule = compile.parse1(input_string)
     actual = compile.reorder_for_safety(rule)
     correct = compile.parse1(correct_string)
     if correct != actual:
         emsg = "Correct: " + str(correct)
         emsg += "; Actual: " + str(actual)
         self.fail(msg + " :: " + emsg)
Beispiel #6
0
 def check(self, input_string, correct_string, msg):
     rule = compile.parse1(input_string)
     actual = compile.reorder_for_safety(rule)
     correct = compile.parse1(correct_string)
     if correct != actual:
         emsg = "Correct: " + str(correct)
         emsg += "; Actual: " + str(actual)
         self.fail(msg + " :: " + emsg)
Beispiel #7
0
    def compute_delta_rules(cls, formulas):
        """Return list of DeltaRules computed from formulas.

        Assuming FORMULAS has no self-joins, return a list of DeltaRules
        derived from those FORMULAS.
        """
        # Should do the following for correctness, but it needs to be
        #    done elsewhere so that we can properly maintain the tables
        #    that are generated.
        # formulas = cls.eliminate_self_joins(formulas)
        delta_rules = []
        for rule in formulas:
            if rule.is_atom():
                continue
            rule = compile.reorder_for_safety(rule)
            for literal in rule.body:
                if literal.is_builtin():
                    continue
                newbody = [lit for lit in rule.body if lit is not literal]
                delta_rules.append(DeltaRule(literal, rule.head, newbody, rule))
        return delta_rules
Beispiel #8
0
    def compute_delta_rules(cls, formulas):
        """Return list of DeltaRules computed from formulas.

        Assuming FORMULAS has no self-joins, return a list of DeltaRules
        derived from those FORMULAS.
        """
        # Should do the following for correctness, but it needs to be
        #    done elsewhere so that we can properly maintain the tables
        #    that are generated.
        # formulas = cls.eliminate_self_joins(formulas)
        delta_rules = []
        for rule in formulas:
            if rule.is_atom():
                continue
            rule = compile.reorder_for_safety(rule)
            for literal in rule.body:
                if literal.is_builtin():
                    continue
                newbody = [lit for lit in rule.body if lit is not literal]
                delta_rules.append(DeltaRule(literal, rule.head, newbody,
                                             rule))
        return delta_rules