Bug 956442 - Include version in desktop Sync client records. r=gps, a=bajaj
authorRichard Newman <rnewman@mozilla.com>
Mon, 06 Jan 2014 18:41:12 -0800
changeset 175686 7c5ec27e38940fdf92fcade74d6f879fedb41f5d
parent 175685 f60df68dc9988e8bef955aaf3d831e66a922b4b3
child 175687 0c0281672c110afb4a9cb17b17df6abcfa037f45
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, bajaj
bugs956442
milestone28.0a2
Bug 956442 - Include version in desktop Sync client records. r=gps, a=bajaj
services/sync/modules/engines/clients.js
services/sync/tests/unit/test_clients_engine.js
--- a/services/sync/modules/engines/clients.js
+++ b/services/sync/modules/engines/clients.js
@@ -22,17 +22,17 @@ this.ClientsRec = function ClientsRec(co
   CryptoWrapper.call(this, collection, id);
 }
 ClientsRec.prototype = {
   __proto__: CryptoWrapper.prototype,
   _logName: "Sync.Record.Clients",
   ttl: CLIENTS_TTL
 };
 
-Utils.deferGetSet(ClientsRec, "cleartext", ["name", "type", "commands"]);
+Utils.deferGetSet(ClientsRec, "cleartext", ["name", "type", "commands", "version"]);
 
 
 this.ClientEngine = function ClientEngine(service) {
   SyncEngine.call(this, "Clients", service);
 
   // Reset the client on every startup so that we fetch recent clients
   this._resetClient();
 }
@@ -381,16 +381,17 @@ ClientStore.prototype = {
   createRecord: function createRecord(id, collection) {
     let record = new ClientsRec(collection, id);
 
     // Package the individual components into a record for the local client
     if (id == this.engine.localID) {
       record.name = this.engine.localName;
       record.type = this.engine.localType;
       record.commands = this.engine.localCommands;
+      record.version = Services.appinfo.version;
     }
     else
       record.cleartext = this._remoteClients[id];
 
     return record;
   },
 
   itemExists: function itemExists(id) id in this.getAllIDs(),
--- a/services/sync/tests/unit/test_clients_engine.js
+++ b/services/sync/tests/unit/test_clients_engine.js
@@ -1,23 +1,44 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/clients.js");
+Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
 const MORE_THAN_CLIENTS_TTL_REFRESH = 691200; // 8 days
 const LESS_THAN_CLIENTS_TTL_REFRESH = 86400;  // 1 day
 
 let engine = Service.clientsEngine;
 
+/**
+ * Unpack the record with this ID, and verify that it has the same version that
+ * we should be putting into records.
+ */
+function check_record_version(user, id) {
+    let payload = JSON.parse(user.collection("clients").wbo(id).payload);
+
+    let rec = new CryptoWrapper();
+    rec.id = id;
+    rec.collection = "clients";
+    rec.ciphertext = payload.ciphertext;
+    rec.hmac = payload.hmac;
+    rec.IV = payload.IV;
+
+    let cleartext = rec.decrypt(Service.collectionKeys.keyForCollection("clients"));
+
+    _("Payload is " + JSON.stringify(cleartext));
+    do_check_eq(Services.appinfo.version, cleartext.version);
+}
+
 add_test(function test_bad_hmac() {
   _("Ensure that Clients engine deletes corrupt records.");
   let contents = {
     meta: {global: {engines: {clients: {version: engine.version,
                                         syncID: engine.syncID}}}},
     clients: {},
     crypto: {}
   };
@@ -65,16 +86,19 @@ add_test(function test_bad_hmac() {
 
     _("First sync, client record is uploaded");
     do_check_eq(engine.lastRecordUpload, 0);
     check_clients_count(0);
     engine._sync();
     check_clients_count(1);
     do_check_true(engine.lastRecordUpload > 0);
 
+    // Our uploaded record has a version.
+    check_record_version(user, engine.localID);
+
     // Initial setup can wipe the server, so clean up.
     deletedCollections = [];
     deletedItems       = [];
 
     _("Change our keys and our client ID, reupload keys.");
     let oldLocalID  = engine.localID;     // Preserve to test for deletion!
     engine.localID = Utils.makeGUID();
     engine.resetClient();