Skip to content

[EnforceAuth] Add policy: Create Policy Test#15

Open
boorad wants to merge 3 commits into
developfrom
ea/policy/create-policy-test-1773196208773
Open

[EnforceAuth] Add policy: Create Policy Test#15
boorad wants to merge 3 commits into
developfrom
ea/policy/create-policy-test-1773196208773

Conversation

@boorad
Copy link
Copy Markdown
Contributor

@boorad boorad commented Mar 11, 2026

New Policy: Create Policy Test


Created via EnforceAuth

Summary by CodeRabbit

  • Tests
    • Added a new policy test that implements a minimal deny-all rule to expand policy testing coverage. This validates policy behavior for retail API flows, helps catch regressions early, and strengthens safety assurances for policy changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5d49e8c4-ba59-4625-aa28-36ddc5f11746

📥 Commits

Reviewing files that changed from the base of the PR and between 1d529c0 and 949b433.

📒 Files selected for processing (1)
  • infra/opa/policies/retail/retail_api/create_policy_test.rego
🚧 Files skipped from review as they are similar to previous changes (1)
  • infra/opa/policies/retail/retail_api/create_policy_test.rego

📝 Walkthrough

Walkthrough

A new Open Policy Agent test policy file was added at infra/opa/policies/retail/retail_api/create_policy_test.rego containing a package declaration, rego.v1 import, and a default deny (default allow = false) rule for testing.

Changes

Cohort / File(s) Summary
OPA Test Policy
infra/opa/policies/retail/retail_api/create_policy_test.rego
Added new Rego test policy file with package create_policy_test, import rego.v1, and default allow = false (deny-all) rule for tests.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 I nibble on lines of Rego at play,
A tiny test file hops into the fray.
Default deny keeps mischief at bay,
One snug rule to guard the way.
Hop, hop — the policies stay!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a new test policy file for the Create Policy functionality, which matches the added Rego test policy file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ea/policy/create-policy-test-1773196208773
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Regal (0.39.0)
infra/opa/policies/retail/retail_api/create_policy_test.rego

{
"errors": [
"error(s) encountered while linting: errors encountered when reading files to lint: failed to parse 1 module(s) — first error: 1 error occurred: infra/opa/policies/retail/retail_api/create_policy_test.rego:1: rego_parse_error: expected METADATA block, found whitespace\n\t# METADATA\n\t^"
]
}


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR adds a new OPA Rego policy file for "Create Policy Test". The policy structure is valid but incomplete and non-functional - it only defines a default deny rule without any allow conditions, which will block all requests.

Critical Issue

  • The policy needs allow rules to be functional. Currently, it will deny all requests because only default allow = false is defined with no conditions for allowing access.

Please add appropriate allow rules based on the intended authorization requirements, or clarify if this deny-all behavior is intentional for testing purposes.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.


import rego.v1

default allow = false
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: This policy will deny all requests because it only defines default allow = false with no allow rules. Add at least one allow rule to make this policy functional, or if this is intentional for testing, add a comment explaining the deny-all behavior.

Suggested change
default allow = false
default allow = false
# TODO: Add allow rules to define when access should be granted
# Example:
# allow if {
# input.user.role == "admin"
# }

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
infra/opa/policies/retail/retail_api/create_policy_test.rego (1)

1-1: Package name does not match directory structure.

The file is located at infra/opa/policies/retail/retail_api/create_policy_test.rego, but the package is declared as create_policy_test. Per OPA conventions, the package path should mirror the directory structure for policy discoverability and correct resolution.

Consider updating to reflect the directory hierarchy:

-package create_policy_test
+package retail.retail_api.create_policy_test

Adjust the package prefix based on your OPA bundle root configuration.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infra/opa/policies/retail/retail_api/create_policy_test.rego` at line 1, The
package declaration "package create_policy_test" doesn't reflect the file's
directory path; update the package line (replace the existing "package
create_policy_test") to mirror the directory hierarchy (for example "package
retail.retail_api.create_policy_test" or the correct prefix based on your OPA
bundle root) so the package path matches infra/opa/policies/retail/retail_api;
ensure the new package exactly matches your bundle root convention so rules in
this file are discovered correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@infra/opa/policies/retail/retail_api/create_policy_test.rego`:
- Line 1: The package declaration "package create_policy_test" doesn't reflect
the file's directory path; update the package line (replace the existing
"package create_policy_test") to mirror the directory hierarchy (for example
"package retail.retail_api.create_policy_test" or the correct prefix based on
your OPA bundle root) so the package path matches
infra/opa/policies/retail/retail_api; ensure the new package exactly matches
your bundle root convention so rules in this file are discovered correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b2493ac-e284-40c0-b414-251713c89430

📥 Commits

Reviewing files that changed from the base of the PR and between 375c1c7 and 39cb25a.

📒 Files selected for processing (1)
  • infra/opa/policies/retail/retail_api/create_policy_test.rego

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@infra/opa/policies/retail/retail_api/create_policy_test.rego`:
- Line 4: The package declaration currently reads "create_policy_test" and
should be renamed to match the repo pattern; update the package line in
create_policy_test to "retail.retail_api.create_policy_test" so it mirrors
sibling files like retail.retail_api.accounts_test and
retail.retail_api.authentication_test, ensuring the package path matches the
directory structure and existing policy tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 451c8c00-12a3-452c-b10b-bc926fc79d9c

📥 Commits

Reviewing files that changed from the base of the PR and between 39cb25a and 1d529c0.

📒 Files selected for processing (1)
  • infra/opa/policies/retail/retail_api/create_policy_test.rego

# METADATA
# title: Create Policy Test

package create_policy_test
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

python - <<'PY'
from pathlib import Path

root = Path("infra/opa/policies")
for path in sorted(root.rglob("*.rego")):
    package = None
    for line in path.read_text().splitlines():
        stripped = line.strip()
        if stripped.startswith("package "):
            package = stripped.split(None, 1)[1]
            break
    print(f"{path}: {package}")
PY

Repository: EnforceAuth/ea-financial

Length of output: 3311


Rename the package to match the directory structure and sibling policies.

The package should be retail.retail_api.create_policy_test, not create_policy_test. All other files in this directory follow the pattern where the package mirrors the path: retail.retail_api.accounts_test, retail.retail_api.authentication_test, etc. Update the package declaration on line 4 to be consistent with the rest of the codebase.

🧰 Tools
🪛 Regal (0.39.0)

[error] 4-4: Directory structure should mirror package

(idiomatic)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infra/opa/policies/retail/retail_api/create_policy_test.rego` at line 4, The
package declaration currently reads "create_policy_test" and should be renamed
to match the repo pattern; update the package line in create_policy_test to
"retail.retail_api.create_policy_test" so it mirrors sibling files like
retail.retail_api.accounts_test and retail.retail_api.authentication_test,
ensuring the package path matches the directory structure and existing policy
tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant