Skip to content

Commit b580b23

Browse files
author
Beatriz Rizental
authored
Merge pull request #968 from brizental/1738208-runtime-type-checks
Bug 1738208 - Add runtime type check to args passed to setUploadEnabled API
2 parents 913004e + 40f0f8a commit b580b23

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#965](https://github.com/mozilla/glean.js/pull/965): Attempt to infer the Python virtualenv folder from the environment before falling back to the default `.venv`.
66
* Users may provide a folder name through the `VIRTUAL_ENV` environment variable.
77
* If the user is inside an active virtualenv the `VIRTUAL_ENV` environment variable is already set by Python. See: https://docs.python.org/3/library/venv.html.
8+
* [#968](https://github.com/mozilla/glean.js/pull/968): Add runtime arguments type checking to `Glean.setUploadEnabled` API.
89

910
# v0.25.0 (2021-11-15)
1011

glean/src/core/glean.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ class Glean {
356356
* @param flag When true, enable metric collection.
357357
*/
358358
static setUploadEnabled(flag: boolean): void {
359+
if (!isBoolean(flag)) {
360+
log(
361+
LOG_TAG,
362+
"Unable to change upload state, new value must be a boolean. Ignoring.",
363+
LoggingLevel.Error
364+
);
365+
return;
366+
}
367+
359368
Context.dispatcher.launch(async () => {
360369
if (!Context.initialized) {
361370
log(

glean/tests/unit/core/glean.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,18 @@ describe("Glean", function() {
605605
await Glean.testResetGlean(testAppId, true);
606606
assert.strictEqual(Context.initialized, true);
607607
});
608+
609+
it("setUploadEnabled does nothing in case a non-boolean value is passed to it", async function() {
610+
// Set the current upload value to false,
611+
// strings are "truthy", this way we can be sure calling with the wrong type dod not work.
612+
Glean.setUploadEnabled(false);
613+
await Context.dispatcher.testBlockOnQueue();
614+
assert.strictEqual(Context.uploadEnabled, false);
615+
616+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
617+
// @ts-ignore
618+
Glean.setUploadEnabled("not a boolean");
619+
await Context.dispatcher.testBlockOnQueue();
620+
assert.strictEqual(Context.uploadEnabled, false);
621+
});
608622
});

0 commit comments

Comments
 (0)