Skip to content

Fix route-level RBAC enforcement for privileged endpoints#19

Merged
osama1998H merged 2 commits into
masterfrom
codex/fix-security-report-item-2
Mar 27, 2026
Merged

Fix route-level RBAC enforcement for privileged endpoints#19
osama1998H merged 2 commits into
masterfrom
codex/fix-security-report-item-2

Conversation

@osama1998H

@osama1998H osama1998H commented Mar 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • add reusable permission-check middleware for privileged JWT routes and wire the router to enforce a route-to-permission matrix
  • add DB-backed authorization checks with superuser bypass support and canonical permission constants, including organization read/write permissions
  • seed new organization permissions, expand RBAC coverage tests, regenerate Swagger docs, and mark security report finding 2 as fixed

Testing

  • go test ./...
  • rebuilt the app image with docker compose build app
  • started the stack with docker compose up -d
  • verified migration 000003 applied and new organization permissions exist in Postgres
  • exercised live HTTP flows to confirm 403 for low-privilege users, 200 after granting users:read, and continued 403 for unrelated protected routes

Summary by CodeRabbit

  • New Features

    • Implemented role-based access control (RBAC) enforcement across all authenticated API endpoints
    • Users must now have specific permissions to access sensitive operations and administrative features
    • Superuser accounts automatically bypass all permission checks
  • Bug Fixes

    • Fixed authorization gaps on previously unprotected admin routes
  • Documentation

    • Updated API documentation to clearly specify required permissions for each endpoint
    • Added 403 Forbidden error response documentation to affected endpoints

@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@osama1998H has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 59 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 59 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b9b3bd4-0138-4156-a81b-dda3138c802d

📥 Commits

Reviewing files that changed from the base of the PR and between fb01d33 and 709891d.

📒 Files selected for processing (6)
  • internal/api/middleware/ratelimit.go
  • internal/api/middleware/ratelimit_test.go
  • internal/api/router_authorization_test.go
  • internal/repository/postgres/apikeys.go
  • internal/repository/postgres/null_scans_test.go
  • internal/repository/postgres/users.go
📝 Walkthrough

Walkthrough

This PR implements fine-grained RBAC authorization enforcement across protected API endpoints. It adds permission-validating middleware, applies it to routes requiring specific permissions, updates API documentation to reflect authorization requirements, extends the RBAC service with org-aware logic, and introduces database infrastructure and tests for permission validation.

Changes

Cohort / File(s) Summary
Documentation Metadata
docs/docs.go, docs/swagger.json, docs/swagger.yaml, internal/api/handlers/apikeys.go, internal/api/handlers/audit.go, internal/api/handlers/organizations.go, internal/api/handlers/roles.go, internal/api/handlers/users.go, internal/api/handlers/webhooks.go
Updated Swagger/OpenAPI annotations across endpoint handlers to declare required RBAC permission scopes (e.g., apikeys:read, users:*, roles:*) and added documented 403 Forbidden response entries referencing SwaggerErrorResponse.
Security Documentation
docs/security-report.md
Updated risk framing to highlight Redis fail-open behavior during outages and marked finding 2 (weak authorization on protected routes) as fixed; expanded verification details on router-level permission enforcement and superuser bypass.
Authorization Middleware
internal/api/middleware/authorization.go
New middleware implementation with RequirePermission function that validates user permissions via context-extracted identifiers, delegates to an Authorize method, and maps domain errors to HTTP responses (403, 401, 500).
Router Wiring
internal/api/router.go
Applied middleware.RequirePermission wrapping to JWT-protected endpoints across users, organizations, roles, API keys, audit logs, and webhooks to enforce permission checks at route registration.
Domain Constants
internal/domain/role.go
Added 15 new exported permission name constants (e.g., PermissionUsersRead, PermissionRolesWrite, PermissionWebhooksDelete) for canonical permission references.
Repository Authorization
internal/repository/postgres/roles.go, internal/repository/postgres/tenant_scope_test.go
Added UserHasPermission store method querying join across user roles, role permissions, and permissions table; includes org-scoped test validating permission isolation.
RBAC Service Logic
internal/service/rbac.go, internal/service/rbac_scope_test.go
Updated HasPermission signature to accept orgID; added Authorize method that handles user lookup, allows superuser bypass, checks permission, and returns domain.ErrForbidden on denial; includes test covering all three paths.
Authorization Testing
internal/api/router_authorization_test.go
Added comprehensive HTTP integration tests covering privilege enforcement on protected routes, self-service endpoint accessibility, permission grant validation, and superuser bypass behavior.
Database Migrations & Seeds
migrations/000003_organization_permissions.up.sql, migrations/000003_organization_permissions.down.sql, sql/schema.sql
Added migration and schema seed entries for organizations:read and organizations:write permissions with idempotent insert clauses.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Router & Middleware
    participant RBACService
    participant PostgreSQL
    
    Client->>Router & Middleware: HTTP Request + JWT Token
    Router & Middleware->>Router & Middleware: Extract userID, orgID from context
    
    alt Missing Identity
        Router & Middleware-->>Client: 401 Unauthorized
    else Identity Present
        Router & Middleware->>RBACService: Authorize(ctx, orgID, userID, permission)
        RBACService->>PostgreSQL: GetUserByID(orgID, userID)
        PostgreSQL-->>RBACService: User entity
        
        alt User is Superuser
            RBACService-->>Router & Middleware: nil (authorized)
        else Not Superuser
            RBACService->>PostgreSQL: UserHasPermission(orgID, userID, permission)
            PostgreSQL-->>RBACService: bool result
            
            alt Permission Granted
                RBACService-->>Router & Middleware: nil (authorized)
            else Permission Denied
                RBACService-->>Router & Middleware: ErrForbidden
                Router & Middleware-->>Client: 403 Forbidden
            end
        end
        
        alt Authorization Succeeded
            Router & Middleware->>Router & Middleware: next.ServeHTTP(w, r)
            Router & Middleware-->>Client: 200/201 OK (handler response)
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Permission checks now guard each door,
Middleware hops through routes with four
Constants clear, the rules are found,
Superusers skip around!
Authorization—hopped and done. 🔐

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: implementing route-level RBAC (Role-Based Access Control) enforcement for protected endpoints.
Description check ✅ Passed The description covers the main changes but lacks some template sections like type of change selection and explicit related issues reference, though the core information is present.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-security-report-item-2

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/api/router.go (1)

