Rego is the declarative policy language used by Open Policy Agent (OPA) for writing and enforcing policies across cloud-native stacks, featuring data-driven rules, comprehensions, and 200+ built-in functions for infrastructure, security, and compliance automation.
Overall
score
97%
Create a simple content moderation policy using Rego, following a strict test-driven development workflow.
Create policy_test.rego before implementing the policy. The test package must be package policy_test.
Include the following tests:
test_allow_approved_content — input with category set to "news" should be allowedtest_deny_flagged_content — input with category set to "spam" should be deniedtest_deny_missing_category — input with no category field should be deniedUse the with input as { ... } keyword to provide mock input in each test.
Create policy.rego with package policy and import rego.v1.
The policy must:
deny (i.e., default allow := false)allow rule that permits content when input.category is one of: "news", "sports", "technology"Run opa test . -v and confirm all tests pass.