Migrate functions.config() reads to process.env#766
Merged
Conversation
Replaces the five remaining Gen 1 functions.config() reads with
direct process.env access, completing the prep needed for the
firebase-functions v6 -> v7 bump (v7 removes functions.config()
entirely; it throws on call).
Production code:
- api/basicAuth.js API_SERVICEUSER_USERNAME / _PASSWORD
- auth/createTestEmailToken.js TESTING_ENABLED
- auth/webauthnHelpers.js WEBAUTHN_RPID / _RPNAME / _ORIGINS
- auth/modes/flightnet/index.js AUTH_STATIC_CREDENTIALS
- auth/modes/ip/index.js AUTH_IPS
Drops the `process.env.K_CONFIGURATION ? {} : functions.config()`
guard in the three files that had it. The guard existed only
because functions.config() throws in Gen 2 runtimes; process.env
behaves identically in both, so the guard is dead code now.
In webauthnHelpers.js, also drops the legacy alias-handling
(`rp_id`/`expected_origins`/`expectedorigins`) and the
Array.isArray(originsRaw) branch. Env vars are always strings, so
only canonical CSV is accepted. Track 2 (GH var population) must
canonicalize any alias-using env on copy.
Spec migration is purely mechanical: jest.mock('firebase-functions
/v1', { config: ... }) replaced with process.env.X = ... in
beforeEach + delete in afterEach. Same coverage. One stale test
removed ("accepts origins as array") and two added in
webauthnHelpers.spec.js ("trims whitespace", "defaults rpName").
CI workflows (firebase-hosting-{dev,prod}.yml) extended to write
the new keys into functions/.env.<projectId> from per-env GH vars
and secrets. API_SERVICEUSER_PASSWORD and AUTH_STATIC_CREDENTIALS
are secrets; the rest are vars. Unset values render as empty
strings, which the code's existing guards treat as disabled.
This PR is gated on track 2 (populating GH vars/secrets across
the 6 dev + 5 prod environments and the WebAuthn alias audit)
before un-drafting and merging.
Full suite: 36 suites / 314 tests passing.
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.
Summary
Replaces the five remaining Gen 1
functions.config()reads with directprocess.envaccess, completing the prep work needed for the upcomingfirebase-functionsv6 → v7 bump (v7 removesfunctions.config()entirely; calling it throws).Production code (5 files):
functions/api/basicAuth.jsAPI_SERVICEUSER_USERNAME,API_SERVICEUSER_PASSWORDfirebase-functions/v1import.functions/auth/createTestEmailToken.jsTESTING_ENABLED(compared=== 'true')firebase-functions/v1import (still needed for.region().https.onRequest).functions/auth/webauthnHelpers.jsWEBAUTHN_RPID,WEBAUTHN_RPNAME(default'Flightbox'),WEBAUTHN_ORIGINS(CSV → trimmed array)rp_id/expected_origins/expectedorigins) and theArray.isArray(originsRaw)branch — env vars are always strings.functions/auth/modes/flightnet/index.jsAUTH_STATIC_CREDENTIALS(CSVuser:pass)functions/auth/modes/ip/index.jsAUTH_IPS(CSV)Also drops the
process.env.K_CONFIGURATION ? {} : functions.config()guard in the three files that had it — the guard existed only becausefunctions.config()throws in Gen 2 runtimes;process.envbehaves identically in both, so the guard is dead code now.Specs (5 files): mechanical swap —
jest.mock('firebase-functions/v1', { config: ... })replaced withprocess.env.X = ...inbeforeEachanddelete process.env.XinafterEach. Same coverage. One stale test removed inwebauthnHelpers.spec.js(accepts origins as array— no longer applicable) and two added (trims whitespace around CSV origins,defaults rpName to "Flightbox").CI workflows (
firebase-hosting-{dev,prod}.yml): heredoc extended to write the new keys from per-env GH vars and secrets.API_SERVICEUSER_PASSWORDandAUTH_STATIC_CREDENTIALSare secrets; the rest are vars. Unset values render as empty strings, which the code's guards treat as disabled.Tests: 36 suites / 314 tests passing.
grep functions.config functions/returns zero hits.Un-draft checklist (track 2 — must complete before merging)
This PR is intentionally a draft. Merging without track 2 will cause every Gen 1 function that read
functions.config()to start receiving empty values on the next deploy — auth will break.firebase functions:config:get webauthn --project <projectId>for each of the 6 dev + 5 prod projects and verify origins/rpid use the canonical keys. If any env usesrp_id/expected_origins/expectedorigins, canonicalize on copy into GH vars (or revert the alias-drop inwebauthnHelpers.jsvia follow-up commit).webauthn.originsas a JSON array (["a","b"]), convert to CSV (a,b) before settingWEBAUTHN_ORIGINS.API_SERVICEUSER_USERNAME,AUTH_IPS,TESTING_ENABLED,WEBAUTHN_RPID,WEBAUTHN_RPNAME,WEBAUTHN_ORIGINS.API_SERVICEUSER_PASSWORD,AUTH_STATIC_CREDENTIALS.createTestEmailToken.jsis now strict — only the literal string"true"enables the endpoint. SetTESTING_ENABLED=trueoncypress-testingand any other test env that needs it (no longer accepts"1","yes", etc.).API_SERVICEUSER_PASSWORDdoes not contain#,=, leading/trailing whitespace, or newlines — the CI heredoc writes raw values into a dotenv file without quoting, and those characters break the dotenv parser.AUTH_STATIC_CREDENTIALSis structurallyuser:pw,user:pw, so it's safe.Post-merge canary
build_and_deploy_functionsforlszm_test(the test project per repo convention); confirm the heredoc step renders the expected.env.<projectId>andfirebase deployreports no config errors.lszm-test: API basic-auth (200), IP-mode allowed/disallowed (success/401),createTestEmailToken(token ifTESTING_ENABLED=true, else 403), WebAuthn registration round-trip.firebase functions:log --project <projectId>— confirm nofunctions.config() is no longer availableerrors and noWebAuthn RP config missingerrors.masterfor prod rollout.Follow-up
Once this is deployed cleanly to all dev envs, PR C is a one-line
firebase-functions^6.6.0→^7.0.0bump infunctions/package.json+ lockfile.