Repository navigation
fix(delete-user-data): reject invalid select and regex param values at deploy #3278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bfd3441
fix(delete-user-data): reject invalid select and regex param values a…
CorieW b13b5d5
fix(delete-user-data): accept the Shallow and No option labels
CorieW dce498f
fix(delete-user-data): default a blank RTDB location to us-central1
CorieW d279add
fix(delete-user-data): tidy invalid-param errors, docs and tests
CorieW 45e1bd1
fix(delete-user-data): keep a blank RTDB location unset
CorieW f5c0a75
fix(delete-user-data): report blank and invalid params in one error
CorieW 45e9494
Merge remote-tracking branch 'origin/kits' into fix/kits-delete-user-…
CorieW 32a478f
fix(delete-user-data): accept option labels as the extension did
CorieW 78ccd89
fix(delete-user-data): fix the select label type error
CorieW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /** | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { afterEach, beforeAll, describe, expect, test, vi } from "vitest"; | ||
|
|
||
| let assertValidParams: () => void; | ||
|
|
||
| beforeAll(async () => { | ||
| process.env.FIREBASE_KIT_INSTANCE_ID ??= "test-instance"; | ||
| ({ assertValidParams } = await import("../src/config")); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| // Values the published extension's install API rejects (checked with | ||
| // `validateOnly` against firebase/delete-user-data@0.1.30). | ||
| const REJECTED: Array<[string, string, string]> = [ | ||
| ["FIRESTORE_DELETE_MODE", "RECURSIVE", "recursive, shallow"], | ||
| ["FIRESTORE_DELETE_MODE", "recursivex", "recursive, shallow"], | ||
| ["FIRESTORE_DELETE_MODE", "recursive ", "recursive, shallow"], | ||
| ["ENABLE_AUTO_DISCOVERY", "true", "yes, no"], | ||
| ["ENABLE_AUTO_DISCOVERY", "YES", "yes, no"], | ||
| [ | ||
| "SELECTED_DATABASE_LOCATION", | ||
| "us-east1", | ||
| "us-central1, europe-west1, asia-southeast1", | ||
| ], | ||
| [ | ||
| "SELECTED_DATABASE_LOCATION", | ||
| "US-CENTRAL1", | ||
| "us-central1, europe-west1, asia-southeast1", | ||
| ], | ||
| [ | ||
| "SELECTED_DATABASE_INSTANCE", | ||
| "https://x.firebaseio.com", | ||
| "Invalid database instance", | ||
| ], | ||
| ["CLOUD_STORAGE_BUCKET", "gs://x", "Invalid storage bucket"], | ||
| ["CLOUD_STORAGE_BUCKET", "Upper_Case", "Invalid storage bucket"], | ||
| ["CLOUD_STORAGE_BUCKET", "abc\n", "Invalid storage bucket"], | ||
| ["SELECTED_DATABASE_INSTANCE", "abc\n", "Invalid database instance"], | ||
| [ | ||
| "SELECTED_DATABASE_LOCATION", | ||
| " ", | ||
| "us-central1, europe-west1, asia-southeast1", | ||
| ], | ||
| ]; | ||
|
|
||
| const ACCEPTED: Array<[string, string]> = [ | ||
| ["FIRESTORE_DELETE_MODE", "recursive"], | ||
| ["FIRESTORE_DELETE_MODE", "shallow"], | ||
| ["ENABLE_AUTO_DISCOVERY", "yes"], | ||
| ["ENABLE_AUTO_DISCOVERY", "no"], | ||
| ["SELECTED_DATABASE_LOCATION", "us-central1"], | ||
| ["SELECTED_DATABASE_LOCATION", "europe-west1"], | ||
| ["SELECTED_DATABASE_LOCATION", "asia-southeast1"], | ||
| ["SELECTED_DATABASE_INSTANCE", "my-instance"], | ||
| ["SELECTED_DATABASE_INSTANCE", " my-instance"], | ||
| ["SELECTED_DATABASE_INSTANCE", "a b"], | ||
| ["CLOUD_STORAGE_BUCKET", "my-project-12345.appspot.com"], | ||
| ["CLOUD_STORAGE_BUCKET", "my_bucket-1.example"], | ||
| ]; | ||
|
CorieW marked this conversation as resolved.
|
||
|
|
||
| describe("assertValidParams", () => { | ||
| test("passes when no params have been supplied yet", () => { | ||
| expect(() => assertValidParams()).not.toThrow(); | ||
| }); | ||
|
|
||
| test.each(REJECTED)("rejects %s=%j", (name, value, allowed) => { | ||
| vi.stubEnv(name, value); | ||
|
|
||
| expect(() => assertValidParams()).toThrow( | ||
| `${name}=${JSON.stringify(value)}` | ||
| ); | ||
| expect(() => assertValidParams()).toThrow(allowed); | ||
| }); | ||
|
|
||
| test.each(ACCEPTED)("accepts %s=%j", (name, value) => { | ||
| vi.stubEnv(name, value); | ||
|
|
||
| expect(() => assertValidParams()).not.toThrow(); | ||
| }); | ||
|
|
||
| // The extension's installer accepts a select label and stores it verbatim, | ||
| // so the kit accepts it too, even though `Recursive` then runs as shallow | ||
| // and `Yes` as off, as they did in the extension. | ||
| test.each([ | ||
| ["FIRESTORE_DELETE_MODE", "Recursive"], | ||
| ["FIRESTORE_DELETE_MODE", "Shallow"], | ||
| ["ENABLE_AUTO_DISCOVERY", "Yes"], | ||
| ["ENABLE_AUTO_DISCOVERY", "No"], | ||
| ["SELECTED_DATABASE_LOCATION", "United States"], | ||
| ["SELECTED_DATABASE_LOCATION", "Belgium"], | ||
| ["SELECTED_DATABASE_LOCATION", "Singapore"], | ||
| ])("accepts the option label %s=%j", (name, value) => { | ||
| vi.stubEnv(name, value); | ||
|
|
||
| expect(() => assertValidParams()).not.toThrow(); | ||
| }); | ||
|
|
||
| // Blank values belong to assertRequiredParams; optional ones may be blank, | ||
| // as in the extension. | ||
| test.each([ | ||
| "FIRESTORE_DELETE_MODE", | ||
| "ENABLE_AUTO_DISCOVERY", | ||
| "SELECTED_DATABASE_LOCATION", | ||
| "SELECTED_DATABASE_INSTANCE", | ||
| "CLOUD_STORAGE_BUCKET", | ||
| ])("leaves an empty %s alone", (name) => { | ||
| vi.stubEnv(name, ""); | ||
|
|
||
| expect(() => assertValidParams()).not.toThrow(); | ||
| }); | ||
|
|
||
| test("names every invalid param in one error", () => { | ||
| vi.stubEnv("FIRESTORE_DELETE_MODE", "RECURSIVE"); | ||
| vi.stubEnv("ENABLE_AUTO_DISCOVERY", "true"); | ||
|
|
||
| expect(() => assertValidParams()).toThrow( | ||
| /FIRESTORE_DELETE_MODE="RECURSIVE".*; ENABLE_AUTO_DISCOVERY="true"/ | ||
| ); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.