fix(auth): skip project config name assertion when using the Auth emulator#3142
Open
kyungseopk1m wants to merge 1 commit into
Open
fix(auth): skip project config name assertion when using the Auth emulator#3142kyungseopk1m wants to merge 1 commit into
kyungseopk1m wants to merge 1 commit into
Conversation
…lator The Auth emulator does not populate the resource `name` field on its /config responses, so getProjectConfig() and updateProjectConfig() throw "INTERNAL ASSERT FAILED: Unable to get/update project config" against the emulator. Skip the assertion in both validators when useEmulator() is true. Production behavior is unchanged — a backend response missing `name` still throws. The guard reuses the existing useEmulator() helper, matching the same dynamic-read pattern AuthResourceUrlBuilder and AuthHttpClient already use to branch on the emulator. Fixes firebase#2461.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the GET_PROJECT_CONFIG and UPDATE_PROJECT_CONFIG response validators in src/auth/auth-api-request.ts to skip the name field assertion when running against the Auth emulator. Additionally, it adds comprehensive unit tests in test/unit/auth/auth-api-request.spec.ts to verify the behavior of getProjectConfig and updateProjectConfig under both standard and emulator environments. I have no feedback to provide.
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.
Closes #2461.
Thanks @nerder and @mexican-jack for the same-symptom reports on
updateProjectConfigand password policy updates — both go through the endpoints touched here.Summary
getProjectConfig()andupdateProjectConfig()throwINTERNAL ASSERT FAILED: Unable to get/update project configwhen the Auth emulator is running. The emulator doesn't populate the resourcenamefield on/configresponses, and both endpoint validators requirenameto be a non-empty string.This PR skips that assertion when
useEmulator()is true so the call succeeds against the emulator. Production behavior is unchanged.Behavior change
FIREBASE_AUTH_EMULATOR_HOSTset):getProjectConfig()/updateProjectConfig()resolve with whatever the emulator returns.namestill throwsINTERNAL ASSERT FAILED.The Identity Toolkit
projects.getConfig/projects.updateConfigREST contract treatsnameas an output-only resource name that production always populates — the emulator just doesn't implement it.Scope
The guard is limited to
GET_PROJECT_CONFIGandUPDATE_PROJECT_CONFIGbecause those are the two endpoints with reproductions in the issue and its comments. Other validators in the same file (GET_TENANT,UPDATE_TENANT, OIDC/SAML config) follow the same pattern but have no emulator reports — leaving them out keeps the diff narrow.Password policy updates (raised by @mexican-jack) go through
updateProjectConfiginternally, so this PR covers that case as well.Implementation notes
The guard uses the existing
useEmulator()helper atsrc/auth/auth-api-request.ts:2321— the same oneAuthResourceUrlBuilder(line 134),TenantAwareAuthResourceUrlBuilder(line 200), andAuthHttpClient(line 232) use to branch on the emulator. Same dynamic-read pattern as the rest ofmain.Relationship to #3080
#3080 is open in the same area and captures the emulator host at init time instead of reading it on each call. This PR uses the dynamic
useEmulator()read because that's whatmaindoes today. If #3080 lands first, I'll rebase and switch the validator guard to the captured value so the emulator semantics stay aligned.Test coverage
test/unit/auth/auth-api-request.spec.tsadds agetProjectConfigand anupdateProjectConfigdescribe block under thesupportsTenantManagementbranch. Each has three cases:namepopulated — strictcallParamsmatch (URL, method, body, headers, timeout) for regression coveragename— still throws (covers the existing assertion)namewithFIREBASE_AUTH_EMULATOR_HOSTset — resolves, with a strict match against the emulator URLhttp://localhost:9099/identitytoolkit.googleapis.com/v2/projects/project_id/config[?updateMask=...]and theBearer owneremulator headersafterEachclearsFIREBASE_AUTH_EMULATOR_HOSTso emulator state doesn't bleed into other specs.Verification
npm run lint— 0 errors.npx mocha test/unit/auth/auth-api-request.spec.ts --require ts-node/register— 746 passing, 0 failing.npm run test:unit— 6246 passing, 0 failing.Diff: 2 files changed, +136 insertions, -1 deletion (10 LOC in
src, the rest in test).