Skip to content
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

Fixes a number of issues where ext:dev:emulator:* did not allow valid extension configurations #3529

Merged
merged 11 commits into from
Jul 7, 2021

Conversation

joehan
Copy link
Contributor

@joehan joehan commented Jun 23, 2021

Description

Fixes a bunch of issues where the param and spec validation for the extension emulator behaved badly:

  • False-y default values were broken in multiple places. I went through and fixed these.
  • Param validation was happening before variable substitution. I refactored buildOptions to make sure this happened first.
  • Spec validation for params with defaults did not substitute autopopulated params into those defaults. We were also checking defaults against validationRegex. This meant that these regex checks would fail for some defaults that referenced autopopulated params. I removed this.

I also did some minor modernization and cleanup of these files.
Fixes #2928

  • Scenarios Tested

I tested a number of extension that Invertase reported were broken on the emulator. I also found some cases where the Storage and auth emulators weren't working correctly with extension - I'm going to try to fix that in a followup.

@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Jun 23, 2021
@joehan joehan marked this pull request as ready for review June 24, 2021 20:12
@joehan joehan requested a review from huangjeff5 June 24, 2021 20:16
@@ -13,7 +13,7 @@ export function checkResponse(response: string, spec: Param): boolean {
let valid = true;
let responses: string[];

if (spec.required && !response) {
if (spec.required && (response == "" || response == undefined)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit ugly, but necessary to cover both the case where a param is completely omitted from the .env file, and the case where a param is set to nothing in the .env file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait can you help me understand how this code change is any different?

let a;
if(!a) {
  console.log("undefined!")
}
a = ""
if(!a) {
  console.log("empty string!")
}

=> "undefined!"
=> "empty string!"

https://jsfiddle.net/cvyb3fja/

The !response condition seems to capture empty string and undefined value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, looking at this again, I think the real issue is that the typing here is pretty wonky. The YAML parser and .ENV parser we use cast strings that look like numbers or booleans to actual numbers or booleans, and we don't always cast those back to strings before passing them around. In this case, this was breaking if you ever tried to set a param to "false" or "0" - the parsers would cast those to boolean false or number 0, and suddenly !response == true.

If you think this is too hacky, I can try to fix these typing issues in this PR as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we're trying to exclude the response=false from falling into this if block? Maybe we should explicitly specify that?

i.e. (!response && response !== false)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAML parsing is full of weird surprises..

@joehan joehan requested a review from taeold June 24, 2021 20:18
@@ -13,7 +13,7 @@ export function checkResponse(response: string, spec: Param): boolean {
let valid = true;
let responses: string[];

if (spec.required && !response) {
if (spec.required && (response == "" || response == undefined)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait can you help me understand how this code change is any different?

let a;
if(!a) {
  console.log("undefined!")
}
a = ""
if(!a) {
  console.log("empty string!")
}

=> "undefined!"
=> "empty string!"

https://jsfiddle.net/cvyb3fja/

The !response condition seems to capture empty string and undefined value.

src/extensions/emulator/optionsHelper.ts Show resolved Hide resolved
src/extensions/emulator/optionsHelper.ts Outdated Show resolved Hide resolved
src/extensions/extensionsHelper.ts Show resolved Hide resolved
src/extensions/emulator/optionsHelper.ts Show resolved Hide resolved
src/extensions/extensionsHelper.ts Outdated Show resolved Hide resolved
src/extensions/extensionsHelper.ts Outdated Show resolved Hide resolved
src/extensions/extensionsHelper.ts Show resolved Hide resolved
src/test/extensions/emulator/optionsHelper.spec.ts Outdated Show resolved Hide resolved
@joehan joehan merged commit 8680f9b into master Jul 7, 2021
devpeerapong pushed a commit to devpeerapong/firebase-tools that referenced this pull request Dec 14, 2021
… extension configurations (firebase#3529)

* fixes a number of issues where ext:dev:emulator:* did not allow valid extension configurations

* Adding tests for cases fixed

* add changelog

* format

* pr fixes

* correct a comment
@bkendall bkendall deleted the jh-ext-emu-fixes branch March 18, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default PARAM isn't being injected during extension emulation
3 participants