Bug 617478: clear CollectionKeys on startOver. r=philiKON.
authorRichard Newman <rnewman@mozilla.com>
Tue, 07 Dec 2010 16:30:06 -0800
changeset 58878 af61f19326a987a25e2cc27e292a1d10b6371475
parent 58877 83b27b845f94535e97dafdbcfbf4b5c486ac2a58
child 58879 81bce58ee4a31cb55986dfe160cbc2ebb4b08462
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersphiliKON
bugs617478
Bug 617478: clear CollectionKeys on startOver. r=philiKON.
services/sync/modules/base_records/crypto.js
services/sync/modules/service.js
services/sync/tests/unit/test_service_wipeClient.js
--- a/services/sync/modules/base_records/crypto.js
+++ b/services/sync/modules/base_records/crypto.js
@@ -163,16 +163,23 @@ function CollectionKeyManager() {
   
   this._log = Log4Moz.repository.getLogger("CollectionKeys");
 }
 
 // TODO: persist this locally as an Identity. Bug 610913.
 // Note that the last modified time needs to be preserved.
 CollectionKeyManager.prototype = {
   
+  clear: function clear() {
+    this._log.info("Clearing CollectionKeys...");
+    this._lastModified = 0;
+    this._collections = {};
+    this._default = null;
+  },
+  
   keyForCollection: function(collection) {
                       
     // Moderately temporary debugging code.
     this._log.trace("keyForCollection: " + collection + ". Default is " + (this._default ? "not null." : "null."));
     
     if (collection && this._collections[collection])
       return this._collections[collection];
     
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -840,16 +840,19 @@ WeaveSvc.prototype = {
     this.logout();
     // Reset all engines.
     this.resetClient();
     // Reset Weave prefs.
     this._ignorePrefObserver = true;
     Svc.Prefs.resetBranch("");
     this._ignorePrefObserver = false;
     
+    // Clear keys.
+    CollectionKeys.clear();
+    
     Svc.Prefs.set("lastversion", WEAVE_VERSION);
     // Find weave logins and remove them.
     this.password = "";
     this.passphrase = "";
     Svc.Login.findLogins({}, PWDMGR_HOST, "", "").map(function(login) {
       Svc.Login.removeLogin(login);
     });
     Svc.Obs.notify("weave:service:start-over");
--- a/services/sync/tests/unit/test_service_wipeClient.js
+++ b/services/sync/tests/unit/test_service_wipeClient.js
@@ -1,8 +1,9 @@
+Cu.import("resource://services-sync/base_records/crypto.js");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/util.js");
 
 Svc.DefaultPrefs.set("registerEngines", "");
 Cu.import("resource://services-sync/service.js");
 
 
 function CanDecryptEngine() {
@@ -57,11 +58,19 @@ function test_withEngineList() {
     do_check_false(Engines.get("cannotdecrypt").wasWiped);
   } finally {
     Engines.get("candecrypt").wasWiped = false;
     Engines.get("cannotdecrypt").wasWiped = false;
     Service.startOver();
   }
 }
 
+function test_startOver_clears_keys() {
+  CollectionKeys.generateNewKeys();
+  do_check_true(!!CollectionKeys.keyForCollection());
+  Service.startOver();
+  do_check_false(!!CollectionKeys.keyForCollection());
+}
+
 function run_test() {
   test_withEngineList();
+  test_startOver_clears_keys();
 }