-
Notifications
You must be signed in to change notification settings - Fork 798
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
fix(telemetry): handle malformed telemetry tokens #3014
Conversation
@@ -25,7 +30,10 @@ export async function readConfig(): Promise<TelemetryConfig> { | |||
}; | |||
|
|||
await writeConfig(config); | |||
} else if (!!config && !config['tokens.telemetry'].match(UUID_REGEX)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the line that was failing. If the config file existed, but 'tokens.telemetry' either:
- existed and wasn't a string
- did not exist at all
we would call match()
on "something" that didn't have it in it's prototype chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be safe to do the inverse and call RegExp.test()
with "something" as an argument, i.e. !UUID_REGEX.test(config['tokens.telemetry'])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh good point - done in fc90181
src/cli/ionic-config.ts
Outdated
@@ -25,7 +30,10 @@ export async function readConfig(): Promise<TelemetryConfig> { | |||
}; | |||
|
|||
await writeConfig(config); | |||
} else if (!!config && !config['tokens.telemetry'].match(UUID_REGEX)) { | |||
} else if ( | |||
!!config && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@splitinfinities is there a reason I can't remove this check? (Just the !!config &&
). Per this condition, this should always return true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended this to be a guard clause to protect against accessing config if it ended up not being defined. I think what you changed it to is sensible as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
||
expect(result.isFile).toBe(true); | ||
|
||
const config = await readConfig(); | ||
|
||
expect(Object.keys(config).join()).toBe('telemetry.stencil,tokens.telemetry'); | ||
expect(config['telemetry.stencil']).toBe(true); | ||
expect(!!config['tokens.telemetry'].match(UUID_REGEX)).toBe(true); | ||
expect(config['tokens.telemetry']).toMatch(UUID_REGEX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL!
this fix handles the event that a user has an Ionic configuration file, but does not have a 'tokens.telemetry' field in said file. STENCIL-85: ionic-pwa fails at startup
add a `beforeEach` test setup block to delete the configuration file before each test is run, in order to ensure better separation of tests & attempt to mitigate side effects between tests for this function. this led to a small amount of clean up in pre-existing tests update usage of let->const where appropriate use jest's toMatch() where appropriate update the test for an invalid, but string value for tokens.telemetry to better differentiate it from the test added in the parent commit
fc90181
to
7445e0e
Compare
handle the scenario that a user has an Ionic configuration file, but does not have a 'tokens.telemetry' field in said file. STENCIL-85: ionic-pwa fails at startup
Fixes: #3013
Summary:
this fix handles the event that a user has an Ionic configuration file,
but does not have a 'tokens.telemetry' field in said file.
Replication:
With
master@HEAD
, modify your local~/.ionic/config.json
in one of two ways'tokens.telemetry'
completely'tokens.telemetry'
to undefined (or any other valid JSON)Then, spin up a small Stencil project, and attempt to turn telemetry off/on:
Testing:
With the HEAD of this branch, build it and install it in the PWA app you build