Bug 1472238: ensure version is not an empty string r?lina
MozReview-Commit-ID: CbPFJkl3vGr
--- a/dom/push/PushBroadcastService.jsm
+++ b/dom/push/PushBroadcastService.jsm
@@ -109,16 +109,20 @@ var BroadcastService = class {
*/
async addListener(broadcastId, version, sourceInfo) {
console.info("addListener: adding listener", broadcastId, version, sourceInfo);
await this.initializePromise;
this._validateSourceInfo(sourceInfo);
if (typeof version !== "string") {
throw new TypeError("version should be a string");
}
+ if (!version) {
+ throw new TypeError("version should not be an empty string");
+ }
+
const isNew = !this.jsonFile.data.listeners.hasOwnProperty(broadcastId);
// Update listeners before telling the pushService to subscribe,
// in case it would disregard the update in the small window
// between getting listeners and setting state to RUNNING.
this.jsonFile.data.listeners[broadcastId] = {version, sourceInfo};
this.jsonFile.saveSoon();
--- a/dom/push/test/xpcshell/test_broadcast_success.js
+++ b/dom/push/test/xpcshell/test_broadcast_success.js
@@ -260,8 +260,22 @@ add_task(async function test_broadcast_r
const path = FileTestUtils.getTempFile("broadcast-listeners.json").path;
const broadcastService = new BroadcastService(getPushServiceMock(), path);
await assert.rejects(broadcastService.addListener("ghi", "2018-05-06", {
moduleName: "resource://gre/modules/ghi.jsm",
symbolName: "getGhi"
}), /moduleURI must be a string/, "rejects sourceInfo that doesn't have moduleURI");
});
+
+add_task(async function test_broadcast_reject_version_not_string() {
+ await assert.rejects(broadcastService.addListener("ghi", {}, {
+ moduleURI: "resource://gre/modules/ghi.jsm",
+ symbolName: "getGhi"
+ }), /version should be a string/, "rejects version that isn't a string");
+});
+
+add_task(async function test_broadcast_reject_version_empty_string() {
+ await assert.rejects(broadcastService.addListener("ghi", "", {
+ moduleURI: "resource://gre/modules/ghi.jsm",
+ symbolName: "getGhi"
+ }), /version should not be an empty string/, "rejects version that is an empty string");
+});