mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 565430 - Service.startOver should purge client-specific data (i.e. client/tabs) from the server. r=rnewman
This commit is contained in:
parent
f5b87fff6f
commit
e48dd927d6
@ -1057,6 +1057,11 @@ SyncEngine.prototype = {
|
||||
this._resetClient();
|
||||
},
|
||||
|
||||
removeClientData: function removeClientData() {
|
||||
// Implement this method in engines that store client specific data
|
||||
// on the server.
|
||||
},
|
||||
|
||||
/*
|
||||
* Decide on (and partially effect) an error-handling strategy.
|
||||
*
|
||||
|
@ -45,6 +45,7 @@ Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/engines.js");
|
||||
Cu.import("resource://services-sync/ext/StringBundle.js");
|
||||
Cu.import("resource://services-sync/record.js");
|
||||
Cu.import("resource://services-sync/resource.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
const CLIENTS_TTL = 1814400; // 21 days
|
||||
@ -193,7 +194,12 @@ ClientEngine.prototype = {
|
||||
SyncEngine.prototype._resetClient.call(this);
|
||||
this._store.wipe();
|
||||
},
|
||||
|
||||
|
||||
removeClientData: function removeClientData() {
|
||||
let res = new Resource(this.engineURL + "/" + this.localID);
|
||||
res.delete();
|
||||
},
|
||||
|
||||
// Override the default behavior to delete bad records from the server.
|
||||
handleHMACMismatch: function handleHMACMismatch(item, mayRetry) {
|
||||
this._log.debug("Handling HMAC mismatch for " + item.id);
|
||||
|
@ -48,6 +48,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
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/resource.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://services-sync/ext/Preferences.js");
|
||||
|
||||
@ -106,6 +107,10 @@ TabEngine.prototype = {
|
||||
this._tracker.modified = true;
|
||||
},
|
||||
|
||||
removeClientData: function removeClientData() {
|
||||
new Resource(this.engineURL + "/" + Clients.localID).delete();
|
||||
},
|
||||
|
||||
/* The intent is not to show tabs in the menu if they're already
|
||||
* open locally. There are a couple ways to interpret this: for
|
||||
* instance, we could do it by removing a tab from the list when
|
||||
|
@ -1014,6 +1014,16 @@ WeaveSvc.prototype = {
|
||||
}))(),
|
||||
|
||||
startOver: function() {
|
||||
// Clear client-specific data from the server, including disabled engines.
|
||||
for each (let engine in [Clients].concat(Engines.getAll())) {
|
||||
try {
|
||||
engine.removeClientData();
|
||||
} catch(ex) {
|
||||
this._log.warn("Deleting client data for " + engine.name + " failed:"
|
||||
+ Utils.exceptionStr(ex));
|
||||
}
|
||||
}
|
||||
|
||||
// Set a username error so the status message shows "set up..."
|
||||
Status.login = LOGIN_FAILED_NO_USERNAME;
|
||||
this.logout();
|
||||
|
@ -157,7 +157,6 @@ function test_sync() {
|
||||
_("Ensure that Clients engine uploads a new client record once a week.");
|
||||
Svc.Prefs.set("clusterURL", "http://localhost:8080/");
|
||||
Svc.Prefs.set("username", "foo");
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
CollectionKeys.generateNewKeys();
|
||||
|
||||
@ -170,6 +169,9 @@ function test_sync() {
|
||||
"/1.0/foo/storage/meta/global": global.handler(),
|
||||
"/1.0/foo/storage/clients": coll.handler()
|
||||
});
|
||||
server.registerPathHandler(
|
||||
"/1.0/foo/storage/clients/" + Clients.localID, clientwbo.handler());
|
||||
|
||||
do_test_pending();
|
||||
|
||||
try {
|
||||
@ -189,10 +191,13 @@ function test_sync() {
|
||||
do_check_true(!!clientwbo.payload);
|
||||
do_check_true(Clients.lastRecordUpload > lastweek);
|
||||
|
||||
_("Remove client record.");
|
||||
Clients.removeClientData();
|
||||
do_check_eq(clientwbo.payload, undefined);
|
||||
|
||||
_("Time travel one day back, no record uploaded.");
|
||||
Clients.lastRecordUpload -= LESS_THAN_CLIENTS_TTL_REFRESH;
|
||||
let yesterday = Clients.lastRecordUpload;
|
||||
clientwbo.payload = undefined;
|
||||
Clients.sync();
|
||||
do_check_eq(clientwbo.payload, undefined);
|
||||
do_check_eq(Clients.lastRecordUpload, yesterday);
|
||||
@ -208,7 +213,7 @@ function test_sync() {
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
Log4Moz.repository.getLogger("Engine.Clients").level = Log4Moz.Level.Trace;
|
||||
test_bad_hmac(); // Needs to run first: doesn't use fake service!
|
||||
test_bad_hmac();
|
||||
test_properties();
|
||||
test_sync();
|
||||
}
|
||||
|
30
services/sync/tests/unit/test_service_startOver.js
Normal file
30
services/sync/tests/unit/test_service_startOver.js
Normal file
@ -0,0 +1,30 @@
|
||||
Cu.import("resource://services-sync/engines.js");
|
||||
Cu.import("resource://services-sync/service.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
function BlaEngine() {
|
||||
SyncEngine.call(this, "Bla");
|
||||
}
|
||||
BlaEngine.prototype = {
|
||||
__proto__: SyncEngine.prototype,
|
||||
|
||||
removed: false,
|
||||
removeClientData: function() {
|
||||
this.removed = true;
|
||||
}
|
||||
|
||||
};
|
||||
Engines.register(BlaEngine);
|
||||
|
||||
|
||||
function test_removeClientData() {
|
||||
let engine = Engines.get("bla");
|
||||
do_check_false(engine.removed);
|
||||
Service.startOver();
|
||||
do_check_true(engine.removed);
|
||||
}
|
||||
|
||||
|
||||
function run_test() {
|
||||
test_removeClientData();
|
||||
}
|
Loading…
Reference in New Issue
Block a user