NO-ISSUE: Add test for tenant visibility enforcement on creation - #504
Conversation
Remove the privileged `auth.ContextWithSubject` setup that was injecting a system user with universal tenants into the test context. The tests now rely solely on the mocked `TenancyLogic` to determine tenant visibility, which better reflects real request flows. Add a new test case that verifies the server rejects object creation with `PermissionDenied` when the requested tenant is not visible to the caller. This exercises the path where a user attempts to assign a tenant that exists in the template but falls outside their own visible set. Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
|
@jhernand: This pull request explicitly references no jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughThis PR modifies a tenancy-focused test suite in Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/servers/servers_tenancy_test.go`:
- Around line 299-307: The new ClusterTemplate_builder instance is missing Title
and Description which other templates include; update the template created in
the test (the ClusterTemplate_builder used at the shown diff) to set non-empty
Title and Description fields (e.g., call Title: "..." and Description: "..." on
the same builder) so the schema/DAO validation won't fail and
Expect(err).ToNot(HaveOccurred()) can pass; ensure the builder uses the same
field names (Title and Description) as the other templates in this test file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c79c852b-a395-4a70-a650-975f3c0562d5
📒 Files selected for processing (1)
internal/servers/servers_tenancy_test.go
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CrystalChun, jhernand The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest-required |
1 similar comment
|
/retest-required |
Summary
auth.ContextWithSubjectsetup from the tenancy testBeforeEach, sotests rely on the mocked
TenancyLogicrather than a system-level bypass. This better reflectshow real requests are processed.
PermissionDeniedwhen a user tries tocreate an object with a tenant that exists in the template but is invisible to the caller.
Test plan
ginkgo run -r internal --focus="Tenancy logic"and confirm all four test cases pass.Summary by CodeRabbit