fix(enforcer): send checkAllTenants payload and auth header correctly (PER-15318)#134
Draft
zeevmoney wants to merge 1 commit into
Draft
fix(enforcer): send checkAllTenants payload and auth header correctly (PER-15318)#134zeevmoney wants to merge 1 commit into
zeevmoney wants to merge 1 commit into
Conversation
checkAllTenants passed { headers, params } as the axios POST body (2nd
arg), so the Authorization header was never sent and the query was
nested under `params` instead of being the request body — the PDP could
neither authenticate nor read the request.
Mirror check(): send the normalized { user, action, resource, context }
as the body and pass headers/timeout as the axios config arg. Normalize
the string forms of user/resource but skip default-tenant injection,
since an all-tenants query must not be pinned to a tenant. Add an AVA
regression test asserting the auth header is sent, the body shape is
correct, and no tenant is injected.
Fixes PER-15318
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix (SDK source). Standalone — based on
main, independent of the test-modernization stack (ci: pin actions to SHA and run full test suite on PRs #131–test: comprehensive unit + e2e coverage across SDK (stacked on #132) #133). Linear: PER-15318.What is the current behavior?
Enforcer.checkAllTenantsbuilds its request incorrectly:{ headers, params }is passed as the axios POST body (the 2nd arg). Consequences:Authorizationheader is never sent as a request header → the PDP cannot authenticate the call.user / action / resource / contextare nested underparamsin the body instead of being the request payload.The method effectively cannot work against the PDP.
What is the new behavior?
Mirrors the correct
check()mechanics:headers/timeoutare the axios config (3rd) arg, so the auth header is actually sent.user/resourcestring forms are normalized the same waycheck()does ('elon'→{ key: 'elon' },'document:doc-1'→{ type: 'document', key: 'doc-1' }).check(), which injectsmultiTenancy.defaultTenant). Documented inline.sdk = 'node'default, return mapping, and the existingtry/catchare unchanged. Single-responsibility fix.Other information:
Tests
src/tests/unit/check-all-tenants.spec.ts— mocks the enforcer's PDP axios adapter and asserts:Authorization: Bearer <token>header is sent, body shape is the normalized payload, body contains noheaders/paramskeys (the old bug), no tenant is injected, and the return maps to the tenant objects. Covers string and object input forms.yarn build/tsc+yarn lintclean.Manual test plan
await permit.checkAllTenants('user-1', 'read', 'document:doc-1'). 3. Confirm the PDP receives an authenticated request and returns the allowed tenants (previously 401/empty due to the missing auth header).Adjacent issues noted (out of scope, not fixed here)
checkAllTenants'try/catchonly logs + rethrows (noPermitConnectionErrorwrapping likecheck()), andindex.tswraps the call in a second identical try/catch (double-logging on error). Candidates for a follow-up.Note on the test stack: PR test: comprehensive unit + e2e coverage across SDK (stacked on #132) #133 adds a Vitest characterization test asserting the current (buggy) body placement (flagged
TODO(PER-15318)). Once this fix and that stack both land, that characterization test should be flipped to assert the corrected behavior — happy to do that on the test: comprehensive unit + e2e coverage across SDK (stacked on #132) #133 branch.Generated with Claude Code