Repository navigation
test(api): answer region-scoped Azure exchange tests from the real matcher - #1148
Conversation
…tcher newAzureRegionScopedHandler hand-wrote auth.matchAllRegionsConstraint's all-match rule and returned its own verdict as the authorization answer, so the region-denial tests stayed green with the production matcher regressed to containsAny's any-match rule. Grant execute:ri-exchange constrained to eastus through grantPermissions instead, so auth.PermissionsAllowForConstraintSets decides on the constraint set the handler actually built. The submitted set is recovered from the mock's recorded calls, and a positive control proves the same grant allows an exchange that stays inside eastus. Closes LeanerCloud#208 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 1
✨ Finishing Touches
Comment |
|
Independent review (claude-cc-platform reviewer, cold brief): APPROVE No blocking findings. The change is test-only: one file, Real matcher: the helper now grants Mutation probes on
Claims: accurate. The matcher on main is already all-match, so no production bug was masked. Determinism: the 4 touched tests pass 20/20 runs each. Base drift: clean merge onto current main. Nits:
|
|
Independent review (claude-fleet): APPROVE baae966 Findings (none blocking):
Attacked:
Verified locally on a
Reviewed by an independent agent with no author context. Review only: nothing was pushed, and the GitHub review state is unchanged. |
|
Local verification (macOS, exact head Gate status: two independent reviews approve this SHA (posted above), local verification passes, and CI is green. Merge waits on @IAmJSD marking the PR ready (see #974). |
|
Local verification at
|
|
Marked ready and merged by the owner's agent after 2 independent reviews and local verification (see the review and verification comments above, all at |
Root cause
newAzureRegionScopedHandler(internal/api/handler_ri_exchange_azure_test.go) hand-wrote apermitsclosure that copiedauth.matchAllRegionsConstraint's all-match rule, then handed its own verdict back to the handler through twomock.MatchedByexpectations. The region property that the tests built on it assert was therefore decided by the test, not by the production matcher. IfmatchAllRegionsConstraintregressed tocontainsAny(the any-match bug it was written to fix), every one of those tests stayed green.Fix (test-only)
execute:ri-exchangewithConstraints{Regions: ["eastus"]}throughMockAuthService.grantPermissions. That routesHasPermissionForConstraintsAPIthroughauth.PermissionsAllowForConstraintSets, so the real matcher evaluates the constraint set the handler actually built.capturedpointer is gone. A newsubmittedConstraintSets(t, mockAuth)reads the constraint set from the mock's recorded calls. It requires exactly one constraint check foruser-1/execute/ri-exchange, so the "which regions did the handler think it touches" assertions still hold.HasPermissionAPI(ctx, "user-1", "execute", "ri-exchange")expectation is still required, now as anAssertCalledin cleanup, becausegrantPermissionsregisters the verb check as.Maybe().TestExecuteAzureExchange_RegionScopedCallerAllowedInsideRegion: the same eastus-only grant must allow an exchange whose source and target are both in eastus. Without it, a grant or matcher that denied everything would satisfy the denial tests without testing anything.permittedRegionparameter is dropped (every caller passed"eastus", andunparamflagged it).mock.MatchedByclosures the issue lists as legitimate are unchanged. No production code is changed.Closes #208
Verification
All evidence below is unit/mock level (
MockAuthServiceplus a testify Azure exchange client mock). No real Azure or AWS calls. Tests were run withAWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/nullbecause the local machine's default AWS profile is invalid.Mutation probes. Each one was applied to
internal/auth/service_group.gomatchAllRegionsConstraintright after the empty-list guard, then reverted. Each test was run on its own withgo test ./internal/api/ -count=1 -run 'TestExecuteAzureExchange_<name>$':return containsAny(permRegions, reqRegions)(any-match regression)return false(deny-all)CalculateExchangecall)Before the fix, the
origin/maintest file under the samecontainsAnymutation: SourceRegionOutsidePermissionRefused, UnreportedSourceRegionRefused and UnownedSourceDenialsAreIndistinguishable all PASS. That is the gap the issue describes.UnownedSourceDenialsAreIndistinguishableis expected to be insensitive to the matcher. The ownership gate runs before the constraint check, and the test asserts that two denials look the same, not region enforcement.CI-equivalent checks (all clean):
No DB, migration or concurrency surface is touched.
Out of scope
requirePermissionConstraints.HasAPIKeyPermissionForConstraintsAPIis still constant-stubbed byallowConstraintChecks. The issue tracks this separately because the mock needs both key and owner permission sets.newAzureExecuteHandler/newAzureExecuteMoneyPathHandlerstill return a constanttruefrom the constraint check. They model an unconstrained permission and are not region tests, so I left them alone.Maintainer: please mirror the issue's triage labels onto this PR:
priority/p2,severity/medium,urgency/this-quarter,impact/internal,effort/m,type/chore,triaged.🤖 Generated with Claude Code