diff options
Diffstat (limited to 'services/sync/tests/unit/test_service_sync_remoteSetup.js')
-rw-r--r-- | services/sync/tests/unit/test_service_sync_remoteSetup.js | 77 |
1 files changed, 4 insertions, 73 deletions
diff --git a/services/sync/tests/unit/test_service_sync_remoteSetup.js b/services/sync/tests/unit/test_service_sync_remoteSetup.js index 83dbf3cd7..852ba64d5 100644 --- a/services/sync/tests/unit/test_service_sync_remoteSetup.js +++ b/services/sync/tests/unit/test_service_sync_remoteSetup.js @@ -10,7 +10,6 @@ Cu.import("resource://testing-common/services/sync/fakeservices.js"); Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { - validate_all_future_pings(); let logger = Log.repository.rootLogger; Log.repository.rootLogger.addAppender(new Log.DumpAppender()); @@ -54,27 +53,15 @@ function run_test() { return_timestamp(request, response, ts); } - const GLOBAL_PATH = "/1.1/johndoe/storage/meta/global"; - const INFO_PATH = "/1.1/johndoe/info/collections"; - - let handlers = { + let server = httpd_setup({ "/1.1/johndoe/storage": storageHandler, "/1.1/johndoe/storage/crypto/keys": upd("crypto", keysWBO.handler()), "/1.1/johndoe/storage/crypto": upd("crypto", cryptoColl.handler()), "/1.1/johndoe/storage/clients": upd("clients", clients.handler()), - "/1.1/johndoe/storage/meta": upd("meta", wasCalledHandler(metaColl)), "/1.1/johndoe/storage/meta/global": upd("meta", wasCalledHandler(meta_global)), + "/1.1/johndoe/storage/meta": upd("meta", wasCalledHandler(metaColl)), "/1.1/johndoe/info/collections": collectionsHelper.handler - }; - - function mockHandler(path, mock) { - server.registerPathHandler(path, mock(handlers[path])); - return { - restore() { server.registerPathHandler(path, handlers[path]); } - } - } - - let server = httpd_setup(handlers); + }); try { _("Log in."); @@ -102,63 +89,6 @@ function run_test() { Service.recordManager.get(Service.metaURL).payload.syncID = "foobar"; do_check_true(Service._remoteSetup()); - let returnStatusCode = (method, code) => (oldMethod) => (req, res) => { - if (req.method === method) { - res.setStatusLine(req.httpVersion, code, ""); - } else { - oldMethod(req, res); - } - }; - - let mock = mockHandler(GLOBAL_PATH, returnStatusCode("GET", 401)); - Service.recordManager.del(Service.metaURL); - _("Checking that remoteSetup returns false on 401 on first get /meta/global."); - do_check_false(Service._remoteSetup()); - mock.restore(); - - Service.login("johndoe", "ilovejane", syncKey); - mock = mockHandler(GLOBAL_PATH, returnStatusCode("GET", 503)); - Service.recordManager.del(Service.metaURL); - _("Checking that remoteSetup returns false on 503 on first get /meta/global."); - do_check_false(Service._remoteSetup()); - do_check_eq(Service.status.sync, METARECORD_DOWNLOAD_FAIL); - mock.restore(); - - mock = mockHandler(GLOBAL_PATH, returnStatusCode("GET", 404)); - Service.recordManager.del(Service.metaURL); - _("Checking that remoteSetup recovers on 404 on first get /meta/global."); - do_check_true(Service._remoteSetup()); - mock.restore(); - - let makeOutdatedMeta = () => { - Service.metaModified = 0; - let infoResponse = Service._fetchInfo(); - return { - status: infoResponse.status, - obj: { - crypto: infoResponse.obj.crypto, - clients: infoResponse.obj.clients, - meta: 1 - } - }; - } - - _("Checking that remoteSetup recovers on 404 on get /meta/global after clear cached one."); - mock = mockHandler(GLOBAL_PATH, returnStatusCode("GET", 404)); - Service.recordManager.set(Service.metaURL, { isNew: false }); - do_check_true(Service._remoteSetup(makeOutdatedMeta())); - mock.restore(); - - _("Checking that remoteSetup returns false on 503 on get /meta/global after clear cached one."); - mock = mockHandler(GLOBAL_PATH, returnStatusCode("GET", 503)); - Service.status.sync = ""; - Service.recordManager.set(Service.metaURL, { isNew: false }); - do_check_false(Service._remoteSetup(makeOutdatedMeta())); - do_check_eq(Service.status.sync, ""); - mock.restore(); - - metaColl.delete({}); - _("Do an initial sync."); let beforeSync = Date.now()/1000; Service.sync(); @@ -230,6 +160,7 @@ function run_test() { do_check_false(Service.verifyAndFetchSymmetricKeys()); do_check_eq(Service.status.login, LOGIN_FAILED_INVALID_PASSPHRASE); + } finally { Svc.Prefs.resetBranch(""); server.stop(do_test_finished); |