Ejemplo n.º 1
0
    def _GenerateRule(self, **kwargs):
        """Generate the rule for the blockable being voted on.

    Args:
      **kwargs: Arguments to be passed to the SantaRule constructor for all
          returned rules.
    Returns:
      An un-persisted SantaRule corresponding to the blockable being voted on.
    """
        return santa.SantaRule(parent=self.blockable.key,
                               rule_type=self.blockable.rule_type,
                               **kwargs)
Ejemplo n.º 2
0
def EnsureCritialRules():
    """Pre-populates Datastore with any critical Rule entities."""
    for critical_hash in settings.CRITICAL_MAC_OS_CERT_HASHES:

        cert = santa.SantaCertificate.get_by_id(critical_hash)

        if not cert:
            cert = santa.SantaCertificate(id=critical_hash,
                                          id_type=constants.ID_TYPE.SHA256)
            cert.put()

        # Check for at least one matching SantaRule.
        rule_missing = santa.SantaRule.query(ancestor=cert.key).get(
            keys_only=True) is None

        # Doesn't exist? Add it!
        if rule_missing:
            santa.SantaRule(parent=cert.key,
                            rule_type=constants.RULE_TYPE.CERTIFICATE,
                            policy=constants.RULE_POLICY.WHITELIST).put()
Ejemplo n.º 3
0
    def setUp(self, app):
        super(RulesTest, self).setUp(wsgi_app=app)

        self.blockable1 = test_utils.CreateBlockable()
        self.blockable2 = test_utils.CreateBlockable()

        self.rule_1 = base.Rule(parent=self.blockable1.key,
                                id=123456,
                                rule_type='BINARY',
                                policy='WHITELIST')
        self.rule_2 = base.Rule(parent=self.blockable2.key,
                                id=123457,
                                rule_type='BINARY',
                                policy='BLACKLIST')
        self.rule_3 = santa.SantaRule(parent=self.blockable2.key,
                                      id=123458,
                                      rule_type='BINARY',
                                      policy='WHITELIST')
        self.rule_1.put()
        self.rule_2.put()
        self.rule_3.put()

        self.PatchValidateXSRFToken()