Bug 1472238: ensure version is not an empty string r?lina draft
authorEthan Glasser-Camp <ethan@betacantrips.com>
Fri, 29 Jun 2018 12:43:42 -0400
changeset 823236 d36b97b0a90050aa53e621df0ef0d1de1685114c
parent 823235 f5f84dad9f9a2b29a611282f0a0bf951a65c094c
child 823237 556fde500b41934115537741c6d606f6147db0fa
push id117622
push userbmo:eglassercamp@mozilla.com
push dateThu, 26 Jul 2018 21:32:07 +0000
reviewerslina
bugs1472238
milestone63.0a1
Bug 1472238: ensure version is not an empty string r?lina MozReview-Commit-ID: CbPFJkl3vGr
dom/push/PushBroadcastService.jsm
dom/push/test/xpcshell/test_broadcast_success.js
--- 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");
+});