98-142: ⚠️ Potential issue | 🔴 Critical

Protected routes cannot be accessed via API keys due to missing auth middleware wiring and incompatible permission checks.

All newly protected routes (users, organizations, roles, api-keys, audit, webhooks) are gated by JWTAuth middleware, which only accepts Authorization: Bearer <JWT> tokens. The APIKeyAuth middleware exists but is never wired into the router, making it impossible for service-to-service API key clients to reach any of these endpoints. Even if APIKeyAuth were added, the RequirePermission middleware requires ContextKeyUserID to be present in the context—but APIKeyAuth only sets ContextKeyOrgID, causing authorization to fail.

Additionally, API key scopes are stored in the database (line 30 of internal/service/apikey.go) but are never validated or enforced anywhere in the middleware chain or service layer, violating the requirement that "API key scopes must control access. Always verify scopes in the service layer before allowing operations."

To fix:

  1. Create a combined auth middleware that accepts both JWT and API keys, or integrate APIKeyAuth into the protected route group.
  2. Modify RequirePermission to handle API key–authenticated requests (with scope-based access control instead of user-based RBAC).
  3. Implement scope validation in the service layer before allowing API key operations.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/api/router.go` around lines 98 - 142, Protected routes are currently
only using middleware.JWTAuth so API keys can't authenticate and
RequirePermission assumes a user ID in context, while APIKeyAuth only sets
ContextKeyOrgID and API key scopes (from internal/service/apikey.go) are never
enforced; fix by wiring a combined authenticator (or apply both
middleware.JWTAuth and middleware.APIKeyAuth) to the protected router group so
requests can authenticate with either method, update
middleware.RequirePermission to detect when ContextKeyOrgID/API key is present
and perform scope-based checks (falling back to user-based RBAC when
ContextKeyUserID is set), and enforce scope validation in the service layer
before sensitive operations (implement explicit scope checks in apikey service
methods and in services handling users/roles/webhooks/audit/api-keys such as
apiKeyH.CreateAPIKey, apiKeyH.RevokeAPIKey, webhook handlers and corresponding
service methods) to ensure API key scopes control access.
🧹 Nitpick comments (3)
internal/repository/postgres/roles.go (1)

189-190: Use the standard wrapped-error prefix here.

Please switch this to the repo format, e.g. fmt.Errorf("db.UserHasPermission: %w", err), so downstream logging and error traces stay consistent.

As per coding guidelines, "Wrap errors with context using fmt.Errorf() in the format: fmt.Errorf("<package>.<function>: %w", <error>)."

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

In `@internal/repository/postgres/roles.go` around lines 189 - 190, The error wrap
in the row.Scan call uses a freeform message; update it to use the repo standard
package+function prefix. Replace the current fmt.Errorf("check user permission:
%w", err) with fmt.Errorf("db.UserHasPermission: %w", err) inside the
UserHasPermission implementation in roles.go so downstream logging/traces follow
the standard format.
internal/api/router_authorization_test.go (2)

24-25: Missing testing.Short() guard for database-dependent tests.

Per coding guidelines, DB-dependent tests must include a testing.Short() guard to allow skipping in short mode. All tests in this file depend on the database via testutil.RequireTestStore(t).

♻️ Proposed fix: add Short() guard at the start of each test
 func TestRouterRequiresPermissionsOnPrivilegedRoutes(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping database-dependent test in short mode")
+	}
 	store := testutil.RequireTestStore(t)

Apply the same pattern to TestRouterAllowsSelfServiceEndpointsWithoutRBACPermissions, TestRouterAllowsGrantedPermissions, and TestRouterAllowsSuperuserBypass.

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

In `@internal/api/router_authorization_test.go` around lines 24 - 25, Each
DB-dependent test must skip in short mode: at the top of
TestRouterRequiresPermissionsOnPrivilegedRoutes,
TestRouterAllowsSelfServiceEndpointsWithoutRBACPermissions,
TestRouterAllowsGrantedPermissions, and TestRouterAllowsSuperuserBypass add a
guard like if testing.Short() { t.Skip("skipping DB test in short mode") }
before calling testutil.RequireTestStore(t) so the tests are skipped when
running with -short.

72-72: Unused context variable.

The ctx variable is created but only referenced in a no-op statement _ = ctx. Either use it or remove it.

♻️ Proposed fix: remove unused context
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-
 	org := testutil.CreateOrganization(t, store, "router-forbidden-org")
 	user := testutil.CreateUser(t, store, org.ID, "router-forbidden-user")
 	accessToken := issueAccessToken(t, user.ID, org.ID)
 
 	// ... test cases ...
-
-	_ = ctx
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/api/router_authorization_test.go` at line 72, The test declares an
unused context variable `ctx` that is only referenced via `_ = ctx`; remove the
unused `ctx` declaration (or replace its usage with a real use if intended) so
there are no no-op assignments left in router_authorization_test.go; look for
the `ctx` variable near the `_ = ctx` line and delete the declaration and the `_
= ctx` statement (or wire `ctx` into the test call that requires a context such
as any function that accepts `context.Context`).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/api/router_authorization_test.go`:
- Around line 178-183: The test is passing nil for the scopes parameter to
CreateAPIKey which violates the DB NOT NULL constraint; update the path closure
in router_authorization_test.go so the call to store.CreateAPIKey(ctx, orgID,
"router-delete-key", "uni", uuid.NewString(), nil, nil) supplies an empty slice
for scopes (e.g., []string{} or make([]string,0)) instead of nil; keep all other
args the same and ensure any other CreateAPIKey calls in this test use a non-nil
empty slice for scopes.

In `@internal/repository/postgres/roles.go`:
- Around line 176-185: The authorization query in UserHasPermission is filtering
on ur.org_id but user_roles only has user_id and role_id; change the query to
scope by the organization via the roles table instead—join roles (e.g., alias r)
or reference roles.org_id and replace ur.org_id with r.org_id in the WHERE
clause so the EXISTS check correctly enforces multi-tenant isolation; update the
QueryRow parameters if needed to still pass orgID, userID, permission to match
the new WHERE predicate in UserHasPermission.

In `@internal/repository/postgres/tenant_scope_test.go`:
- Around line 227-229: The test TestStoreUserHasPermissionHonorsOrgScope
currently calls RequireTestStore immediately; add a testing.Short() guard at the
top of that test so it skips when tests are run with -short. Specifically, check
testing.Short() at the start of TestStoreUserHasPermissionHonorsOrgScope and
call t.Skip("skipping DB test in short mode") before calling RequireTestStore to
avoid requiring the database in short runs.

In `@internal/service/rbac_scope_test.go`:
- Around line 59-61: In TestRBACServiceAuthorize add a testing.Short() guard
before calling RequireTestStore so the DB-backed test is skipped in short mode;
specifically, at the start of the TestRBACServiceAuthorize function check if
testing.Short() { t.Skip("skipping DB test in short mode") } and only then call
testutil.RequireTestStore and NewRBACService/NewAuditService to create the store
and services.

---

Outside diff comments:
In `@internal/api/router.go`:
- Around line 98-142: Protected routes are currently only using
middleware.JWTAuth so API keys can't authenticate and RequirePermission assumes
a user ID in context, while APIKeyAuth only sets ContextKeyOrgID and API key
scopes (from internal/service/apikey.go) are never enforced; fix by wiring a
combined authenticator (or apply both middleware.JWTAuth and
middleware.APIKeyAuth) to the protected router group so requests can
authenticate with either method, update middleware.RequirePermission to detect
when ContextKeyOrgID/API key is present and perform scope-based checks (falling
back to user-based RBAC when ContextKeyUserID is set), and enforce scope
validation in the service layer before sensitive operations (implement explicit
scope checks in apikey service methods and in services handling
users/roles/webhooks/audit/api-keys such as apiKeyH.CreateAPIKey,
apiKeyH.RevokeAPIKey, webhook handlers and corresponding service methods) to
ensure API key scopes control access.

---

Nitpick comments:
In `@internal/api/router_authorization_test.go`:
- Around line 24-25: Each DB-dependent test must skip in short mode: at the top
of TestRouterRequiresPermissionsOnPrivilegedRoutes,
TestRouterAllowsSelfServiceEndpointsWithoutRBACPermissions,
TestRouterAllowsGrantedPermissions, and TestRouterAllowsSuperuserBypass add a
guard like if testing.Short() { t.Skip("skipping DB test in short mode") }
before calling testutil.RequireTestStore(t) so the tests are skipped when
running with -short.
- Line 72: The test declares an unused context variable `ctx` that is only
referenced via `_ = ctx`; remove the unused `ctx` declaration (or replace its
usage with a real use if intended) so there are no no-op assignments left in
router_authorization_test.go; look for the `ctx` variable near the `_ = ctx`
line and delete the declaration and the `_ = ctx` statement (or wire `ctx` into
the test call that requires a context such as any function that accepts
`context.Context`).

In `@internal/repository/postgres/roles.go`:
- Around line 189-190: The error wrap in the row.Scan call uses a freeform
message; update it to use the repo standard package+function prefix. Replace the
current fmt.Errorf("check user permission: %w", err) with
fmt.Errorf("db.UserHasPermission: %w", err) inside the UserHasPermission
implementation in roles.go so downstream logging/traces follow the standard
format.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e5ddc56-8f1f-457c-b8a7-342e52538dda

📥 Commits

Reviewing files that changed from the base of the PR and between 96b3e37 and fb01d33.

📒 Files selected for processing (21)
  • docs/docs.go
  • docs/security-report.md
  • docs/swagger.json
  • docs/swagger.yaml
  • internal/api/handlers/apikeys.go
  • internal/api/handlers/audit.go
  • internal/api/handlers/organizations.go
  • internal/api/handlers/roles.go
  • internal/api/handlers/users.go
  • internal/api/handlers/webhooks.go
  • internal/api/middleware/authorization.go
  • internal/api/router.go
  • internal/api/router_authorization_test.go
  • internal/domain/role.go
  • internal/repository/postgres/roles.go
  • internal/repository/postgres/tenant_scope_test.go
  • internal/service/rbac.go
  • internal/service/rbac_scope_test.go
  • migrations/000003_organization_permissions.down.sql
  • migrations/000003_organization_permissions.up.sql
  • sql/schema.sql

Comment thread internal/api/router_authorization_test.go
Comment on lines +176 to +185
func (s *Store) UserHasPermission(ctx context.Context, orgID, userID uuid.UUID, permission string) (bool, error) {
row := s.pool.QueryRow(ctx,
`SELECT EXISTS (
SELECT 1
FROM user_roles ur
JOIN role_permissions rp ON rp.role_id = ur.role_id
JOIN permissions p ON p.id = rp.permission_id
WHERE ur.org_id = $1 AND ur.user_id = $2 AND p.name = $3
)`,
orgID, userID, permission,

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 | 🔴 Critical

user_roles.org_id will break this authorization query.

Line 183 filters on ur.org_id, but user_roles only stores user_id and role_id. That means this new RBAC path will fail with a SQL error instead of returning allow/deny. Scope through roles.org_id here.

🐛 Proposed fix
 func (s *Store) UserHasPermission(ctx context.Context, orgID, userID uuid.UUID, permission string) (bool, error) {
 	row := s.pool.QueryRow(ctx,
 		`SELECT EXISTS (
 			SELECT 1
 			FROM user_roles ur
+			JOIN roles r ON r.id = ur.role_id
 			JOIN role_permissions rp ON rp.role_id = ur.role_id
 			JOIN permissions p ON p.id = rp.permission_id
-			WHERE ur.org_id = $1 AND ur.user_id = $2 AND p.name = $3
+			WHERE r.org_id = $1 AND ur.user_id = $2 AND p.name = $3
 		)`,
 		orgID, userID, permission,
 	)

As per coding guidelines, "Multi-tenancy isolation must be enforced: every repository query must filter by org_id. No exceptions."

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

In `@internal/repository/postgres/roles.go` around lines 176 - 185, The
authorization query in UserHasPermission is filtering on ur.org_id but
user_roles only has user_id and role_id; change the query to scope by the
organization via the roles table instead—join roles (e.g., alias r) or reference
roles.org_id and replace ur.org_id with r.org_id in the WHERE clause so the
EXISTS check correctly enforces multi-tenant isolation; update the QueryRow
parameters if needed to still pass orgID, userID, permission to match the new
WHERE predicate in UserHasPermission.

Comment on lines +227 to +229
func TestStoreUserHasPermissionHonorsOrgScope(t *testing.T) {
store := testutil.RequireTestStore(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)

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

Skip this DB-backed test in short mode.

Line 228 hits RequireTestStore immediately, so go test -short ./... will still require the database. Please add a testing.Short() guard before creating the store.

💡 Minimal fix
 func TestStoreUserHasPermissionHonorsOrgScope(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping DB-dependent test in short mode")
+	}
 	store := testutil.RequireTestStore(t)
 	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
As per coding guidelines, "DB-dependent tests must include testing.Short() guard."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestStoreUserHasPermissionHonorsOrgScope(t *testing.T) {
store := testutil.RequireTestStore(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
func TestStoreUserHasPermissionHonorsOrgScope(t *testing.T) {
if testing.Short() {
t.Skip("skipping DB-dependent test in short mode")
}
store := testutil.RequireTestStore(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/repository/postgres/tenant_scope_test.go` around lines 227 - 229,
The test TestStoreUserHasPermissionHonorsOrgScope currently calls
RequireTestStore immediately; add a testing.Short() guard at the top of that
test so it skips when tests are run with -short. Specifically, check
testing.Short() at the start of TestStoreUserHasPermissionHonorsOrgScope and
call t.Skip("skipping DB test in short mode") before calling RequireTestStore to
avoid requiring the database in short runs.

