def test_role_has_no_rule(self):
        """Test the role that is not covered by any rule."""
        rules_engine = get_rules_engine_with_rule(
            RoleRulesEngineTest.yaml_str_multiple_resource_ids_rules)
        self.assertTrue(1 <= len(rules_engine.rule_book.rules_map))

        data_creater = frsd.FakeRoleDataCreater(
            'someRoleName', ["bigquery.someres.get", "bigquery.someres.list"],
            frsd.PROJECT1)

        fake_role = data_creater.get_resource()
        got_violations = list(rules_engine.find_violations(fake_role))
        self.assertEqual(got_violations, [])
    def test_no_violation_for_rules(self):
        """Role is a correct forsetiCloudsqlViewer(project 1) that should have no violation."""
        rules_engine = get_rules_engine_with_rule(
            RoleRulesEngineTest.yaml_str_multiple_rules_on_projects)
        self.assertTrue(1 <= len(rules_engine.rule_book.rules_map))

        data_creater = frsd.FakeRoleDataCreater(
            'forsetiCloudsqlViewer',
            ["cloudsql.backupRuns.get", "cloudsql.backupRuns.list"],
            frsd.PROJECT1)

        fake_role = data_creater.get_resource()
        got_violations = list(rules_engine.find_violations(fake_role))
        self.assertEqual(got_violations, [])
    def test_no_violation_for_rules_with_multi_resource_ids(self):
        """Role is a correct forsetiBigqueryViewer that should have no violation."""
        rules_engine = get_rules_engine_with_rule(
            RoleRulesEngineTest.yaml_str_multiple_resource_ids_rules)
        self.assertTrue(1 <= len(rules_engine.rule_book.rules_map))

        data_creater = frsd.FakeRoleDataCreater('forsetiBigqueryViewer', [
            "bigquery.datasets.get", "bigquery.tables.get",
            "bigquery.tables.list"
        ], frsd.PROJECT1)

        fake_role = data_creater.get_resource()
        got_violations = list(rules_engine.find_violations(fake_role))
        self.assertEqual(got_violations, [])
    def test_violations_for_rules_on_wildcard(self):
        """Role is a incorrect forsetiBigqueryViewer that should have violations."""
        rules_engine = get_rules_engine_with_rule(
            RoleRulesEngineTest.yaml_str_multiple_rules_on_projects)
        self.assertTrue(1 <= len(rules_engine.rule_book.rules_map))

        data_creater = frsd.FakeRoleDataCreater(
            'forsetiBigqueryViewer',
            ["bigquery.datasets.get", "bigquery.tables.list"], frsd.PROJECT1)

        fake_role = data_creater.get_resource()
        got_violations = list(rules_engine.find_violations(fake_role))
        self.assertEqual(got_violations, [
            frsd.generate_violation(fake_role, 0, 'forsetiBigqueryViewer rule')
        ])