Repository navigation
Update relevant 401 codes to 403 in middleware - #2622
hminsky2002 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The implementation, tests, OpenAPI contracts, and changelog consistently apply the corrected authorization semantics.
0 open findings
What changed in this PR
Corrects authorization semantics by returning 403 for authenticated users lacking required permissions while preserving 401 for unauthenticated requests.
Changes:
- Updates administrator and permission checks to use
ForbiddenError. - Aligns integration tests and OpenAPI responses with the new status codes.
- Documents the behavior change in the changelog.
| File | Description |
|---|---|
CHANGELOG.md |
Documents corrected authorization responses. |
src/middleware/requireAdministratorRole.ts |
Distinguishes unauthenticated and forbidden requests. |
src/middleware/__tests__/requireAdministratorRole.int.test.ts |
Tests the middleware’s 401/403 behavior. |
src/handlers/terminologySetsHandlers.ts |
Returns 403 for insufficient terminology-set permissions. |
src/handlers/opportunitiesHandlers.ts |
Returns 403 when terminology-set reference permission is absent. |
src/__tests__/terminologySets.int.test.ts |
Updates terminology and opportunity expectations. |
src/__tests__/sources.int.test.ts |
Updates administrator-only deletion expectation. |
src/__tests__/funders.int.test.ts |
Updates administrator-only funder expectations. |
src/__tests__/defaultPermissionGrants.int.test.ts |
Updates administrator-only grant expectations. |
src/__tests__/dataProviders.int.test.ts |
Updates administrator-only provider expectation. |
src/__tests__/changemakers.int.test.ts |
Updates administrator-only patch expectation. |
src/__tests__/baseFieldsCopyTasks.int.test.ts |
Updates administrator-only task expectations. |
src/__tests__/baseFields.int.test.ts |
Updates administrator-only field expectations. |
src/openapi/paths/terminologySets.json |
Documents POST 403 response. |
src/openapi/paths/terminologySet.json |
Documents PATCH 403 response. |
src/openapi/paths/source.json |
Documents DELETE 403 response. |
src/openapi/paths/funderCollaborativeMember.json |
Documents member-operation 403 responses. |
src/openapi/paths/funder.json |
Documents PUT 403 response. |
src/openapi/paths/defaultPermissionGrants.json |
Documents collection-level 403 responses. |
src/openapi/paths/defaultPermissionGrant.json |
Documents item-level 403 responses. |
src/openapi/paths/dataProvider.json |
Documents PUT 403 response. |
src/openapi/paths/changemakerFiscalSponsor.json |
Documents fiscal-sponsor 403 responses. |
src/openapi/paths/changemaker.json |
Documents PATCH 403 response. |
src/openapi/paths/baseFieldsCopyTasks.json |
Documents task-operation 403 responses. |
src/openapi/paths/baseFieldLocalization.json |
Documents localization PUT 403 response. |
src/openapi/paths/baseField.json |
Documents base-field PUT 403 response. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2622 +/- ##
=======================================
Coverage 94.19% 94.19%
=======================================
Files 345 345
Lines 4425 4428 +3
Branches 582 583 +1
=======================================
+ Hits 4168 4171 +3
Misses 256 256
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🔎 A preview deployment of this pull request is available at https://utilities.philanthropydatacommons.org/pdc-service-preview-2622-jzkgl/ (and upstream https://pdc-service-preview-2622-jzkgl.ondigitalocean.app) assuming this PR is still open. 🔍 |
an authenticated user who isn't an admin will get a 401 response on certain middleware responses, when they should be getting 403. this commit updates the relevant middleware and handlers to accomodate this Issue #2547 Use HTTP 403 in place of 401 where needed
ca79c52 to
324c3b8
Compare
an authenticated user who isn't an admin will get a 401 response on certain middleware responses, when they should be getting 403. This commit updates the relevant middleware and handlers to accomodate this!
Closes #2547