Comment on lines +59 to +61
func TestRBACServiceAuthorize(t *testing.T) {
store := testutil.RequireTestStore(t)
svc := NewRBACService(store, NewAuditService(store, testutil.DiscardLogger()))

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

Skip this DB-backed test in short mode.

Line 60 calls RequireTestStore unconditionally, so go test -short ./... still needs Postgres. Add a testing.Short() guard before the store is created.

💡 Minimal fix
 func TestRBACServiceAuthorize(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping DB-dependent test in short mode")
+	}
 	store := testutil.RequireTestStore(t)
 	svc := NewRBACService(store, NewAuditService(store, testutil.DiscardLogger()))
As per coding guidelines, "DB-dependent tests must include testing.Short() guard."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestRBACServiceAuthorize(t *testing.T) {
store := testutil.RequireTestStore(t)
svc := NewRBACService(store, NewAuditService(store, testutil.DiscardLogger()))
func TestRBACServiceAuthorize(t *testing.T) {
if testing.Short() {
t.Skip("skipping DB-dependent test in short mode")
}
store := testutil.RequireTestStore(t)
svc := NewRBACService(store, NewAuditService(store, testutil.DiscardLogger()))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/service/rbac_scope_test.go` around lines 59 - 61, In
TestRBACServiceAuthorize add a testing.Short() guard before calling
RequireTestStore so the DB-backed test is skipped in short mode; specifically,
at the start of the TestRBACServiceAuthorize function check if testing.Short() {
t.Skip("skipping DB test in short mode") } and only then call
testutil.RequireTestStore and NewRBACService/NewAuditService to create the store
and services.

@osama1998H osama1998H merged commit 31724b4 into master Mar 27, 2026
4 checks passed
@osama1998H osama1998H deleted the codex/fix-security-report-item-2 branch March 27, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant