mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out 3 changesets (bug 884421) for intermittent xpcshell failures on a CLOSED TREE.
Backed out changeset 75b7cf367efb (bug 884421) Backed out changeset 2264c04671c4 (bug 884421) Backed out changeset 45c529ffbe90 (bug 884421)
This commit is contained in:
parent
481c9c8114
commit
7e3e2ab547
@ -22,10 +22,12 @@ Cu.import("resource://testing-common/httpd.js");
|
||||
*
|
||||
* The Bagheera server is essentially a glorified document store.
|
||||
*/
|
||||
this.BagheeraServer = function BagheeraServer() {
|
||||
this.BagheeraServer = function BagheeraServer(serverURI="http://localhost") {
|
||||
this._log = Log4Moz.repository.getLogger("metrics.BagheeraServer");
|
||||
|
||||
this.serverURI = serverURI;
|
||||
this.server = new HttpServer();
|
||||
this.port = 8080;
|
||||
this.namespaces = {};
|
||||
|
||||
this.allowAllNamespaces = false;
|
||||
@ -124,14 +126,15 @@ BagheeraServer.prototype = {
|
||||
this.namespaces[ns] = {};
|
||||
},
|
||||
|
||||
start: function start(port=-1) {
|
||||
start: function start(port) {
|
||||
if (!port) {
|
||||
throw new Error("port argument must be specified.");
|
||||
}
|
||||
|
||||
this.port = port;
|
||||
|
||||
this.server.registerPrefixHandler("/", this._handleRequest.bind(this));
|
||||
this.server.start(port);
|
||||
let i = this.server.identity;
|
||||
|
||||
this.serverURI = i.primaryScheme + "://" + i.primaryHost + ":" +
|
||||
i.primaryPort + "/";
|
||||
this.port = i.primaryPort;
|
||||
},
|
||||
|
||||
stop: function stop(cb) {
|
||||
|
@ -882,6 +882,7 @@ this.StorageServer = function StorageServer(callback) {
|
||||
StorageServer.prototype = {
|
||||
DEFAULT_QUOTA: 1024 * 1024, // # bytes.
|
||||
|
||||
port: 8080,
|
||||
server: null, // HttpServer.
|
||||
users: null, // Map of username => {collections, password}.
|
||||
|
||||
@ -897,8 +898,8 @@ StorageServer.prototype = {
|
||||
* Start the StorageServer's underlying HTTP server.
|
||||
*
|
||||
* @param port
|
||||
* The numeric port on which to start. A falsy value implies to
|
||||
* select any available port.
|
||||
* The numeric port on which to start. A falsy value implies the
|
||||
* default (8080).
|
||||
* @param cb
|
||||
* A callback function (of no arguments) which is invoked after
|
||||
* startup.
|
||||
@ -908,14 +909,11 @@ StorageServer.prototype = {
|
||||
this._log.warn("Warning: server already started on " + this.port);
|
||||
return;
|
||||
}
|
||||
if (!port) {
|
||||
port = -1;
|
||||
if (port) {
|
||||
this.port = port;
|
||||
}
|
||||
this.port = port;
|
||||
|
||||
try {
|
||||
this.server.start(this.port);
|
||||
this.port = this.server.identity.primaryPort;
|
||||
this.started = true;
|
||||
if (cb) {
|
||||
cb();
|
||||
@ -934,10 +932,10 @@ StorageServer.prototype = {
|
||||
* Start the server synchronously.
|
||||
*
|
||||
* @param port
|
||||
* The numeric port on which to start. The default is to choose
|
||||
* any available port.
|
||||
* The numeric port on which to start. A falsy value implies the
|
||||
* default (8080).
|
||||
*/
|
||||
startSynchronous: function startSynchronous(port=-1) {
|
||||
startSynchronous: function startSynchronous(port) {
|
||||
let cb = Async.makeSpinningCallback();
|
||||
this.start(port, cb);
|
||||
cb.wait();
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu, manager: Cm} = Components;
|
||||
|
||||
// Where to bind test HTTP servers to.
|
||||
const TEST_SERVER_URL = "http://localhost:8080/";
|
||||
|
||||
let gSyncProfile = do_get_profile();
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
@ -46,7 +46,18 @@ function do_check_throws(aFunc, aResult, aStack) {
|
||||
*/
|
||||
let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
|
||||
|
||||
function httpd_setup (handlers, port=-1) {
|
||||
/**
|
||||
* Obtain a port number to run a server on.
|
||||
*
|
||||
* In the ideal world, this would be dynamic so multiple servers could be run
|
||||
* in parallel.
|
||||
*/
|
||||
function get_server_port() {
|
||||
return 8080;
|
||||
}
|
||||
|
||||
function httpd_setup (handlers, port) {
|
||||
let port = port || 8080;
|
||||
let server = new HttpServer();
|
||||
for (let path in handlers) {
|
||||
server.registerPathHandler(path, handlers[path]);
|
||||
@ -62,10 +73,6 @@ function httpd_setup (handlers, port=-1) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
// Set the base URI for convenience.
|
||||
let i = server.identity;
|
||||
server.baseURI = i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort;
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,15 @@ Cu.import("resource://testing-common/services-common/bagheeraserver.js");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
|
||||
function getClientAndServer() {
|
||||
let server = new BagheeraServer();
|
||||
server.start();
|
||||
const PORT = 8080;
|
||||
|
||||
let client = new BagheeraClient(server.serverURI);
|
||||
function getClientAndServer(port=PORT) {
|
||||
let uri = "http://localhost";
|
||||
let server = new BagheeraServer(uri);
|
||||
|
||||
server.start(port);
|
||||
|
||||
let client = new BagheeraClient(uri + ":" + port);
|
||||
|
||||
return [client, server];
|
||||
}
|
||||
@ -24,13 +28,13 @@ function run_test() {
|
||||
}
|
||||
|
||||
add_test(function test_constructor() {
|
||||
let client = new BagheeraClient("http://localhost:1234/");
|
||||
let client = new BagheeraClient("http://localhost:8080/");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_post_json_transport_failure() {
|
||||
let client = new BagheeraClient("http://localhost:1234/");
|
||||
let client = new BagheeraClient("http://localhost:8080/");
|
||||
|
||||
client.uploadJSON("foo", "bar", {}).then(function onResult(result) {
|
||||
do_check_false(result.transportSuccess);
|
||||
@ -134,4 +138,4 @@ add_test(function test_delete_document() {
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
});
|
||||
});
|
@ -5,6 +5,8 @@
|
||||
|
||||
Cu.import("resource://testing-common/services-common/bagheeraserver.js");
|
||||
|
||||
const PORT = 8080;
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
@ -22,9 +24,22 @@ add_test(function test_server_empty() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_server_start_no_port() {
|
||||
let server = new BagheeraServer();
|
||||
|
||||
try {
|
||||
server.start();
|
||||
} catch (ex) {
|
||||
do_check_true(ex.message.startsWith("port argument must be"));
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_server_start() {
|
||||
let server = new BagheeraServer();
|
||||
server.start();
|
||||
server.start(PORT);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
|
@ -6,6 +6,8 @@ Cu.import("resource://services-common/log4moz.js");
|
||||
Cu.import("resource://services-common/rest.js");
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
|
||||
const TEST_RESOURCE_URL = TEST_SERVER_URL + "resource";
|
||||
|
||||
//DEBUG = true;
|
||||
|
||||
function run_test() {
|
||||
@ -72,10 +74,10 @@ add_test(function test_proxy_auth_redirect() {
|
||||
"/original": original,
|
||||
"/pac3": pacHandler
|
||||
});
|
||||
PACSystemSettings.PACURI = server.baseURI + "/pac3";
|
||||
PACSystemSettings.PACURI = "http://localhost:8080/pac3";
|
||||
installFakePAC();
|
||||
|
||||
let res = new RESTRequest(server.baseURI + "/original");
|
||||
let res = new RESTRequest("http://localhost:8080/original");
|
||||
res.get(function (error) {
|
||||
do_check_true(pacFetched);
|
||||
do_check_true(fetched);
|
||||
@ -110,7 +112,8 @@ add_test(function test_simple_get() {
|
||||
let handler = httpd_handler(200, "OK", "Huzzah!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource").get(function (error) {
|
||||
let uri = TEST_RESOURCE_URL;
|
||||
let request = new RESTRequest(uri).get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
do_check_eq(this.status, this.COMPLETED);
|
||||
@ -131,7 +134,7 @@ add_test(function test_get() {
|
||||
let handler = httpd_handler(200, "OK", "Huzzah!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
do_check_eq(request.status, request.NOT_SENT);
|
||||
|
||||
request.onProgress = request.onComplete = function () {
|
||||
@ -195,7 +198,7 @@ add_test(function test_get_utf8() {
|
||||
}});
|
||||
|
||||
// Check if charset in Content-Type is propertly interpreted.
|
||||
let request1 = new RESTRequest(server.baseURI + "/resource");
|
||||
let request1 = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request1.get(function(error) {
|
||||
do_check_null(error);
|
||||
|
||||
@ -206,7 +209,7 @@ add_test(function test_get_utf8() {
|
||||
|
||||
// Check that we default to UTF-8 if Content-Type doesn't have a charset.
|
||||
charset = false;
|
||||
let request2 = new RESTRequest(server.baseURI + "/resource");
|
||||
let request2 = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request2.get(function(error) {
|
||||
do_check_null(error);
|
||||
|
||||
@ -242,7 +245,7 @@ add_test(function test_charsets() {
|
||||
}});
|
||||
|
||||
// Check that provided charset overrides hint.
|
||||
let request1 = new RESTRequest(server.baseURI + "/resource");
|
||||
let request1 = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request1.charset = "not-a-charset";
|
||||
request1.get(function(error) {
|
||||
do_check_null(error);
|
||||
@ -255,7 +258,7 @@ add_test(function test_charsets() {
|
||||
|
||||
// Check that hint is used if Content-Type doesn't have a charset.
|
||||
charset = false;
|
||||
let request2 = new RESTRequest(server.baseURI + "/resource");
|
||||
let request2 = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request2.charset = "us-ascii";
|
||||
request2.get(function(error) {
|
||||
do_check_null(error);
|
||||
@ -277,7 +280,7 @@ add_test(function test_put() {
|
||||
let handler = httpd_handler(200, "OK", "Got it!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
do_check_eq(request.status, request.NOT_SENT);
|
||||
|
||||
request.onProgress = request.onComplete = function () {
|
||||
@ -326,7 +329,7 @@ add_test(function test_post() {
|
||||
let handler = httpd_handler(200, "OK", "Got it!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
do_check_eq(request.status, request.NOT_SENT);
|
||||
|
||||
request.onProgress = request.onComplete = function () {
|
||||
@ -375,7 +378,7 @@ add_test(function test_delete() {
|
||||
let handler = httpd_handler(200, "OK", "Got it!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
do_check_eq(request.status, request.NOT_SENT);
|
||||
|
||||
request.onProgress = request.onComplete = function () {
|
||||
@ -421,7 +424,7 @@ add_test(function test_get_404() {
|
||||
let handler = httpd_handler(404, "Not Found", "Cannae find it!");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
@ -447,7 +450,7 @@ add_test(function test_put_json() {
|
||||
injson: "format",
|
||||
number: 42
|
||||
};
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.put(sample_data, function (error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
@ -477,7 +480,7 @@ add_test(function test_post_json() {
|
||||
injson: "format",
|
||||
number: 42
|
||||
};
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.post(sample_data, function (error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
@ -501,7 +504,7 @@ add_test(function test_put_override_content_type() {
|
||||
let handler = httpd_handler(200, "OK");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.setHeader("Content-Type", "application/lolcat");
|
||||
request.put("O HAI!!1!", function (error) {
|
||||
do_check_eq(error, null);
|
||||
@ -526,7 +529,7 @@ add_test(function test_post_override_content_type() {
|
||||
let handler = httpd_handler(200, "OK");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.setHeader("Content-Type", "application/lolcat");
|
||||
request.post("O HAI!!1!", function (error) {
|
||||
do_check_eq(error, null);
|
||||
@ -556,7 +559,7 @@ add_test(function test_get_no_headers() {
|
||||
"connection", "pragma", "cache-control",
|
||||
"content-length"];
|
||||
|
||||
new RESTRequest(server.baseURI + "/resource").get(function (error) {
|
||||
new RESTRequest(TEST_RESOURCE_URL).get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -581,8 +584,8 @@ add_test(function test_changing_uri() {
|
||||
let handler = httpd_handler(200, "OK");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest("http://localhost:1234/the-wrong-resource");
|
||||
request.uri = CommonUtils.makeURI(server.baseURI + "/resource");
|
||||
let request = new RESTRequest("http://localhost:8080/the-wrong-resource");
|
||||
request.uri = CommonUtils.makeURI(TEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -597,7 +600,7 @@ add_test(function test_request_setHeader() {
|
||||
let handler = httpd_handler(200, "OK");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
|
||||
request.setHeader("X-What-Is-Weave", "awesome");
|
||||
request.setHeader("X-WHAT-is-Weave", "more awesomer");
|
||||
@ -626,7 +629,7 @@ add_test(function test_response_headers() {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
}
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
@ -646,7 +649,7 @@ add_test(function test_response_headers() {
|
||||
* (e.g. NS_ERROR_CONNECTION_REFUSED).
|
||||
*/
|
||||
add_test(function test_connection_refused() {
|
||||
let request = new RESTRequest("http://localhost:1234/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.onProgress = function onProgress() {
|
||||
do_throw("Shouldn't have called request.onProgress()!");
|
||||
};
|
||||
@ -668,7 +671,7 @@ add_test(function test_abort() {
|
||||
}
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
|
||||
// Aborting a request that hasn't been sent yet is pointless and will throw.
|
||||
do_check_throws(function () {
|
||||
@ -706,12 +709,9 @@ add_test(function test_timeout() {
|
||||
// why you really only want to make one HTTP request to this server ever.
|
||||
server_connection = connection;
|
||||
};
|
||||
server.start();
|
||||
let identity = server.identity;
|
||||
let uri = identity.primaryScheme + "://" + identity.primaryHost + ":" +
|
||||
identity.primaryPort;
|
||||
server.start(8080);
|
||||
|
||||
let request = new RESTRequest(uri + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.timeout = 0.1; // 100 milliseconds
|
||||
request.get(function (error) {
|
||||
do_check_eq(error.result, Cr.NS_ERROR_NET_TIMEOUT);
|
||||
@ -731,7 +731,7 @@ add_test(function test_exception_in_onProgress() {
|
||||
let handler = httpd_handler(200, "OK", "Foobar");
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new RESTRequest(server.baseURI + "/resource");
|
||||
let request = new RESTRequest(TEST_RESOURCE_URL);
|
||||
request.onProgress = function onProgress() {
|
||||
it.does.not.exist();
|
||||
};
|
||||
@ -753,14 +753,13 @@ add_test(function test_new_channel() {
|
||||
}
|
||||
|
||||
let redirectRequested = false;
|
||||
let redirectURL;
|
||||
function redirectHandler(metadata, response) {
|
||||
checkUA(metadata);
|
||||
redirectRequested = true;
|
||||
|
||||
let body = "Redirecting";
|
||||
response.setStatusLine(metadata.httpVersion, 307, "TEMPORARY REDIRECT");
|
||||
response.setHeader("Location", redirectURL);
|
||||
response.setHeader("Location", "http://localhost:8081/resource");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
@ -774,9 +773,8 @@ add_test(function test_new_channel() {
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
let server1 = httpd_setup({"/redirect": redirectHandler});
|
||||
let server2 = httpd_setup({"/resource": resourceHandler});
|
||||
redirectURL = server2.baseURI + "/resource";
|
||||
let server1 = httpd_setup({"/redirect": redirectHandler}, 8080);
|
||||
let server2 = httpd_setup({"/resource": resourceHandler}, 8081);
|
||||
|
||||
function advance() {
|
||||
server1.stop(function () {
|
||||
@ -784,7 +782,7 @@ add_test(function test_new_channel() {
|
||||
});
|
||||
}
|
||||
|
||||
let request = new RESTRequest(server1.baseURI + "/redirect");
|
||||
let request = new RESTRequest("http://localhost:8080/redirect");
|
||||
request.setHeader("User-Agent", "foo bar");
|
||||
|
||||
// Swizzle in our own fakery, because this redirect is neither
|
||||
@ -820,10 +818,10 @@ add_test(function test_not_sending_cookie() {
|
||||
|
||||
let cookieSer = Cc["@mozilla.org/cookieService;1"]
|
||||
.getService(Ci.nsICookieService);
|
||||
let uri = CommonUtils.makeURI(server.baseURI);
|
||||
let uri = CommonUtils.makeURI("http://localhost:8080");
|
||||
cookieSer.setCookieString(uri, null, "test=test; path=/;", null);
|
||||
|
||||
let res = new RESTRequest(server.baseURI + "/test");
|
||||
let res = new RESTRequest("http://localhost:8080/test");
|
||||
res.get(function (error) {
|
||||
do_check_null(error);
|
||||
do_check_true(this.response.success);
|
||||
|
@ -6,17 +6,16 @@ Cu.import("resource://services-common/rest.js");
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
Cu.import("resource://testing-common/services-common/storageserver.js");
|
||||
|
||||
const PORT = 8080;
|
||||
const DEFAULT_USER = "123";
|
||||
const DEFAULT_PASSWORD = "password";
|
||||
|
||||
/**
|
||||
* Helper function to prepare a RESTRequest against the server.
|
||||
*/
|
||||
function localRequest(server, path, user=DEFAULT_USER, password=DEFAULT_PASSWORD) {
|
||||
function localRequest(path, user=DEFAULT_USER, password=DEFAULT_PASSWORD) {
|
||||
_("localRequest: " + path);
|
||||
let identity = server.server.identity;
|
||||
let url = identity.primaryScheme + "://" + identity.primaryHost + ":" +
|
||||
identity.primaryPort + path;
|
||||
let url = "http://127.0.0.1:" + PORT + path;
|
||||
_("url: " + url);
|
||||
let req = new RESTRequest(url);
|
||||
|
||||
@ -121,8 +120,9 @@ add_test(function test_creation() {
|
||||
});
|
||||
do_check_true(!!server);
|
||||
|
||||
server.start(-1, function () {
|
||||
server.start(PORT, function () {
|
||||
_("Started on " + server.port);
|
||||
do_check_eq(server.port, PORT);
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
});
|
||||
@ -131,7 +131,7 @@ add_test(function test_synchronous_start() {
|
||||
_("Ensure starting using startSynchronous works.");
|
||||
|
||||
let server = new StorageServer();
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
||||
@ -184,11 +184,11 @@ add_test(function test_basic_http() {
|
||||
let server = new StorageServer();
|
||||
server.registerUser("345", "password");
|
||||
do_check_true(server.userExists("345"));
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
_("Started on " + server.port);
|
||||
do_check_eq(server.requestCount, 0);
|
||||
let req = localRequest(server, "/2.0/storage/crypto/keys");
|
||||
let req = localRequest("/2.0/storage/crypto/keys");
|
||||
_("req is " + req);
|
||||
req.get(function (err) {
|
||||
do_check_eq(null, err);
|
||||
@ -200,12 +200,12 @@ add_test(function test_basic_http() {
|
||||
add_test(function test_info_collections() {
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let path = "/2.0/123/info/collections";
|
||||
|
||||
_("info/collections on empty server should be empty object.");
|
||||
let request = localRequest(server, path, "123", "password");
|
||||
let request = localRequest(path, "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 200);
|
||||
@ -213,7 +213,7 @@ add_test(function test_info_collections() {
|
||||
|
||||
_("Creating an empty collection should result in collection appearing.");
|
||||
let coll = server.createCollection("123", "col1");
|
||||
let request = localRequest(server, path, "123", "password");
|
||||
let request = localRequest(path, "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 200);
|
||||
@ -233,12 +233,11 @@ add_test(function test_bso_get_existing() {
|
||||
server.createContents("123", {
|
||||
test: {"bso": {"foo": "bar"}}
|
||||
});
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").collection("test");
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test/bso", "123",
|
||||
"password");
|
||||
let request = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 200);
|
||||
@ -259,14 +258,14 @@ add_test(function test_percent_decoding() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").createCollection("test");
|
||||
coll.insert("001", {foo: "bar"});
|
||||
coll.insert("002", {bar: "foo"});
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test?ids=001%2C002",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test?ids=001%2C002", "123",
|
||||
"password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_null(error);
|
||||
do_check_eq(request.response.status, 200);
|
||||
@ -284,9 +283,9 @@ add_test(function test_bso_404() {
|
||||
server.createContents("123", {
|
||||
test: {}
|
||||
});
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test/foo");
|
||||
let request = localRequest("/2.0/123/storage/test/foo");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
|
||||
@ -304,7 +303,7 @@ add_test(function test_bso_if_modified_since_304() {
|
||||
server.createContents("123", {
|
||||
test: {bso: {foo: "bar"}}
|
||||
});
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").collection("test");
|
||||
do_check_neq(coll, null);
|
||||
@ -313,8 +312,7 @@ add_test(function test_bso_if_modified_since_304() {
|
||||
coll.timestamp -= 10000;
|
||||
coll.bso("bso").modified -= 10000;
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test/bso",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request.setHeader("X-If-Modified-Since", "" + server.serverTime());
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(null, error);
|
||||
@ -322,8 +320,7 @@ add_test(function test_bso_if_modified_since_304() {
|
||||
do_check_eq(request.response.status, 304);
|
||||
do_check_false("content-type" in request.response.headers);
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test/bso",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request.setHeader("X-If-Modified-Since", "" + (server.serverTime() - 20000));
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(null, error);
|
||||
@ -341,7 +338,7 @@ add_test(function test_bso_if_unmodified_since() {
|
||||
server.createContents("123", {
|
||||
test: {bso: {foo: "bar"}}
|
||||
});
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").collection("test");
|
||||
do_check_neq(coll, null);
|
||||
@ -349,8 +346,7 @@ add_test(function test_bso_if_unmodified_since() {
|
||||
let time = coll.timestamp;
|
||||
|
||||
_("Ensure we get a 412 for specified times older than server time.");
|
||||
let request = localRequest(server, "/2.0/123/storage/test/bso",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request.setHeader("X-If-Unmodified-Since", time - 5000);
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
let payload = JSON.stringify({"payload": "foobar"});
|
||||
@ -359,8 +355,7 @@ add_test(function test_bso_if_unmodified_since() {
|
||||
do_check_eq(request.response.status, 412);
|
||||
|
||||
_("Ensure we get a 204 if update goes through.");
|
||||
let request = localRequest(server, "/2.0/123/storage/test/bso",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
request.setHeader("X-If-Unmodified-Since", time + 1);
|
||||
let error = doPutRequest(request, payload);
|
||||
@ -371,8 +366,7 @@ add_test(function test_bso_if_unmodified_since() {
|
||||
// Not sure why a client would send X-If-Unmodified-Since if a BSO doesn't
|
||||
// exist. But, why not test it?
|
||||
_("Ensure we get a 201 if creation goes through.");
|
||||
let request = localRequest(server, "/2.0/123/storage/test/none",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/none", "123", "password");
|
||||
request.setHeader("Content-Type", "application/json");
|
||||
request.setHeader("X-If-Unmodified-Since", time);
|
||||
let error = doPutRequest(request, payload);
|
||||
@ -388,15 +382,14 @@ add_test(function test_bso_delete_not_exist() {
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.user("123").createCollection("empty");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
server.callback.onItemDeleted = function onItemDeleted(username, collection,
|
||||
id) {
|
||||
do_throw("onItemDeleted should not have been called.");
|
||||
};
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/empty/nada",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/empty/nada", "123", "password");
|
||||
let error = doDeleteRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 404);
|
||||
@ -410,7 +403,7 @@ add_test(function test_bso_delete_exists() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").createCollection("test");
|
||||
let bso = coll.insert("myid", {foo: "bar"});
|
||||
@ -423,8 +416,7 @@ add_test(function test_bso_delete_exists() {
|
||||
do_check_eq(id, "myid");
|
||||
};
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/test/myid",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/myid", "123", "password");
|
||||
let error = doDeleteRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 204);
|
||||
@ -432,8 +424,7 @@ add_test(function test_bso_delete_exists() {
|
||||
do_check_true(coll.timestamp > timestamp);
|
||||
|
||||
_("On next request the BSO should not exist.");
|
||||
let request = localRequest(server, "/2.0/123/storage/test/myid",
|
||||
"123", "password");
|
||||
let request = localRequest("/2.0/123/storage/test/myid", "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 404);
|
||||
@ -445,7 +436,7 @@ add_test(function test_bso_delete_unmodified() {
|
||||
_("Ensure X-If-Unmodified-Since works when deleting BSOs.");
|
||||
|
||||
let server = new StorageServer();
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
server.registerUser("123", "password");
|
||||
let coll = server.user("123").createCollection("test");
|
||||
let bso = coll.insert("myid", {foo: "bar"});
|
||||
@ -454,7 +445,7 @@ add_test(function test_bso_delete_unmodified() {
|
||||
|
||||
_("Issuing a DELETE with an older time should fail.");
|
||||
let path = "/2.0/123/storage/test/myid";
|
||||
let request = localRequest(server, path, "123", "password");
|
||||
let request = localRequest(path, "123", "password");
|
||||
request.setHeader("X-If-Unmodified-Since", modified - 1000);
|
||||
let error = doDeleteRequest(request);
|
||||
do_check_eq(error, null);
|
||||
@ -463,7 +454,7 @@ add_test(function test_bso_delete_unmodified() {
|
||||
do_check_neq(coll.bso("myid"), null);
|
||||
|
||||
_("Issuing a DELETE with a newer time should work.");
|
||||
let request = localRequest(server, path, "123", "password");
|
||||
let request = localRequest(path, "123", "password");
|
||||
request.setHeader("X-If-Unmodified-Since", modified + 1000);
|
||||
let error = doDeleteRequest(request);
|
||||
do_check_eq(error, null);
|
||||
@ -478,21 +469,19 @@ add_test(function test_collection_get_unmodified_since() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
let collection = server.user("123").createCollection("testcoll");
|
||||
collection.insert("bso0", {foo: "bar"});
|
||||
|
||||
let serverModified = collection.timestamp;
|
||||
|
||||
let request1 = localRequest(server, "/2.0/123/storage/testcoll",
|
||||
"123", "password");
|
||||
let request1 = localRequest("/2.0/123/storage/testcoll", "123", "password");
|
||||
request1.setHeader("X-If-Unmodified-Since", serverModified);
|
||||
let error = doGetRequest(request1);
|
||||
do_check_null(error);
|
||||
do_check_eq(request1.response.status, 200);
|
||||
|
||||
let request2 = localRequest(server, "/2.0/123/storage/testcoll",
|
||||
"123", "password");
|
||||
let request2 = localRequest("/2.0/123/storage/testcoll", "123", "password");
|
||||
request2.setHeader("X-If-Unmodified-Since", serverModified - 1);
|
||||
let error = doGetRequest(request2);
|
||||
do_check_null(error);
|
||||
@ -506,21 +495,21 @@ add_test(function test_bso_get_unmodified_since() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
let collection = server.user("123").createCollection("testcoll");
|
||||
let bso = collection.insert("bso0", {foo: "bar"});
|
||||
|
||||
let serverModified = bso.modified;
|
||||
|
||||
let request1 = localRequest(server, "/2.0/123/storage/testcoll/bso0",
|
||||
"123", "password");
|
||||
let request1 = localRequest("/2.0/123/storage/testcoll/bso0", "123",
|
||||
"password");
|
||||
request1.setHeader("X-If-Unmodified-Since", serverModified);
|
||||
let error = doGetRequest(request1);
|
||||
do_check_null(error);
|
||||
do_check_eq(request1.response.status, 200);
|
||||
|
||||
let request2 = localRequest(server, "/2.0/123/storage/testcoll/bso0",
|
||||
"123", "password");
|
||||
let request2 = localRequest("/2.0/123/storage/testcoll/bso0", "123",
|
||||
"password");
|
||||
request2.setHeader("X-If-Unmodified-Since", serverModified - 1);
|
||||
let error = doGetRequest(request2);
|
||||
do_check_null(error);
|
||||
@ -534,9 +523,9 @@ add_test(function test_missing_collection_404() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage/none", "123", "password");
|
||||
let request = localRequest("/2.0/123/storage/none", "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 404);
|
||||
@ -550,9 +539,9 @@ add_test(function test_get_storage_405() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage", "123", "password");
|
||||
let request = localRequest("/2.0/123/storage", "123", "password");
|
||||
let error = doGetRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 405);
|
||||
@ -571,9 +560,9 @@ add_test(function test_delete_storage() {
|
||||
baz: {c: {bob: "law"}, blah: {law: "blog"}}
|
||||
});
|
||||
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let request = localRequest(server, "/2.0/123/storage", "123", "password");
|
||||
let request = localRequest("/2.0/123/storage", "123", "password");
|
||||
let error = doDeleteRequest(request);
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(request.response.status, 204);
|
||||
@ -590,12 +579,12 @@ add_test(function test_x_num_records() {
|
||||
crypto: {foos: {foo: "bar"},
|
||||
bars: {foo: "baz"}}
|
||||
});
|
||||
server.startSynchronous();
|
||||
let bso = localRequest(server, "/2.0/123/storage/crypto/foos");
|
||||
server.startSynchronous(PORT);
|
||||
let bso = localRequest("/2.0/123/storage/crypto/foos");
|
||||
bso.get(function (err) {
|
||||
// BSO fetches don't have one.
|
||||
do_check_false("x-num-records" in this.response.headers);
|
||||
let col = localRequest(server, "/2.0/123/storage/crypto");
|
||||
let col = localRequest("/2.0/123/storage/crypto");
|
||||
col.get(function (err) {
|
||||
// Collection fetches do.
|
||||
do_check_eq(this.response.headers["x-num-records"], "2");
|
||||
@ -612,10 +601,10 @@ add_test(function test_put_delete_put() {
|
||||
server.createContents("123", {
|
||||
test: {bso: {foo: "bar"}}
|
||||
});
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
_("Ensure we can PUT an existing record.");
|
||||
let request1 = localRequest(server, "/2.0/123/storage/test/bso", "123", "password");
|
||||
let request1 = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request1.setHeader("Content-Type", "application/json");
|
||||
let payload1 = JSON.stringify({"payload": "foobar"});
|
||||
let error1 = doPutRequest(request1, payload1);
|
||||
@ -623,14 +612,14 @@ add_test(function test_put_delete_put() {
|
||||
do_check_eq(request1.response.status, 204);
|
||||
|
||||
_("Ensure we can DELETE it.");
|
||||
let request2 = localRequest(server, "/2.0/123/storage/test/bso", "123", "password");
|
||||
let request2 = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
let error2 = doDeleteRequest(request2);
|
||||
do_check_eq(error2, null);
|
||||
do_check_eq(request2.response.status, 204);
|
||||
do_check_false("content-type" in request2.response.headers);
|
||||
|
||||
_("Ensure we can PUT a previously deleted record.");
|
||||
let request3 = localRequest(server, "/2.0/123/storage/test/bso", "123", "password");
|
||||
let request3 = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
request3.setHeader("Content-Type", "application/json");
|
||||
let payload3 = JSON.stringify({"payload": "foobar"});
|
||||
let error3 = doPutRequest(request3, payload3);
|
||||
@ -638,7 +627,7 @@ add_test(function test_put_delete_put() {
|
||||
do_check_eq(request3.response.status, 201);
|
||||
|
||||
_("Ensure we can GET the re-uploaded record.");
|
||||
let request4 = localRequest(server, "/2.0/123/storage/test/bso", "123", "password");
|
||||
let request4 = localRequest("/2.0/123/storage/test/bso", "123", "password");
|
||||
let error4 = doGetRequest(request4);
|
||||
do_check_eq(error4, null);
|
||||
do_check_eq(request4.response.status, 200);
|
||||
@ -652,7 +641,7 @@ add_test(function test_collection_get_newer() {
|
||||
|
||||
let server = new StorageServer();
|
||||
server.registerUser("123", "password");
|
||||
server.startSynchronous();
|
||||
server.startSynchronous(PORT);
|
||||
|
||||
let coll = server.user("123").createCollection("test");
|
||||
let bso1 = coll.insert("001", {foo: "bar"});
|
||||
@ -662,7 +651,7 @@ add_test(function test_collection_get_newer() {
|
||||
bso2.modified = bso1.modified + 1000;
|
||||
|
||||
function newerRequest(newer) {
|
||||
return localRequest(server, "/2.0/123/storage/test?newer=" + newer,
|
||||
return localRequest("/2.0/123/storage/test?newer=" + newer,
|
||||
"123", "password");
|
||||
}
|
||||
|
||||
@ -688,4 +677,4 @@ add_test(function test_collection_get_newer() {
|
||||
do_check_attribute_count(items3, 0);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
});
|
@ -4,6 +4,8 @@
|
||||
Cu.import("resource://services-common/storageservice.js");
|
||||
Cu.import("resource://testing-common/services-common/storageserver.js");
|
||||
|
||||
const BASE_URI = "http://localhost:8080/2.0";
|
||||
|
||||
function run_test() {
|
||||
initTestLogging("Trace");
|
||||
|
||||
@ -25,11 +27,8 @@ function getEmptyServer(user=getRandomUser(), password="password") {
|
||||
});
|
||||
}
|
||||
|
||||
function getClient(server, user=getRandomUser(), password="password") {
|
||||
let identity = server.server.identity;
|
||||
let url = identity.primaryScheme + "://" + identity.primaryHost + ":" +
|
||||
identity.primaryPort + "/2.0/" + user;
|
||||
let client = new StorageServiceClient(url);
|
||||
function getClient(user=getRandomUser(), password="password") {
|
||||
let client = new StorageServiceClient(BASE_URI + "/" + user);
|
||||
client.addListener({
|
||||
onDispatch: function onDispatch(request) {
|
||||
let up = user + ":" + password;
|
||||
@ -42,7 +41,7 @@ function getClient(server, user=getRandomUser(), password="password") {
|
||||
|
||||
function getServerAndClient(user=getRandomUser(), password="password") {
|
||||
let server = getEmptyServer(user, password);
|
||||
let client = getClient(server, user, password);
|
||||
let client = getClient(user, password);
|
||||
|
||||
return [server, client, user, password];
|
||||
}
|
||||
@ -51,7 +50,7 @@ add_test(function test_auth_failure_listener() {
|
||||
_("Ensure the onAuthFailure listener is invoked.");
|
||||
|
||||
let server = getEmptyServer();
|
||||
let client = getClient(server, "324", "INVALID");
|
||||
let client = getClient("324", "INVALID");
|
||||
client.addListener({
|
||||
onAuthFailure: function onAuthFailure(client, request) {
|
||||
_("onAuthFailure");
|
||||
@ -67,7 +66,7 @@ add_test(function test_duplicate_listeners() {
|
||||
_("Ensure that duplicate listeners aren't installed multiple times.");
|
||||
|
||||
let server = getEmptyServer();
|
||||
let client = getClient(server, "1234567", "BAD_PASSWORD");
|
||||
let client = getClient("1234567", "BAD_PASSWORD");
|
||||
|
||||
let invokeCount = 0;
|
||||
let listener = {
|
||||
@ -587,9 +586,8 @@ add_test(function test_set_bso_conditional() {
|
||||
add_test(function test_set_bso_argument_errors() {
|
||||
_("Ensure BSO set detects invalid arguments.");
|
||||
|
||||
let server = getEmptyServer();
|
||||
let bso = new BasicStorageObject();
|
||||
let client = getClient(server);
|
||||
let client = getClient();
|
||||
|
||||
let threw = false;
|
||||
try {
|
||||
@ -627,7 +625,7 @@ add_test(function test_set_bso_argument_errors() {
|
||||
threw = false;
|
||||
}
|
||||
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_set_bsos_simple() {
|
||||
@ -661,8 +659,7 @@ add_test(function test_set_bsos_simple() {
|
||||
add_test(function test_set_bsos_invalid_bso() {
|
||||
_("Ensure that adding an invalid BSO throws.");
|
||||
|
||||
let server = getEmptyServer();
|
||||
let client = getClient(server);
|
||||
let client = getClient();
|
||||
let request = client.setBSOs("testcoll");
|
||||
|
||||
let threw = false;
|
||||
@ -687,7 +684,7 @@ add_test(function test_set_bsos_invalid_bso() {
|
||||
threw = false;
|
||||
}
|
||||
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_set_bsos_newline() {
|
||||
|
@ -21,12 +21,14 @@ add_test(function test_authenticated_request() {
|
||||
let id = "eyJleHBpcmVzIjogMTM2NTAxMDg5OC4x";
|
||||
let key = "qTZf4ZFpAMpMoeSsX3zVRjiqmNs=";
|
||||
let method = "GET";
|
||||
let uri = CommonUtils.makeURI(TEST_SERVER_URL + "foo");
|
||||
|
||||
let nonce = btoa(CryptoUtils.generateRandomBytes(16));
|
||||
let ts = Math.floor(Date.now() / 1000);
|
||||
let extra = {ts: ts, nonce: nonce};
|
||||
|
||||
let auth;
|
||||
let sig = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri, extra);
|
||||
let auth = sig.getHeader();
|
||||
|
||||
let server = httpd_setup({"/foo": function(request, response) {
|
||||
do_check_true(request.hasHeader("Authorization"));
|
||||
@ -36,9 +38,6 @@ add_test(function test_authenticated_request() {
|
||||
response.bodyOutputStream.write(message, message.length);
|
||||
}
|
||||
});
|
||||
let uri = CommonUtils.makeURI(server.baseURI + "/foo");
|
||||
let sig = CryptoUtils.computeHTTPMACSHA1(id, key, method, uri, extra);
|
||||
auth = sig.getHeader();
|
||||
|
||||
let req = new TokenAuthenticatedRESTRequest(uri, {id: id, key: key}, extra);
|
||||
let cb = Async.makeSpinningCallback();
|
||||
@ -49,4 +48,4 @@ add_test(function test_authenticated_request() {
|
||||
do_check_eq(message, req.response.body);
|
||||
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
});
|
@ -36,7 +36,7 @@ add_test(function test_working_bid_exchange() {
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let cb = Async.makeSpinningCallback();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", cb);
|
||||
let result = cb.wait();
|
||||
do_check_eq("object", typeof(result));
|
||||
@ -93,7 +93,7 @@ add_test(function test_conditions_required_response_handling() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
|
||||
function onResponse(error, token) {
|
||||
do_check_true(error instanceof TokenServerClientServerError);
|
||||
@ -125,7 +125,7 @@ add_test(function test_invalid_403_no_content_type() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
|
||||
function onResponse(error, token) {
|
||||
do_check_true(error instanceof TokenServerClientServerError);
|
||||
@ -156,7 +156,7 @@ add_test(function test_invalid_403_bad_json() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
|
||||
function onResponse(error, token) {
|
||||
do_check_true(error instanceof TokenServerClientServerError);
|
||||
@ -184,7 +184,7 @@ add_test(function test_403_no_urls() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion",
|
||||
function onResponse(error, result) {
|
||||
@ -219,7 +219,7 @@ add_test(function test_send_conditions_accepted() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
|
||||
function onResponse(error, token) {
|
||||
do_check_null(error);
|
||||
@ -238,7 +238,7 @@ add_test(function test_error_404_empty() {
|
||||
let server = httpd_setup();
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/foo";
|
||||
let url = TEST_SERVER_URL + "foo";
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
|
||||
do_check_true(error instanceof TokenServerClientServerError);
|
||||
do_check_eq(error.cause, "malformed-response");
|
||||
@ -276,7 +276,7 @@ add_test(function test_error_404_proper_response() {
|
||||
}
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", onResponse);
|
||||
});
|
||||
|
||||
@ -294,7 +294,7 @@ add_test(function test_bad_json() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
|
||||
do_check_neq(null, error);
|
||||
do_check_eq("TokenServerClientServerError", error.name);
|
||||
@ -320,7 +320,7 @@ add_test(function test_400_response() {
|
||||
});
|
||||
|
||||
let client = new TokenServerClient();
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
|
||||
do_check_neq(null, error);
|
||||
do_check_eq("TokenServerClientServerError", error.name);
|
||||
@ -344,7 +344,7 @@ add_test(function test_unhandled_media_type() {
|
||||
}
|
||||
});
|
||||
|
||||
let url = server.baseURI + "/1.0/foo/1.0";
|
||||
let url = TEST_SERVER_URL + "1.0/foo/1.0";
|
||||
let client = new TokenServerClient();
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
|
||||
do_check_neq(null, error);
|
||||
@ -374,7 +374,7 @@ add_test(function test_rich_media_types() {
|
||||
}
|
||||
});
|
||||
|
||||
let url = server.baseURI + "/foo";
|
||||
let url = TEST_SERVER_URL + "foo";
|
||||
let client = new TokenServerClient();
|
||||
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
|
||||
do_check_eq(null, error);
|
||||
@ -401,7 +401,7 @@ add_test(function test_exception_during_callback() {
|
||||
}
|
||||
});
|
||||
|
||||
let url = server.baseURI + "/foo";
|
||||
let url = TEST_SERVER_URL + "foo";
|
||||
let client = new TokenServerClient();
|
||||
let cb = Async.makeSpinningCallback();
|
||||
let callbackCount = 0;
|
||||
|
@ -22,7 +22,9 @@ Cu.import("resource://testing-common/services/metrics/mocks.jsm");
|
||||
Cu.import("resource://testing-common/services/healthreport/utils.jsm");
|
||||
|
||||
|
||||
const DUMMY_URI = "http://localhost:62013/";
|
||||
const SERVER_HOSTNAME = "localhost";
|
||||
const SERVER_PORT = 8080;
|
||||
const SERVER_URI = "http://" + SERVER_HOSTNAME + ":" + SERVER_PORT;
|
||||
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
const HealthReporterState = bsp.HealthReporterState;
|
||||
@ -38,7 +40,7 @@ function defineNow(policy, now) {
|
||||
});
|
||||
}
|
||||
|
||||
function getJustReporter(name, uri=DUMMY_URI, inspected=false) {
|
||||
function getJustReporter(name, uri=SERVER_URI, inspected=false) {
|
||||
let branch = "healthreport.testing." + name + ".";
|
||||
|
||||
let prefs = new Preferences(branch + "healthreport.");
|
||||
@ -82,13 +84,14 @@ function getReporter(name, uri, inspected) {
|
||||
|
||||
function getReporterAndServer(name, namespace="test") {
|
||||
return Task.spawn(function get() {
|
||||
let server = new BagheeraServer();
|
||||
server.createNamespace(namespace);
|
||||
server.start();
|
||||
|
||||
let reporter = yield getReporter(name, server.serverURI);
|
||||
let reporter = yield getReporter(name, SERVER_URI);
|
||||
reporter.serverNamespace = namespace;
|
||||
|
||||
let server = new BagheeraServer(SERVER_URI);
|
||||
server.createNamespace(namespace);
|
||||
|
||||
server.start(SERVER_PORT);
|
||||
|
||||
throw new Task.Result([reporter, server]);
|
||||
});
|
||||
}
|
||||
@ -164,7 +167,7 @@ add_task(function test_shutdown_normal() {
|
||||
});
|
||||
|
||||
add_task(function test_shutdown_storage_in_progress() {
|
||||
let reporter = yield getJustReporter("shutdown_storage_in_progress", DUMMY_URI, true);
|
||||
let reporter = yield getJustReporter("shutdown_storage_in_progress", SERVER_URI, true);
|
||||
|
||||
reporter.onStorageCreated = function () {
|
||||
print("Faking shutdown during storage initialization.");
|
||||
@ -182,7 +185,7 @@ add_task(function test_shutdown_storage_in_progress() {
|
||||
// results in shutdown and storage closure.
|
||||
add_task(function test_shutdown_provider_manager_in_progress() {
|
||||
let reporter = yield getJustReporter("shutdown_provider_manager_in_progress",
|
||||
DUMMY_URI, true);
|
||||
SERVER_URI, true);
|
||||
|
||||
reporter.onProviderManagerInitialized = function () {
|
||||
print("Faking shutdown during provider manager initialization.");
|
||||
@ -200,7 +203,7 @@ add_task(function test_shutdown_provider_manager_in_progress() {
|
||||
// Simulates an error during provider manager initialization and verifies we shut down.
|
||||
add_task(function test_shutdown_when_provider_manager_errors() {
|
||||
let reporter = yield getJustReporter("shutdown_when_provider_manager_errors",
|
||||
DUMMY_URI, true);
|
||||
SERVER_URI, true);
|
||||
|
||||
reporter.onInitializeProviderManagerFinished = function () {
|
||||
print("Throwing fake error.");
|
||||
@ -583,7 +586,7 @@ add_task(function test_idle_daily() {
|
||||
add_task(function test_data_submission_transport_failure() {
|
||||
let reporter = yield getReporter("data_submission_transport_failure");
|
||||
try {
|
||||
reporter.serverURI = DUMMY_URI;
|
||||
reporter.serverURI = "http://localhost:8080/";
|
||||
reporter.serverNamespace = "test00";
|
||||
|
||||
let deferred = Promise.defer();
|
||||
@ -870,10 +873,10 @@ add_task(function test_failure_if_not_initialized() {
|
||||
});
|
||||
|
||||
add_task(function test_upload_on_init_failure() {
|
||||
let server = new BagheeraServer();
|
||||
server.start();
|
||||
let reporter = yield getJustReporter("upload_on_init_failure", server.serverURI, true);
|
||||
let reporter = yield getJustReporter("upload_on_init_failure", SERVER_URI, true);
|
||||
let server = new BagheeraServer(SERVER_URI);
|
||||
server.createNamespace(reporter.serverNamespace);
|
||||
server.start(SERVER_PORT);
|
||||
|
||||
reporter.onInitializeProviderManagerFinished = function () {
|
||||
throw new Error("Fake error during provider manager initialization.");
|
||||
|
@ -5,6 +5,8 @@
|
||||
"use strict";
|
||||
|
||||
this.EXPORTED_SYMBOLS = [
|
||||
"TEST_CLUSTER_URL",
|
||||
"TEST_SERVER_URL",
|
||||
"btoa", // It comes from a module import.
|
||||
"encryptPayload",
|
||||
"setBasicCredentials",
|
||||
@ -19,6 +21,9 @@ Cu.import("resource://services-crypto/utils.js");
|
||||
Cu.import("resource://testing-common/services-common/logging.js");
|
||||
Cu.import("resource://testing-common/services/sync/fakeservices.js");
|
||||
|
||||
this.TEST_SERVER_URL = "http://localhost:8080/";
|
||||
this.TEST_CLUSTER_URL = TEST_SERVER_URL;
|
||||
|
||||
/**
|
||||
* First wait >100ms (nsITimers can take up to that much time to fire, so
|
||||
* we can account for the timer in delayedAutoconnect) and then two event
|
||||
@ -48,7 +53,8 @@ this.setBasicCredentials =
|
||||
auth.syncKey = syncKey;
|
||||
}
|
||||
|
||||
this.SyncTestingInfrastructure = function (server, username, password, syncKey) {
|
||||
this.SyncTestingInfrastructure =
|
||||
function SyncTestingInfrastructure(username, password, syncKey) {
|
||||
let ns = {};
|
||||
Cu.import("resource://services-sync/service.js", ns);
|
||||
|
||||
@ -57,12 +63,8 @@ this.SyncTestingInfrastructure = function (server, username, password, syncKey)
|
||||
auth.basicPassword = password || "password";
|
||||
auth.syncKey = syncKey || "abcdeabcdeabcdeabcdeabcdea";
|
||||
|
||||
let i = server.identity;
|
||||
let uri = i.primaryScheme + "://" + i.primaryHost + ":" +
|
||||
i.primaryPort + "/";
|
||||
|
||||
ns.Service.serverURL = uri;
|
||||
ns.Service.clusterURL = uri;
|
||||
ns.Service.serverURL = TEST_SERVER_URL;
|
||||
ns.Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
this.logStats = initTestLogging();
|
||||
this.fakeFilesystem = new FakeFilesystemService({});
|
||||
|
@ -535,6 +535,7 @@ function SyncServer(callback) {
|
||||
handler._handleDefault = this.handleDefault.bind(this, handler);
|
||||
}
|
||||
SyncServer.prototype = {
|
||||
port: 8080,
|
||||
server: null, // HttpServer.
|
||||
users: null, // Map of username => {collections, password}.
|
||||
|
||||
@ -543,7 +544,7 @@ SyncServer.prototype = {
|
||||
*
|
||||
* @param port
|
||||
* The numeric port on which to start. A falsy value implies the
|
||||
* default, a randomly chosen port.
|
||||
* default (8080).
|
||||
* @param cb
|
||||
* A callback function (of no arguments) which is invoked after
|
||||
* startup.
|
||||
@ -553,25 +554,23 @@ SyncServer.prototype = {
|
||||
this._log.warn("Warning: server already started on " + this.port);
|
||||
return;
|
||||
}
|
||||
if (port) {
|
||||
this.port = port;
|
||||
}
|
||||
try {
|
||||
this.server.start(port);
|
||||
let i = this.server.identity;
|
||||
this.port = i.primaryPort;
|
||||
this.baseURI = i.primaryScheme + "://" + i.primaryHost + ":" +
|
||||
i.primaryPort + "/";
|
||||
this.server.start(this.port);
|
||||
this.started = true;
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
} catch (ex) {
|
||||
_("==========================================");
|
||||
_("Got exception starting Sync HTTP server.");
|
||||
_("Got exception starting Sync HTTP server on port " + this.port);
|
||||
_("Error: " + Utils.exceptionStr(ex));
|
||||
_("Is there a process already listening on port " + port + "?");
|
||||
_("Is there a process already listening on port " + this.port + "?");
|
||||
_("==========================================");
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -158,9 +158,7 @@ add_test(function test_disabled_install_semantics() {
|
||||
const PASSPHRASE = "abcdeabcdeabcdeabcdeabcdea";
|
||||
const ADDON_ID = "addon1@tests.mozilla.org";
|
||||
|
||||
let server = new SyncServer();
|
||||
server.start();
|
||||
new SyncTestingInfrastructure(server.server, USER, PASSWORD, PASSPHRASE);
|
||||
new SyncTestingInfrastructure(USER, PASSWORD, PASSPHRASE);
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
@ -171,8 +169,10 @@ add_test(function test_disabled_install_semantics() {
|
||||
addons: {}
|
||||
};
|
||||
|
||||
let server = new SyncServer();
|
||||
server.registerUser(USER, "password");
|
||||
server.createContents(USER, contents);
|
||||
server.start();
|
||||
|
||||
let amoServer = new HttpServer();
|
||||
amoServer.registerFile("/search/guid:addon1%40tests.mozilla.org",
|
||||
@ -247,6 +247,8 @@ function run_test() {
|
||||
Log4Moz.repository.getLogger("Sync.AddonsRepository").level =
|
||||
Log4Moz.Level.Trace;
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
reconciler.startListening();
|
||||
|
||||
// Don't flush to disk in the middle of an event listener!
|
||||
|
@ -13,11 +13,10 @@ Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
Service.engineManager.register(BookmarksEngine);
|
||||
var syncTesting = new SyncTestingInfrastructure();
|
||||
|
||||
add_test(function bad_record_allIDs() {
|
||||
let server = new SyncServer();
|
||||
server.start();
|
||||
let syncTesting = new SyncTestingInfrastructure(server.server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
|
||||
_("Ensure that bad Places queries don't cause an error in getAllIDs.");
|
||||
let engine = new BookmarksEngine(Service);
|
||||
@ -44,13 +43,11 @@ add_test(function bad_record_allIDs() {
|
||||
|
||||
_("Clean up.");
|
||||
PlacesUtils.bookmarks.removeItem(badRecordID);
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_ID_caching() {
|
||||
let server = new SyncServer();
|
||||
server.start();
|
||||
let syncTesting = new SyncTestingInfrastructure(server.server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
|
||||
_("Ensure that Places IDs are not cached.");
|
||||
let engine = new BookmarksEngine(Service);
|
||||
@ -86,7 +83,7 @@ add_test(function test_ID_caching() {
|
||||
do_check_eq(newMobileID, store.idForGUID("mobile", false));
|
||||
|
||||
do_check_eq(store.GUIDForId(mobileID), "abcdefghijkl");
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
function serverForFoo(engine) {
|
||||
@ -99,11 +96,11 @@ function serverForFoo(engine) {
|
||||
|
||||
add_test(function test_processIncoming_error_orderChildren() {
|
||||
_("Ensure that _orderChildren() is called even when _processIncoming() throws an error.");
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
let server = serverForFoo(engine);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
|
||||
let collection = server.user("foo").collection("bookmarks");
|
||||
|
||||
@ -169,10 +166,11 @@ add_test(function test_processIncoming_error_orderChildren() {
|
||||
|
||||
add_task(function test_restorePromptsReupload() {
|
||||
_("Ensure that restoring from a backup will reupload all records.");
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
let server = serverForFoo(engine);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
|
||||
let collection = server.user("foo").collection("bookmarks");
|
||||
|
||||
@ -335,10 +333,11 @@ add_test(function test_mismatched_types() {
|
||||
"parentid": "toolbar"
|
||||
};
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
let server = serverForFoo(engine);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
|
||||
_("GUID: " + store.GUIDForId(6, true));
|
||||
|
||||
@ -377,13 +376,14 @@ add_test(function test_mismatched_types() {
|
||||
add_test(function test_bookmark_guidMap_fail() {
|
||||
_("Ensure that failures building the GUID map cause early death.");
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
|
||||
let store = engine._store;
|
||||
let server = serverForFoo(engine);
|
||||
let coll = server.user("foo").collection("bookmarks");
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
|
||||
// Add one item to the server.
|
||||
let itemID = PlacesUtils.bookmarks.createFolder(
|
||||
@ -475,9 +475,10 @@ add_test(function test_bookmark_tag_but_no_uri() {
|
||||
add_test(function test_misreconciled_root() {
|
||||
_("Ensure that we don't reconcile an arbitrary record with a root.");
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let engine = new BookmarksEngine(Service);
|
||||
let store = engine._store;
|
||||
let server = serverForFoo(engine);
|
||||
|
||||
// Log real hard for this test.
|
||||
store._log.trace = store._log.debug;
|
||||
@ -533,7 +534,7 @@ add_test(function test_misreconciled_root() {
|
||||
do_check_eq(parentGUIDBefore, parentGUIDAfter);
|
||||
do_check_eq(parentIDBefore, parentIDAfter);
|
||||
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
|
@ -22,6 +22,8 @@ let store = engine._store;
|
||||
// Clean up after other tests. Only necessary in XULRunner.
|
||||
store.wipe();
|
||||
|
||||
var syncTesting = new SyncTestingInfrastructure();
|
||||
|
||||
function newSmartBookmark(parent, uri, position, title, queryID) {
|
||||
let id = PlacesUtils.bookmarks.insertBookmark(parent, uri, position, title);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, SMART_BOOKMARKS_ANNO,
|
||||
@ -58,8 +60,7 @@ function serverForFoo(engine) {
|
||||
// Verify that Places smart bookmarks have their annotation uploaded and
|
||||
// handled locally.
|
||||
add_test(function test_annotation_uploaded() {
|
||||
let server = serverForFoo(engine);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let startCount = smartBookmarkCount();
|
||||
|
||||
@ -107,6 +108,7 @@ add_test(function test_annotation_uploaded() {
|
||||
do_check_eq(smartBookmarkCount(), startCount + 1);
|
||||
|
||||
_("Sync record to the server.");
|
||||
let server = serverForFoo(engine);
|
||||
let collection = server.user("foo").collection("bookmarks");
|
||||
|
||||
try {
|
||||
@ -173,8 +175,7 @@ add_test(function test_annotation_uploaded() {
|
||||
});
|
||||
|
||||
add_test(function test_smart_bookmarks_duped() {
|
||||
let server = serverForFoo(engine);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
let parent = PlacesUtils.toolbarFolderId;
|
||||
let uri =
|
||||
@ -188,6 +189,7 @@ add_test(function test_smart_bookmarks_duped() {
|
||||
let record = store.createRecord(mostVisitedGUID);
|
||||
|
||||
_("Prepare sync.");
|
||||
let server = serverForFoo(engine);
|
||||
let collection = server.user("foo").collection("bookmarks");
|
||||
|
||||
try {
|
||||
|
@ -58,7 +58,8 @@ add_test(function test_bad_hmac() {
|
||||
|
||||
try {
|
||||
let passphrase = "abcdeabcdeabcdeabcdeabcdea";
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.login("foo", "ilovejane", passphrase);
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
@ -168,6 +169,9 @@ add_test(function test_properties() {
|
||||
add_test(function test_sync() {
|
||||
_("Ensure that Clients engine uploads a new client record once a week.");
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
let contents = {
|
||||
meta: {global: {engines: {clients: {version: engine.version,
|
||||
syncID: engine.syncID}}}},
|
||||
@ -177,9 +181,6 @@ add_test(function test_sync() {
|
||||
let server = serverForUsers({"foo": "password"}, contents);
|
||||
let user = server.user("foo");
|
||||
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
function clientWBO() {
|
||||
return user.collection("clients").wbo(engine.localID);
|
||||
}
|
||||
@ -406,6 +407,8 @@ add_test(function test_process_incoming_commands() {
|
||||
add_test(function test_command_sync() {
|
||||
_("Ensure that commands are synced across clients.");
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
engine._store.wipe();
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
@ -416,8 +419,6 @@ add_test(function test_command_sync() {
|
||||
crypto: {}
|
||||
};
|
||||
let server = serverForUsers({"foo": "password"}, contents);
|
||||
new SyncTestingInfrastructure(server.server);
|
||||
|
||||
let user = server.user("foo");
|
||||
let remoteId = Utils.makeGUID();
|
||||
|
||||
|
@ -25,6 +25,8 @@ add_test(function test_missing_crypto_collection() {
|
||||
}
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane", "a-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa");
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
let handlers = {
|
||||
"/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler),
|
||||
@ -38,7 +40,6 @@ add_test(function test_missing_crypto_collection() {
|
||||
johnU(coll, new ServerCollection({}, true).handler());
|
||||
}
|
||||
let server = httpd_setup(handlers);
|
||||
Service.serverURL = server.baseURI;
|
||||
|
||||
try {
|
||||
let fresh = 0;
|
||||
|
@ -56,8 +56,8 @@ add_task(function test_locally_changed_keys() {
|
||||
};
|
||||
|
||||
setBasicCredentials("johndoe", "password", passphrase);
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.clusterURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Service.engineManager.register(HistoryEngine);
|
||||
|
||||
|
@ -10,8 +10,17 @@ Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
add_test(function test_processIncoming_abort() {
|
||||
_("An abort exception, raised in applyIncoming, will abort _processIncoming.");
|
||||
new SyncTestingInfrastructure();
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
let engine = new RotaryEngine(Service);
|
||||
|
||||
_("Create some server data.");
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
|
||||
let collection = new ServerCollection();
|
||||
let id = Utils.makeGUID();
|
||||
let payload = encryptPayload({id: id, denomination: "Record No. " + id});
|
||||
@ -21,14 +30,6 @@ add_test(function test_processIncoming_abort() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
new SyncTestingInfrastructure(server);
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
_("Create some server data.");
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
_("Fake applyIncoming to abort.");
|
||||
engine._store.applyIncoming = function (record) {
|
||||
let ex = {code: Engine.prototype.eEngineAbortApplyIncoming,
|
||||
|
@ -11,7 +11,7 @@ Cu.import("resource://services-sync/status.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
const FAKE_SERVER_URL = "http://dummy:9000/";
|
||||
const TEST_MAINTENANCE_URL = "http://localhost:8080/maintenance/";
|
||||
const logsdir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
|
||||
const LOG_PREFIX_SUCCESS = "success-";
|
||||
const LOG_PREFIX_ERROR = "error-";
|
||||
@ -125,10 +125,10 @@ function sync_httpd_setup() {
|
||||
});
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
function setUp() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
return generateAndUploadKeys();
|
||||
}
|
||||
@ -148,7 +148,7 @@ function clean() {
|
||||
|
||||
add_test(function test_401_logout() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -188,7 +188,7 @@ add_test(function test_401_logout() {
|
||||
|
||||
add_test(function test_credentials_changed_logout() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -228,8 +228,8 @@ add_test(function test_shouldReportError() {
|
||||
|
||||
// Give ourselves a clusterURL so that the temporary 401 no-error situation
|
||||
// doesn't come into play.
|
||||
Service.serverURL = FAKE_SERVER_URL;
|
||||
Service.clusterURL = FAKE_SERVER_URL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
// Test dontIgnoreErrors, non-network, non-prolonged, login error reported
|
||||
Status.resetSync();
|
||||
@ -407,7 +407,7 @@ add_test(function test_shouldReportError() {
|
||||
add_test(function test_shouldReportError_master_password() {
|
||||
_("Test error ignored due to locked master password");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Monkey patch Service.verifyLogin to imitate
|
||||
// master password being locked.
|
||||
@ -431,7 +431,7 @@ add_test(function test_login_syncAndReportErrors_non_network_error() {
|
||||
// Test non-network errors are reported
|
||||
// when calling syncAndReportErrors
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
Service.identity.basicPassword = null;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
@ -450,7 +450,7 @@ add_test(function test_sync_syncAndReportErrors_non_network_error() {
|
||||
// Test non-network errors are reported
|
||||
// when calling syncAndReportErrors
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -475,7 +475,7 @@ add_test(function test_login_syncAndReportErrors_prolonged_non_network_error() {
|
||||
// Test prolonged, non-network errors are
|
||||
// reported when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
Service.identity.basicPassword = null;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
@ -494,7 +494,7 @@ add_test(function test_sync_syncAndReportErrors_prolonged_non_network_error() {
|
||||
// Test prolonged, non-network errors are
|
||||
// reported when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -518,8 +518,8 @@ add_test(function test_sync_syncAndReportErrors_prolonged_non_network_error() {
|
||||
add_test(function test_login_syncAndReportErrors_network_error() {
|
||||
// Test network errors are reported when calling syncAndReportErrors.
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = FAKE_SERVER_URL;
|
||||
Service.clusterURL = FAKE_SERVER_URL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onSyncError);
|
||||
@ -555,8 +555,8 @@ add_test(function test_login_syncAndReportErrors_prolonged_network_error() {
|
||||
// Test prolonged, network errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = FAKE_SERVER_URL;
|
||||
Service.clusterURL = FAKE_SERVER_URL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onSyncError);
|
||||
@ -591,7 +591,7 @@ add_test(function test_sync_syncAndReportErrors_prolonged_network_error() {
|
||||
add_test(function test_login_prolonged_non_network_error() {
|
||||
// Test prolonged, non-network errors are reported
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
Service.identity.basicPassword = null;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
@ -609,7 +609,7 @@ add_test(function test_login_prolonged_non_network_error() {
|
||||
add_test(function test_sync_prolonged_non_network_error() {
|
||||
// Test prolonged, non-network errors are reported
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -633,8 +633,8 @@ add_test(function test_sync_prolonged_non_network_error() {
|
||||
add_test(function test_login_prolonged_network_error() {
|
||||
// Test prolonged, network errors are reported
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = FAKE_SERVER_URL;
|
||||
Service.clusterURL = FAKE_SERVER_URL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
Svc.Obs.remove("weave:ui:login:error", onSyncError);
|
||||
@ -668,7 +668,7 @@ add_test(function test_sync_prolonged_network_error() {
|
||||
add_test(function test_login_non_network_error() {
|
||||
// Test non-network errors are reported
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
Service.identity.basicPassword = null;
|
||||
|
||||
Svc.Obs.add("weave:ui:login:error", function onSyncError() {
|
||||
@ -686,7 +686,7 @@ add_test(function test_login_non_network_error() {
|
||||
add_test(function test_sync_non_network_error() {
|
||||
// Test non-network errors are reported
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// By calling sync, we ensure we're logged in.
|
||||
Service.sync();
|
||||
@ -709,8 +709,8 @@ add_test(function test_sync_non_network_error() {
|
||||
|
||||
add_test(function test_login_network_error() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = FAKE_SERVER_URL;
|
||||
Service.clusterURL = FAKE_SERVER_URL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
// Test network errors are not reported.
|
||||
Svc.Obs.add("weave:ui:clear-error", function onClearError() {
|
||||
@ -747,7 +747,7 @@ add_test(function test_sync_network_error() {
|
||||
add_test(function test_sync_server_maintenance_error() {
|
||||
// Test server maintenance errors are not reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -780,12 +780,12 @@ add_test(function test_sync_server_maintenance_error() {
|
||||
add_test(function test_info_collections_login_server_maintenance_error() {
|
||||
// Test info/collections server maintenance errors are not reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
Service.username = "broken.info";
|
||||
setBasicCredentials("broken.info", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -821,11 +821,11 @@ add_test(function test_info_collections_login_server_maintenance_error() {
|
||||
add_test(function test_meta_global_login_server_maintenance_error() {
|
||||
// Test meta/global server maintenance errors are not reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.meta", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -861,11 +861,11 @@ add_test(function test_meta_global_login_server_maintenance_error() {
|
||||
add_test(function test_crypto_keys_login_server_maintenance_error() {
|
||||
// Test crypto/keys server maintenance errors are not reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.keys", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
// Force re-download of keys
|
||||
Service.collectionKeys.clear();
|
||||
@ -904,7 +904,7 @@ add_test(function test_crypto_keys_login_server_maintenance_error() {
|
||||
add_test(function test_sync_prolonged_server_maintenance_error() {
|
||||
// Test prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -930,11 +930,11 @@ add_test(function test_sync_prolonged_server_maintenance_error() {
|
||||
add_test(function test_info_collections_login_prolonged_server_maintenance_error(){
|
||||
// Test info/collections prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.info", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -963,11 +963,11 @@ add_test(function test_info_collections_login_prolonged_server_maintenance_error
|
||||
add_test(function test_meta_global_login_prolonged_server_maintenance_error(){
|
||||
// Test meta/global prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.meta", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -996,11 +996,11 @@ add_test(function test_meta_global_login_prolonged_server_maintenance_error(){
|
||||
add_test(function test_download_crypto_keys_login_prolonged_server_maintenance_error(){
|
||||
// Test crypto/keys prolonged server maintenance errors are reported.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.keys", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
// Force re-download of keys
|
||||
Service.collectionKeys.clear();
|
||||
|
||||
@ -1034,8 +1034,8 @@ add_test(function test_upload_crypto_keys_login_prolonged_server_maintenance_err
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.keys", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1068,8 +1068,8 @@ add_test(function test_wipeServer_login_prolonged_server_maintenance_error(){
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1102,8 +1102,8 @@ add_test(function test_wipeRemote_prolonged_server_maintenance_error(){
|
||||
|
||||
server.registerPathHandler("/1.1/broken.wipe/storage/catapult", service_unavailable);
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
generateAndUploadKeys();
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -1140,7 +1140,7 @@ add_test(function test_sync_syncAndReportErrors_server_maintenance_error() {
|
||||
// Test server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -1167,11 +1167,11 @@ add_test(function test_info_collections_login_syncAndReportErrors_server_mainten
|
||||
// Test info/collections server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.info", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1201,11 +1201,11 @@ add_test(function test_meta_global_login_syncAndReportErrors_server_maintenance_
|
||||
// Test meta/global server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.meta", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1235,11 +1235,11 @@ add_test(function test_download_crypto_keys_login_syncAndReportErrors_server_mai
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.keys", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
// Force re-download of keys
|
||||
Service.collectionKeys.clear();
|
||||
|
||||
@ -1274,8 +1274,8 @@ add_test(function test_upload_crypto_keys_login_syncAndReportErrors_server_maint
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.keys", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1308,8 +1308,8 @@ add_test(function test_wipeServer_login_syncAndReportErrors_server_maintenance_e
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1341,8 +1341,8 @@ add_test(function test_wipeRemote_syncAndReportErrors_server_maintenance_error()
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
generateAndUploadKeys();
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -1379,7 +1379,7 @@ add_test(function test_sync_syncAndReportErrors_prolonged_server_maintenance_err
|
||||
// Test prolonged server maintenance errors are
|
||||
// reported when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -1406,11 +1406,11 @@ add_test(function test_info_collections_login_syncAndReportErrors_prolonged_serv
|
||||
// Test info/collections server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.info", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1440,11 +1440,11 @@ add_test(function test_meta_global_login_syncAndReportErrors_prolonged_server_ma
|
||||
// Test meta/global server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.meta", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1474,11 +1474,11 @@ add_test(function test_download_crypto_keys_login_syncAndReportErrors_prolonged_
|
||||
// Test crypto/keys server maintenance errors are reported
|
||||
// when calling syncAndReportErrors.
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
setBasicCredentials("broken.keys", "irrelevant", "irrelevant");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
// Force re-download of keys
|
||||
Service.collectionKeys.clear();
|
||||
|
||||
@ -1513,8 +1513,8 @@ add_test(function test_upload_crypto_keys_login_syncAndReportErrors_prolonged_se
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.keys", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1547,8 +1547,8 @@ add_test(function test_wipeServer_login_syncAndReportErrors_prolonged_server_mai
|
||||
|
||||
// Start off with an empty account, do not upload a key.
|
||||
setBasicCredentials("broken.wipe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/maintenance/";
|
||||
Service.clusterURL = server.baseURI + "/maintenance/";
|
||||
Service.serverURL = TEST_MAINTENANCE_URL;
|
||||
Service.clusterURL = TEST_MAINTENANCE_URL;
|
||||
|
||||
let backoffInterval;
|
||||
Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
|
||||
@ -1615,7 +1615,7 @@ add_test(function test_sync_engine_generic_fail() {
|
||||
});
|
||||
});
|
||||
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(setUp());
|
||||
Service.sync();
|
||||
});
|
||||
|
||||
@ -1708,6 +1708,6 @@ add_test(function test_engine_applyFailed() {
|
||||
});
|
||||
|
||||
do_check_eq(Status.engines["catapult"], undefined);
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(setUp());
|
||||
Service.sync();
|
||||
});
|
||||
|
@ -53,26 +53,26 @@ function sync_httpd_setup() {
|
||||
return httpd_setup(handlers);
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
function setUp() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "aabcdeabcdeabcdeabcdeabcde");
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
new FakeCryptoService();
|
||||
}
|
||||
|
||||
function generateAndUploadKeys(server) {
|
||||
function generateAndUploadKeys() {
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Service.identity.syncKeyBundle);
|
||||
let res = Service.resource(server.baseURI + "/1.1/johndoe/storage/crypto/keys");
|
||||
let res = Service.resource("http://localhost:8080/1.1/johndoe/storage/crypto/keys");
|
||||
return serverKeys.upload(res).success;
|
||||
}
|
||||
|
||||
|
||||
add_test(function test_backoff500() {
|
||||
_("Test: HTTP 500 sets backoff status.");
|
||||
setUp();
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -82,7 +82,7 @@ add_test(function test_backoff500() {
|
||||
do_check_false(Status.enforceBackoff);
|
||||
|
||||
// Forcibly create and upload keys here -- otherwise we don't get to the 500!
|
||||
do_check_true(generateAndUploadKeys(server));
|
||||
do_check_true(generateAndUploadKeys());
|
||||
|
||||
Service.login();
|
||||
Service.sync();
|
||||
@ -98,8 +98,8 @@ add_test(function test_backoff500() {
|
||||
|
||||
add_test(function test_backoff503() {
|
||||
_("Test: HTTP 503 with Retry-After header leads to backoff notification and sets backoff status.");
|
||||
setUp();
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -115,7 +115,7 @@ add_test(function test_backoff503() {
|
||||
try {
|
||||
do_check_false(Status.enforceBackoff);
|
||||
|
||||
do_check_true(generateAndUploadKeys(server));
|
||||
do_check_true(generateAndUploadKeys());
|
||||
|
||||
Service.login();
|
||||
Service.sync();
|
||||
@ -134,8 +134,8 @@ add_test(function test_backoff503() {
|
||||
|
||||
add_test(function test_overQuota() {
|
||||
_("Test: HTTP 400 with body error code 14 means over quota.");
|
||||
setUp();
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -145,7 +145,7 @@ add_test(function test_overQuota() {
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(generateAndUploadKeys(server));
|
||||
do_check_true(generateAndUploadKeys());
|
||||
|
||||
Service.login();
|
||||
Service.sync();
|
||||
@ -161,56 +161,50 @@ add_test(function test_overQuota() {
|
||||
|
||||
add_test(function test_service_networkError() {
|
||||
_("Test: Connection refused error from Service.sync() leads to the right status code.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
server.stop(() => {
|
||||
// Provoke connection refused.
|
||||
Service.clusterURL = "http://localhost:12345/";
|
||||
setUp();
|
||||
// Provoke connection refused.
|
||||
Service.clusterURL = "http://localhost:12345/";
|
||||
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
Service._loggedIn = true;
|
||||
Service.sync();
|
||||
Service._loggedIn = true;
|
||||
Service.sync();
|
||||
|
||||
do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
} finally {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
run_next_test();
|
||||
});
|
||||
do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
} finally {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_service_offline() {
|
||||
_("Test: Wanting to sync in offline mode leads to the right status code but does not increment the ignorable error count.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
server.stop(() => {
|
||||
Services.io.offline = true;
|
||||
setUp();
|
||||
Services.io.offline = true;
|
||||
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
Service._loggedIn = true;
|
||||
Service.sync();
|
||||
Service._loggedIn = true;
|
||||
Service.sync();
|
||||
|
||||
do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
} finally {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
Services.io.offline = false;
|
||||
run_next_test();
|
||||
});
|
||||
do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
|
||||
do_check_eq(Status.service, SYNC_FAILED);
|
||||
} finally {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
Services.io.offline = false;
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_engine_networkError() {
|
||||
_("Test: Network related exceptions from engine.sync() lead to the right status code.");
|
||||
setUp();
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -220,7 +214,7 @@ add_test(function test_engine_networkError() {
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(generateAndUploadKeys(server));
|
||||
do_check_true(generateAndUploadKeys());
|
||||
|
||||
Service.login();
|
||||
Service.sync();
|
||||
@ -235,8 +229,8 @@ add_test(function test_engine_networkError() {
|
||||
});
|
||||
|
||||
add_test(function test_resource_timeout() {
|
||||
setUp();
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -247,7 +241,7 @@ add_test(function test_resource_timeout() {
|
||||
try {
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(generateAndUploadKeys(server));
|
||||
do_check_true(generateAndUploadKeys());
|
||||
|
||||
Service.login();
|
||||
Service.sync();
|
||||
|
@ -17,6 +17,8 @@ add_test(function test_processIncoming_mobile_history_batched() {
|
||||
|
||||
let FAKE_DOWNLOAD_LIMIT = 100;
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
PlacesUtils.history.removeAllPages();
|
||||
Service.engineManager.register(HistoryEngine);
|
||||
@ -30,12 +32,6 @@ add_test(function test_processIncoming_mobile_history_batched() {
|
||||
return this._get(options);
|
||||
};
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/history": collection.handler()
|
||||
});
|
||||
|
||||
new SyncTestingInfrastructure(server);
|
||||
|
||||
// Let's create some 234 server side history records. They're all at least
|
||||
// 10 minutes old.
|
||||
let visitType = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
@ -55,6 +51,10 @@ add_test(function test_processIncoming_mobile_history_batched() {
|
||||
collection.insertWBO(wbo);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/history": collection.handler()
|
||||
});
|
||||
|
||||
let engine = Service.engineManager.get("history");
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
|
@ -22,6 +22,8 @@ function shared_setup() {
|
||||
|
||||
// Do not instantiate SyncTestingInfrastructure; we need real crypto.
|
||||
setBasicCredentials("foo", "foo", "aabcdeabcdeabcdeabcdeabcde");
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
// Make sure RotaryEngine is the only one we sync.
|
||||
Service.engineManager._engines = {};
|
||||
@ -78,7 +80,6 @@ add_test(function hmac_error_during_404() {
|
||||
};
|
||||
|
||||
let server = sync_httpd_setup(handlers);
|
||||
Service.serverURL = server.baseURI;
|
||||
|
||||
try {
|
||||
_("Syncing.");
|
||||
@ -154,7 +155,6 @@ add_test(function hmac_error_during_node_reassignment() {
|
||||
};
|
||||
|
||||
let server = sync_httpd_setup(handlers);
|
||||
Service.serverURL = server.baseURI;
|
||||
_("Syncing.");
|
||||
// First hit of clients will 401. This will happen after meta/global and
|
||||
// keys -- i.e., in the middle of the sync, but before RotaryEngine.
|
||||
|
@ -65,9 +65,9 @@ add_test(function test_url_parsing() {
|
||||
});
|
||||
|
||||
Cu.import("resource://services-common/rest.js");
|
||||
function localRequest(server, path) {
|
||||
function localRequest(path) {
|
||||
_("localRequest: " + path);
|
||||
let url = server.baseURI.substr(0, server.baseURI.length - 1) + path;
|
||||
let url = "http://127.0.0.1:8080" + path;
|
||||
_("url: " + url);
|
||||
return new RESTRequest(url);
|
||||
}
|
||||
@ -76,10 +76,11 @@ add_test(function test_basic_http() {
|
||||
let server = new SyncServer();
|
||||
server.registerUser("john", "password");
|
||||
do_check_true(server.userExists("john"));
|
||||
server.start(null, function () {
|
||||
server.start(8080, function () {
|
||||
_("Started on " + server.port);
|
||||
do_check_eq(server.port, 8080);
|
||||
Utils.nextTick(function () {
|
||||
let req = localRequest(server, "/1.1/john/storage/crypto/keys");
|
||||
let req = localRequest("/1.1/john/storage/crypto/keys");
|
||||
_("req is " + req);
|
||||
req.get(function (err) {
|
||||
do_check_eq(null, err);
|
||||
@ -102,9 +103,10 @@ add_test(function test_info_collections() {
|
||||
}
|
||||
|
||||
server.registerUser("john", "password");
|
||||
server.start(null, function () {
|
||||
server.start(8080, function () {
|
||||
do_check_eq(server.port, 8080);
|
||||
Utils.nextTick(function () {
|
||||
let req = localRequest(server, "/1.1/john/info/collections");
|
||||
let req = localRequest("/1.1/john/info/collections");
|
||||
req.get(function (err) {
|
||||
// Initial info/collections fetch is empty.
|
||||
do_check_eq(null, err);
|
||||
@ -119,7 +121,7 @@ add_test(function test_info_collections() {
|
||||
let putResponseBody = this.response.body;
|
||||
_("PUT response body: " + JSON.stringify(putResponseBody));
|
||||
|
||||
req = localRequest(server, "/1.1/john/info/collections");
|
||||
req = localRequest("/1.1/john/info/collections");
|
||||
req.get(function (err) {
|
||||
do_check_eq(null, err);
|
||||
responseHasCorrectHeaders(this.response);
|
||||
@ -135,7 +137,7 @@ add_test(function test_info_collections() {
|
||||
});
|
||||
}
|
||||
let payload = JSON.stringify({foo: "bar"});
|
||||
localRequest(server, "/1.1/john/storage/crypto/keys").put(payload, cb);
|
||||
localRequest("/1.1/john/storage/crypto/keys").put(payload, cb);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -161,7 +163,7 @@ add_test(function test_storage_request() {
|
||||
do_check_true(coll.timestamp >= creation);
|
||||
|
||||
function retrieveWBONotExists(next) {
|
||||
let req = localRequest(server, keysURL);
|
||||
let req = localRequest(keysURL);
|
||||
req.get(function (err) {
|
||||
_("Body is " + this.response.body);
|
||||
_("Modified is " + this.response.newModified);
|
||||
@ -172,7 +174,7 @@ add_test(function test_storage_request() {
|
||||
});
|
||||
}
|
||||
function retrieveWBOExists(next) {
|
||||
let req = localRequest(server, foosURL);
|
||||
let req = localRequest(foosURL);
|
||||
req.get(function (err) {
|
||||
_("Body is " + this.response.body);
|
||||
_("Modified is " + this.response.newModified);
|
||||
@ -184,7 +186,7 @@ add_test(function test_storage_request() {
|
||||
});
|
||||
}
|
||||
function deleteWBONotExists(next) {
|
||||
let req = localRequest(server, keysURL);
|
||||
let req = localRequest(keysURL);
|
||||
server.callback.onItemDeleted = function (username, collection, wboID) {
|
||||
do_throw("onItemDeleted should not have been called.");
|
||||
};
|
||||
@ -198,7 +200,7 @@ add_test(function test_storage_request() {
|
||||
});
|
||||
}
|
||||
function deleteWBOExists(next) {
|
||||
let req = localRequest(server, foosURL);
|
||||
let req = localRequest(foosURL);
|
||||
server.callback.onItemDeleted = function (username, collection, wboID) {
|
||||
_("onItemDeleted called for " + collection + "/" + wboID);
|
||||
delete server.callback.onItemDeleted;
|
||||
@ -218,7 +220,7 @@ add_test(function test_storage_request() {
|
||||
_("Testing DELETE on /storage.");
|
||||
let now = server.timestamp();
|
||||
_("Timestamp: " + now);
|
||||
let req = localRequest(server, storageURL);
|
||||
let req = localRequest(storageURL);
|
||||
req.delete(function (err) {
|
||||
_("Body is " + this.response.body);
|
||||
_("Modified is " + this.response.newModified);
|
||||
@ -230,7 +232,7 @@ add_test(function test_storage_request() {
|
||||
}
|
||||
function getStorageFails(next) {
|
||||
_("Testing that GET on /storage fails.");
|
||||
let req = localRequest(server, storageURL);
|
||||
let req = localRequest(storageURL);
|
||||
req.get(function (err) {
|
||||
do_check_eq(this.response.status, 405);
|
||||
do_check_eq(this.response.headers["allow"], "DELETE");
|
||||
@ -239,14 +241,14 @@ add_test(function test_storage_request() {
|
||||
}
|
||||
function getMissingCollectionWBO(next) {
|
||||
_("Testing that fetching a WBO from an on-existent collection 404s.");
|
||||
let req = localRequest(server, storageURL + "/foobar/baz");
|
||||
let req = localRequest(storageURL + "/foobar/baz");
|
||||
req.get(function (err) {
|
||||
do_check_eq(this.response.status, 404);
|
||||
Utils.nextTick(next);
|
||||
});
|
||||
}
|
||||
|
||||
server.start(null,
|
||||
server.start(8080,
|
||||
Async.chain(
|
||||
retrieveWBONotExists,
|
||||
retrieveWBOExists,
|
||||
@ -268,12 +270,12 @@ add_test(function test_x_weave_records() {
|
||||
crypto: {foos: {foo: "bar"},
|
||||
bars: {foo: "baz"}}
|
||||
});
|
||||
server.start(null, function () {
|
||||
let wbo = localRequest(server, "/1.1/john/storage/crypto/foos");
|
||||
server.start(8080, function () {
|
||||
let wbo = localRequest("/1.1/john/storage/crypto/foos");
|
||||
wbo.get(function (err) {
|
||||
// WBO fetches don't have one.
|
||||
do_check_false("x-weave-records" in this.response.headers);
|
||||
let col = localRequest(server, "/1.1/john/storage/crypto");
|
||||
let col = localRequest("/1.1/john/storage/crypto");
|
||||
col.get(function (err) {
|
||||
// Collection fetches do.
|
||||
do_check_eq(this.response.headers["x-weave-records"], "2");
|
||||
|
@ -35,10 +35,10 @@ function sync_httpd_setup() {
|
||||
});
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
function setUp() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
@ -65,7 +65,7 @@ add_test(function test_successful_sync_adjustSyncInterval() {
|
||||
Svc.Obs.add("weave:service:sync:finish", onSyncFinish);
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Confirm defaults
|
||||
do_check_false(scheduler.idle);
|
||||
@ -169,7 +169,7 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Confirm defaults
|
||||
do_check_false(scheduler.idle);
|
||||
@ -261,7 +261,7 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
|
||||
add_test(function test_back_triggers_sync() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Single device: no sync triggered.
|
||||
scheduler.idle = true;
|
||||
@ -291,7 +291,7 @@ add_test(function test_back_triggers_sync() {
|
||||
|
||||
add_test(function test_adjust_interval_on_sync_error() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
let syncFailures = 0;
|
||||
function onSyncError() {
|
||||
@ -327,7 +327,7 @@ add_test(function test_bug671378_scenario() {
|
||||
// setting nextSync to a non-zero value and preventing the timer from
|
||||
// being adjusted in the next call to scheduleNextSync().
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
let syncSuccesses = 0;
|
||||
function onSyncFinish() {
|
||||
|
@ -169,9 +169,7 @@ const DATA = {"msg": "eggstreamly sekrit"};
|
||||
const POLLINTERVAL = 50;
|
||||
|
||||
function run_test() {
|
||||
server = httpd_setup({"/new_channel": server_new_channel,
|
||||
"/report": server_report});
|
||||
Svc.Prefs.set("jpake.serverURL", server.baseURI + "/");
|
||||
Svc.Prefs.set("jpake.serverURL", TEST_SERVER_URL);
|
||||
Svc.Prefs.set("jpake.pollInterval", POLLINTERVAL);
|
||||
Svc.Prefs.set("jpake.maxTries", 2);
|
||||
Svc.Prefs.set("jpake.firstMsgMaxTries", 5);
|
||||
@ -188,6 +186,9 @@ function run_test() {
|
||||
// sure the J-PAKE requests don't include those data.
|
||||
setBasicCredentials("johndoe", "ilovejane");
|
||||
|
||||
server = httpd_setup({"/new_channel": server_new_channel,
|
||||
"/report": server_report});
|
||||
|
||||
initTestLogging("Trace");
|
||||
Log4Moz.repository.getLogger("Sync.JPAKEClient").level = Log4Moz.Level.Trace;
|
||||
Log4Moz.repository.getLogger("Common.RESTRequest").level =
|
||||
|
@ -59,8 +59,8 @@ function handleReassign(handler, req, resp) {
|
||||
/**
|
||||
* A node assignment handler.
|
||||
*/
|
||||
const newNodeBody = "http://localhost:8080/";
|
||||
function installNodeHandler(server, next) {
|
||||
let newNodeBody = server.baseURI;
|
||||
function handleNodeRequest(req, resp) {
|
||||
_("Client made a request for a node reassignment.");
|
||||
resp.setStatusLine(req.httpVersion, 200, "OK");
|
||||
@ -75,13 +75,13 @@ function installNodeHandler(server, next) {
|
||||
|
||||
function prepareServer() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
do_check_eq(Service.userAPIURI, "http://localhost:8080/user/1.0/");
|
||||
let server = new SyncServer();
|
||||
server.registerUser("johndoe");
|
||||
server.start();
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.clusterURL = server.baseURI;
|
||||
do_check_eq(Service.userAPIURI, server.baseURI + "user/1.0/");
|
||||
return server;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ function test_fetch() {
|
||||
try {
|
||||
_("Fetching a WBO record");
|
||||
let rec = new WBORecord("coll", "record");
|
||||
rec.fetch(Service.resource(server.baseURI + "/record"));
|
||||
rec.fetch(Service.resource("http://localhost:8080/record"));
|
||||
do_check_eq(rec.id, "asdf-1234-asdf-1234"); // NOT "record"!
|
||||
|
||||
do_check_eq(rec.modified, 2454725.98283);
|
||||
@ -59,7 +59,7 @@ function test_fetch() {
|
||||
do_check_eq(rec.payload.cheese, "roquefort");
|
||||
|
||||
_("Fetching a WBO record using the record manager");
|
||||
let rec2 = Service.recordManager.get(server.baseURI + "/record2");
|
||||
let rec2 = Service.recordManager.get("http://localhost:8080/record2");
|
||||
do_check_eq(rec2.id, "record2");
|
||||
do_check_eq(rec2.modified, 2454725.98284);
|
||||
do_check_eq(typeof(rec2.payload), "object");
|
||||
|
@ -176,9 +176,9 @@ function run_test() {
|
||||
// This apparently has to come first in order for our PAC URL to be hit.
|
||||
// Don't put any other HTTP requests earlier in the file!
|
||||
_("Testing handling of proxy auth redirection.");
|
||||
PACSystemSettings.PACURI = server.baseURI + "/pac1";
|
||||
PACSystemSettings.PACURI = "http://localhost:8080/pac1";
|
||||
installFakePAC();
|
||||
let proxiedRes = new Resource(server.baseURI + "/open");
|
||||
let proxiedRes = new Resource("http://localhost:8080/open");
|
||||
let content = proxiedRes.get();
|
||||
do_check_true(pacFetched);
|
||||
do_check_true(fetched);
|
||||
@ -187,10 +187,10 @@ function run_test() {
|
||||
uninstallFakePAC();
|
||||
|
||||
_("Resource object members");
|
||||
let res = new Resource(server.baseURI + "/open");
|
||||
let res = new Resource("http://localhost:8080/open");
|
||||
do_check_true(res.uri instanceof Ci.nsIURI);
|
||||
do_check_eq(res.uri.spec, server.baseURI + "/open");
|
||||
do_check_eq(res.spec, server.baseURI + "/open");
|
||||
do_check_eq(res.uri.spec, "http://localhost:8080/open");
|
||||
do_check_eq(res.spec, "http://localhost:8080/open");
|
||||
do_check_eq(typeof res.headers, "object");
|
||||
do_check_eq(typeof res.authenticator, "object");
|
||||
// Initially res.data is null since we haven't performed a GET or
|
||||
@ -230,19 +230,19 @@ function run_test() {
|
||||
logger.debug = dbg;
|
||||
|
||||
_("Test that the BasicAuthenticator doesn't screw up header case.");
|
||||
let res1 = new Resource(server.baseURI + "/foo");
|
||||
let res1 = new Resource("http://localhost:8080/foo");
|
||||
res1.setHeader("Authorization", "Basic foobar");
|
||||
do_check_eq(res1.headers["authorization"], "Basic foobar");
|
||||
|
||||
_("GET a password protected resource (test that it'll fail w/o pass, no throw)");
|
||||
let res2 = new Resource(server.baseURI + "/protected");
|
||||
let res2 = new Resource("http://localhost:8080/protected");
|
||||
content = res2.get();
|
||||
do_check_eq(content, "This path exists and is protected - failed");
|
||||
do_check_eq(content.status, 401);
|
||||
do_check_false(content.success);
|
||||
|
||||
_("GET a password protected resource");
|
||||
let res3 = new Resource(server.baseURI + "/protected");
|
||||
let res3 = new Resource("http://localhost:8080/protected");
|
||||
let identity = new IdentityManager();
|
||||
let auth = identity.getBasicResourceAuthenticator("guest", "guest");
|
||||
res3.authenticator = auth;
|
||||
@ -253,7 +253,7 @@ function run_test() {
|
||||
do_check_true(content.success);
|
||||
|
||||
_("GET a non-existent resource (test that it'll fail, but not throw)");
|
||||
let res4 = new Resource(server.baseURI + "/404");
|
||||
let res4 = new Resource("http://localhost:8080/404");
|
||||
content = res4.get();
|
||||
do_check_eq(content, "File not found");
|
||||
do_check_eq(content.status, 404);
|
||||
@ -265,7 +265,7 @@ function run_test() {
|
||||
do_check_eq(content.headers["content-length"], 14);
|
||||
|
||||
_("PUT to a resource (string)");
|
||||
let res5 = new Resource(server.baseURI + "/upload");
|
||||
let res5 = new Resource("http://localhost:8080/upload");
|
||||
content = res5.put(JSON.stringify(sample_data));
|
||||
do_check_eq(content, "Valid data upload via PUT");
|
||||
do_check_eq(content.status, 200);
|
||||
@ -318,13 +318,13 @@ function run_test() {
|
||||
do_check_eq(res5.data, content);
|
||||
|
||||
_("DELETE a resource");
|
||||
let res6 = new Resource(server.baseURI + "/delete");
|
||||
let res6 = new Resource("http://localhost:8080/delete");
|
||||
content = res6.delete();
|
||||
do_check_eq(content, "This resource has been deleted")
|
||||
do_check_eq(content.status, 200);
|
||||
|
||||
_("JSON conversion of response body");
|
||||
let res7 = new Resource(server.baseURI + "/json");
|
||||
let res7 = new Resource("http://localhost:8080/json");
|
||||
content = res7.get();
|
||||
do_check_eq(content, JSON.stringify(sample_data));
|
||||
do_check_eq(content.status, 200);
|
||||
@ -334,12 +334,12 @@ function run_test() {
|
||||
// Before having received any response containing the
|
||||
// X-Weave-Timestamp header, AsyncResource.serverTime is null.
|
||||
do_check_eq(AsyncResource.serverTime, null);
|
||||
let res8 = new Resource(server.baseURI + "/timestamp");
|
||||
let res8 = new Resource("http://localhost:8080/timestamp");
|
||||
content = res8.get();
|
||||
do_check_eq(AsyncResource.serverTime, TIMESTAMP);
|
||||
|
||||
_("GET: no special request headers");
|
||||
let res9 = new Resource(server.baseURI + "/headers");
|
||||
let res9 = new Resource("http://localhost:8080/headers");
|
||||
content = res9.get();
|
||||
do_check_eq(content, '{}');
|
||||
|
||||
@ -387,7 +387,7 @@ function run_test() {
|
||||
}
|
||||
Observers.add("weave:service:backoff:interval", onBackoff);
|
||||
|
||||
let res10 = new Resource(server.baseURI + "/backoff");
|
||||
let res10 = new Resource("http://localhost:8080/backoff");
|
||||
content = res10.get();
|
||||
do_check_eq(backoffInterval, 600);
|
||||
|
||||
@ -399,12 +399,12 @@ function run_test() {
|
||||
}
|
||||
Observers.add("weave:service:quota:remaining", onQuota);
|
||||
|
||||
res10 = new Resource(server.baseURI + "/quota-error");
|
||||
res10 = new Resource("http://localhost:8080/quota-error");
|
||||
content = res10.get();
|
||||
do_check_eq(content.status, 400);
|
||||
do_check_eq(quotaValue, undefined); // HTTP 400, so no observer notification.
|
||||
|
||||
res10 = new Resource(server.baseURI + "/quota-notice");
|
||||
res10 = new Resource("http://localhost:8080/quota-notice");
|
||||
content = res10.get();
|
||||
do_check_eq(content.status, 200);
|
||||
do_check_eq(quotaValue, 1048576);
|
||||
@ -423,7 +423,7 @@ function run_test() {
|
||||
do_check_eq(typeof error.stack, "string");
|
||||
|
||||
_("Checking handling of errors in onProgress.");
|
||||
let res18 = new Resource(server.baseURI + "/json");
|
||||
let res18 = new Resource("http://localhost:8080/json");
|
||||
let onProgress = function(rec) {
|
||||
// Provoke an XPC exception without a Javascript wrapper.
|
||||
Services.io.newURI("::::::::", null, null);
|
||||
@ -444,10 +444,10 @@ function run_test() {
|
||||
do_check_eq(error, "Error: NS_ERROR_MALFORMED_URI");
|
||||
do_check_eq(warnings.pop(),
|
||||
"Got exception calling onProgress handler during fetch of " +
|
||||
server.baseURI + "/json");
|
||||
"http://localhost:8080/json");
|
||||
|
||||
// And this is what happens if JS throws an exception.
|
||||
res18 = new Resource(server.baseURI + "/json");
|
||||
res18 = new Resource("http://localhost:8080/json");
|
||||
onProgress = function(rec) {
|
||||
throw "BOO!";
|
||||
};
|
||||
@ -467,11 +467,11 @@ function run_test() {
|
||||
do_check_eq(error, "Error: NS_ERROR_XPC_JS_THREW_STRING");
|
||||
do_check_eq(warnings.pop(),
|
||||
"Got exception calling onProgress handler during fetch of " +
|
||||
server.baseURI + "/json");
|
||||
"http://localhost:8080/json");
|
||||
|
||||
|
||||
_("Ensure channel timeouts are thrown appropriately.");
|
||||
let res19 = new Resource(server.baseURI + "/json");
|
||||
let res19 = new Resource("http://localhost:8080/json");
|
||||
res19.ABORT_TIMEOUT = 0;
|
||||
error = undefined;
|
||||
try {
|
||||
|
@ -7,6 +7,9 @@ Cu.import("resource://services-sync/identity.js");
|
||||
Cu.import("resource://services-sync/resource.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
const RES_UPLOAD_URL = "http://localhost:8080/upload";
|
||||
const RES_HEADERS_URL = "http://localhost:8080/headers";
|
||||
|
||||
let logger;
|
||||
|
||||
let fetched = false;
|
||||
@ -170,9 +173,9 @@ add_test(function test_proxy_auth_redirect() {
|
||||
"/pac2": server_pac
|
||||
});
|
||||
|
||||
PACSystemSettings.PACURI = server.baseURI + "/pac2";
|
||||
PACSystemSettings.PACURI = "http://localhost:8080/pac2";
|
||||
installFakePAC();
|
||||
let res = new AsyncResource(server.baseURI + "/open");
|
||||
let res = new AsyncResource("http://localhost:8080/open");
|
||||
res.get(function (error, result) {
|
||||
do_check_true(!error);
|
||||
do_check_true(pacFetched);
|
||||
@ -196,19 +199,18 @@ add_test(function test_new_channel() {
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
let locationURL;
|
||||
function redirectHandler(metadata, response) {
|
||||
let body = "Redirecting";
|
||||
response.setStatusLine(metadata.httpVersion, 307, "TEMPORARY REDIRECT");
|
||||
response.setHeader("Location", locationURL);
|
||||
response.setHeader("Location", "http://localhost:8080/resource");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
let server = httpd_setup({"/resource": resourceHandler,
|
||||
"/redirect": redirectHandler});
|
||||
locationURL = server.baseURI + "/resource";
|
||||
"/redirect": redirectHandler},
|
||||
8080);
|
||||
|
||||
let request = new AsyncResource(server.baseURI + "/redirect");
|
||||
let request = new AsyncResource("http://localhost:8080/redirect");
|
||||
request.get(function onRequest(error, content) {
|
||||
do_check_null(error);
|
||||
do_check_true(resourceRequested);
|
||||
@ -244,11 +246,10 @@ add_test(function setup() {
|
||||
|
||||
add_test(function test_members() {
|
||||
_("Resource object members");
|
||||
let uri = server.baseURI + "/open";
|
||||
let res = new AsyncResource(uri);
|
||||
let res = new AsyncResource("http://localhost:8080/open");
|
||||
do_check_true(res.uri instanceof Ci.nsIURI);
|
||||
do_check_eq(res.uri.spec, uri);
|
||||
do_check_eq(res.spec, uri);
|
||||
do_check_eq(res.uri.spec, "http://localhost:8080/open");
|
||||
do_check_eq(res.spec, "http://localhost:8080/open");
|
||||
do_check_eq(typeof res.headers, "object");
|
||||
do_check_eq(typeof res.authenticator, "object");
|
||||
// Initially res.data is null since we haven't performed a GET or
|
||||
@ -260,7 +261,7 @@ add_test(function test_members() {
|
||||
|
||||
add_test(function test_get() {
|
||||
_("GET a non-password-protected resource");
|
||||
let res = new AsyncResource(server.baseURI + "/open");
|
||||
let res = new AsyncResource("http://localhost:8080/open");
|
||||
res.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "This path exists");
|
||||
@ -298,7 +299,7 @@ add_test(function test_get() {
|
||||
|
||||
add_test(function test_basicauth() {
|
||||
_("Test that the BasicAuthenticator doesn't screw up header case.");
|
||||
let res1 = new AsyncResource(server.baseURI + "/foo");
|
||||
let res1 = new AsyncResource("http://localhost:8080/foo");
|
||||
res1.setHeader("Authorization", "Basic foobar");
|
||||
do_check_eq(res1._headers["authorization"], "Basic foobar");
|
||||
do_check_eq(res1.headers["authorization"], "Basic foobar");
|
||||
@ -308,7 +309,7 @@ add_test(function test_basicauth() {
|
||||
|
||||
add_test(function test_get_protected_fail() {
|
||||
_("GET a password protected resource (test that it'll fail w/o pass, no throw)");
|
||||
let res2 = new AsyncResource(server.baseURI + "/protected");
|
||||
let res2 = new AsyncResource("http://localhost:8080/protected");
|
||||
res2.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "This path exists and is protected - failed");
|
||||
@ -322,7 +323,7 @@ add_test(function test_get_protected_success() {
|
||||
_("GET a password protected resource");
|
||||
let identity = new IdentityManager();
|
||||
let auth = identity.getBasicResourceAuthenticator("guest", "guest");
|
||||
let res3 = new AsyncResource(server.baseURI + "/protected");
|
||||
let res3 = new AsyncResource("http://localhost:8080/protected");
|
||||
res3.authenticator = auth;
|
||||
do_check_eq(res3.authenticator, auth);
|
||||
res3.get(function (error, content) {
|
||||
@ -336,7 +337,7 @@ add_test(function test_get_protected_success() {
|
||||
|
||||
add_test(function test_get_404() {
|
||||
_("GET a non-existent resource (test that it'll fail, but not throw)");
|
||||
let res4 = new AsyncResource(server.baseURI + "/404");
|
||||
let res4 = new AsyncResource("http://localhost:8080/404");
|
||||
res4.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "File not found");
|
||||
@ -354,7 +355,7 @@ add_test(function test_get_404() {
|
||||
|
||||
add_test(function test_put_string() {
|
||||
_("PUT to a resource (string)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.put(JSON.stringify(sample_data), function(error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "Valid data upload via PUT");
|
||||
@ -366,7 +367,7 @@ add_test(function test_put_string() {
|
||||
|
||||
add_test(function test_put_object() {
|
||||
_("PUT to a resource (object)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.put(sample_data, function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "Valid data upload via PUT");
|
||||
@ -378,7 +379,7 @@ add_test(function test_put_object() {
|
||||
|
||||
add_test(function test_put_data_string() {
|
||||
_("PUT without data arg (uses resource.data) (string)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.data = JSON.stringify(sample_data);
|
||||
res_upload.put(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -391,7 +392,7 @@ add_test(function test_put_data_string() {
|
||||
|
||||
add_test(function test_put_data_object() {
|
||||
_("PUT without data arg (uses resource.data) (object)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.data = sample_data;
|
||||
res_upload.put(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -404,7 +405,7 @@ add_test(function test_put_data_object() {
|
||||
|
||||
add_test(function test_post_string() {
|
||||
_("POST to a resource (string)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.post(JSON.stringify(sample_data), function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "Valid data upload via POST");
|
||||
@ -416,7 +417,7 @@ add_test(function test_post_string() {
|
||||
|
||||
add_test(function test_post_object() {
|
||||
_("POST to a resource (object)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.post(sample_data, function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "Valid data upload via POST");
|
||||
@ -428,7 +429,7 @@ add_test(function test_post_object() {
|
||||
|
||||
add_test(function test_post_data_string() {
|
||||
_("POST without data arg (uses resource.data) (string)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.data = JSON.stringify(sample_data);
|
||||
res_upload.post(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -441,7 +442,7 @@ add_test(function test_post_data_string() {
|
||||
|
||||
add_test(function test_post_data_object() {
|
||||
_("POST without data arg (uses resource.data) (object)");
|
||||
let res_upload = new AsyncResource(server.baseURI + "/upload");
|
||||
let res_upload = new AsyncResource(RES_UPLOAD_URL);
|
||||
res_upload.data = sample_data;
|
||||
res_upload.post(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -454,7 +455,7 @@ add_test(function test_post_data_object() {
|
||||
|
||||
add_test(function test_delete() {
|
||||
_("DELETE a resource");
|
||||
let res6 = new AsyncResource(server.baseURI + "/delete");
|
||||
let res6 = new AsyncResource("http://localhost:8080/delete");
|
||||
res6.delete(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, "This resource has been deleted");
|
||||
@ -465,7 +466,7 @@ add_test(function test_delete() {
|
||||
|
||||
add_test(function test_json_body() {
|
||||
_("JSON conversion of response body");
|
||||
let res7 = new AsyncResource(server.baseURI + "/json");
|
||||
let res7 = new AsyncResource("http://localhost:8080/json");
|
||||
res7.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, JSON.stringify(sample_data));
|
||||
@ -480,7 +481,7 @@ add_test(function test_weave_timestamp() {
|
||||
// Before having received any response containing the
|
||||
// X-Weave-Timestamp header, AsyncResource.serverTime is null.
|
||||
do_check_eq(AsyncResource.serverTime, null);
|
||||
let res8 = new AsyncResource(server.baseURI + "/timestamp");
|
||||
let res8 = new AsyncResource("http://localhost:8080/timestamp");
|
||||
res8.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(AsyncResource.serverTime, TIMESTAMP);
|
||||
@ -490,7 +491,7 @@ add_test(function test_weave_timestamp() {
|
||||
|
||||
add_test(function test_get_no_headers() {
|
||||
_("GET: no special request headers");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, '{}');
|
||||
@ -500,7 +501,7 @@ add_test(function test_get_no_headers() {
|
||||
|
||||
add_test(function test_put_default_content_type() {
|
||||
_("PUT: Content-Type defaults to text/plain");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.put('data', function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, JSON.stringify({"content-type": "text/plain"}));
|
||||
@ -510,7 +511,7 @@ add_test(function test_put_default_content_type() {
|
||||
|
||||
add_test(function test_post_default_content_type() {
|
||||
_("POST: Content-Type defaults to text/plain");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.post('data', function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content, JSON.stringify({"content-type": "text/plain"}));
|
||||
@ -520,7 +521,7 @@ add_test(function test_post_default_content_type() {
|
||||
|
||||
add_test(function test_setHeader() {
|
||||
_("setHeader(): setting simple header");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.setHeader('X-What-Is-Weave', 'awesome');
|
||||
do_check_eq(res_headers.headers['x-what-is-weave'], 'awesome');
|
||||
res_headers.get(function (error, content) {
|
||||
@ -532,7 +533,7 @@ add_test(function test_setHeader() {
|
||||
|
||||
add_test(function test_setHeader_overwrite() {
|
||||
_("setHeader(): setting multiple headers, overwriting existing header");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.setHeader('X-WHAT-is-Weave', 'more awesomer');
|
||||
res_headers.setHeader('X-Another-Header', 'hello world');
|
||||
do_check_eq(res_headers.headers['x-what-is-weave'], 'more awesomer');
|
||||
@ -548,7 +549,7 @@ add_test(function test_setHeader_overwrite() {
|
||||
|
||||
add_test(function test_headers_object() {
|
||||
_("Setting headers object");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.headers = {};
|
||||
res_headers.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -559,7 +560,7 @@ add_test(function test_headers_object() {
|
||||
|
||||
add_test(function test_put_override_content_type() {
|
||||
_("PUT: override default Content-Type");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.setHeader('Content-Type', 'application/foobar');
|
||||
do_check_eq(res_headers.headers['content-type'], 'application/foobar');
|
||||
res_headers.put('data', function (error, content) {
|
||||
@ -571,7 +572,7 @@ add_test(function test_put_override_content_type() {
|
||||
|
||||
add_test(function test_post_override_content_type() {
|
||||
_("POST: override default Content-Type");
|
||||
let res_headers = new AsyncResource(server.baseURI + "/headers");
|
||||
let res_headers = new AsyncResource(RES_HEADERS_URL);
|
||||
res_headers.setHeader('Content-Type', 'application/foobar');
|
||||
res_headers.post('data', function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
@ -588,7 +589,7 @@ add_test(function test_weave_backoff() {
|
||||
}
|
||||
Observers.add("weave:service:backoff:interval", onBackoff);
|
||||
|
||||
let res10 = new AsyncResource(server.baseURI + "/backoff");
|
||||
let res10 = new AsyncResource("http://localhost:8080/backoff");
|
||||
res10.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(backoffInterval, 600);
|
||||
@ -598,7 +599,7 @@ add_test(function test_weave_backoff() {
|
||||
|
||||
add_test(function test_quota_error() {
|
||||
_("X-Weave-Quota-Remaining header notifies observer on successful requests.");
|
||||
let res10 = new AsyncResource(server.baseURI + "/quota-error");
|
||||
let res10 = new AsyncResource("http://localhost:8080/quota-error");
|
||||
res10.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content.status, 400);
|
||||
@ -608,7 +609,7 @@ add_test(function test_quota_error() {
|
||||
});
|
||||
|
||||
add_test(function test_quota_notice() {
|
||||
let res10 = new AsyncResource(server.baseURI + "/quota-notice");
|
||||
let res10 = new AsyncResource("http://localhost:8080/quota-notice");
|
||||
res10.get(function (error, content) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(content.status, 200);
|
||||
@ -630,7 +631,7 @@ add_test(function test_preserve_exceptions() {
|
||||
|
||||
add_test(function test_xpc_exception_handling() {
|
||||
_("Exception handling inside fetches.");
|
||||
let res14 = new AsyncResource(server.baseURI + "/json");
|
||||
let res14 = new AsyncResource("http://localhost:8080/json");
|
||||
res14._onProgress = function(rec) {
|
||||
// Provoke an XPC exception without a Javascript wrapper.
|
||||
Services.io.newURI("::::::::", null, null);
|
||||
@ -644,7 +645,7 @@ add_test(function test_xpc_exception_handling() {
|
||||
do_check_eq(content, null);
|
||||
do_check_eq(warnings.pop(),
|
||||
"Got exception calling onProgress handler during fetch of " +
|
||||
server.baseURI + "/json");
|
||||
"http://localhost:8080/json");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
@ -652,7 +653,7 @@ add_test(function test_xpc_exception_handling() {
|
||||
|
||||
add_test(function test_js_exception_handling() {
|
||||
_("JS exception handling inside fetches.");
|
||||
let res15 = new AsyncResource(server.baseURI + "/json");
|
||||
let res15 = new AsyncResource("http://localhost:8080/json");
|
||||
res15._onProgress = function(rec) {
|
||||
throw "BOO!";
|
||||
};
|
||||
@ -665,7 +666,7 @@ add_test(function test_js_exception_handling() {
|
||||
do_check_eq(content, null);
|
||||
do_check_eq(warnings.pop(),
|
||||
"Got exception calling onProgress handler during fetch of " +
|
||||
server.baseURI + "/json");
|
||||
"http://localhost:8080/json");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
@ -673,7 +674,7 @@ add_test(function test_js_exception_handling() {
|
||||
|
||||
add_test(function test_timeout() {
|
||||
_("Ensure channel timeouts are thrown appropriately.");
|
||||
let res19 = new AsyncResource(server.baseURI + "/json");
|
||||
let res19 = new AsyncResource("http://localhost:8080/json");
|
||||
res19.ABORT_TIMEOUT = 0;
|
||||
res19.get(function (error, content) {
|
||||
do_check_eq(error.result, Cr.NS_ERROR_NET_TIMEOUT);
|
||||
@ -709,10 +710,10 @@ add_test(function test_not_sending_cookie() {
|
||||
}
|
||||
let cookieSer = Cc["@mozilla.org/cookieService;1"]
|
||||
.getService(Ci.nsICookieService);
|
||||
let uri = CommonUtils.makeURI(server.baseURI);
|
||||
let uri = CommonUtils.makeURI("http://localhost:8080");
|
||||
cookieSer.setCookieString(uri, null, "test=test; path=/;", null);
|
||||
|
||||
let res = new AsyncResource(server.baseURI + "/test");
|
||||
let res = new AsyncResource("http://localhost:8080/test");
|
||||
res.get(function (error) {
|
||||
do_check_null(error);
|
||||
do_check_true(this.response.success);
|
||||
|
@ -7,6 +7,8 @@ Cu.import("resource://services-sync/service.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
const TEST_GET_URL = "http://localhost:8080/1.1/johndoe/storage/meta/global";
|
||||
|
||||
// Tracking info/collections.
|
||||
let collectionsHelper = track_collections_helper();
|
||||
let collections = collectionsHelper.collections;
|
||||
@ -24,7 +26,6 @@ function uaHandler(f) {
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
|
||||
meta_global = new ServerWBO('global');
|
||||
server = httpd_setup({
|
||||
"/1.1/johndoe/info/collections": uaHandler(collectionsHelper.handler),
|
||||
@ -32,9 +33,8 @@ function run_test() {
|
||||
});
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane");
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
_("Server URL: " + server.baseURI);
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
expectedUA = Services.appinfo.name + "/" + Services.appinfo.version +
|
||||
" FxSync/" + WEAVE_VERSION + "." +
|
||||
@ -54,7 +54,7 @@ add_test(function test_fetchInfo() {
|
||||
|
||||
add_test(function test_desktop_post() {
|
||||
_("Testing direct Resource POST.");
|
||||
let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global");
|
||||
let r = new AsyncResource(TEST_GET_URL);
|
||||
r.post("foo=bar", function (error, content) {
|
||||
_("User-Agent: " + ua);
|
||||
do_check_eq(ua, expectedUA + ".desktop");
|
||||
@ -66,7 +66,7 @@ add_test(function test_desktop_post() {
|
||||
add_test(function test_desktop_get() {
|
||||
_("Testing async.");
|
||||
Svc.Prefs.set("client.type", "desktop");
|
||||
let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global");
|
||||
let r = new AsyncResource(TEST_GET_URL);
|
||||
r.get(function(error, content) {
|
||||
_("User-Agent: " + ua);
|
||||
do_check_eq(ua, expectedUA + ".desktop");
|
||||
@ -78,7 +78,7 @@ add_test(function test_desktop_get() {
|
||||
add_test(function test_mobile_get() {
|
||||
_("Testing mobile.");
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
let r = new AsyncResource(server.baseURI + "/1.1/johndoe/storage/meta/global");
|
||||
let r = new AsyncResource(TEST_GET_URL);
|
||||
r.get(function (error, content) {
|
||||
_("User-Agent: " + ua);
|
||||
do_check_eq(ua, expectedUA + ".mobile");
|
||||
|
@ -43,8 +43,8 @@ function sync_httpd_setup() {
|
||||
return httpd_setup(handlers);
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
new SyncTestingInfrastructure(server, "johndoe", "ilovejane", "sekrit");
|
||||
function setUp() {
|
||||
new SyncTestingInfrastructure("johndoe", "ilovejane", "sekrit");
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
@ -80,7 +80,7 @@ add_test(function test_tracker_score_updated() {
|
||||
|
||||
add_test(function test_sync_triggered() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
Service.login();
|
||||
|
||||
@ -103,7 +103,7 @@ add_test(function test_clients_engine_sync_triggered() {
|
||||
// global score tracker gives it that treatment. See bug 676042 for more.
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
Service.login();
|
||||
|
||||
const TOPIC = "weave:service:sync:finish";
|
||||
@ -121,7 +121,7 @@ add_test(function test_clients_engine_sync_triggered() {
|
||||
add_test(function test_incorrect_credentials_sync_not_triggered() {
|
||||
_("Ensure that score changes don't trigger a sync if Status.login != LOGIN_SUCCEEDED.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Ensure we don't actually try to sync.
|
||||
function onSyncStart() {
|
||||
|
@ -29,7 +29,8 @@ add_test(function test_change_password() {
|
||||
}
|
||||
|
||||
try {
|
||||
Service.baseURI = "http://localhost:9999/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
setBasicCredentials("johndoe", "ilovejane");
|
||||
|
||||
_("changePassword() returns false for a network error, the password won't change.");
|
||||
@ -43,7 +44,6 @@ add_test(function test_change_password() {
|
||||
"/user/1.0/janedoe/password": send(401, "Unauthorized", "Forbidden!")
|
||||
});
|
||||
|
||||
Service.serverURL = server.baseURI;
|
||||
res = Service.changePassword("ILoveJane83");
|
||||
do_check_true(res);
|
||||
do_check_eq(Service.identity.basicPassword, "ILoveJane83");
|
||||
|
@ -16,7 +16,7 @@ function run_test() {
|
||||
"/user/1.0/vuuf3eqgloxpxmzph27f5a6ve7gzlrms": httpd_handler(200, "OK", "1")
|
||||
});
|
||||
try {
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
|
||||
_("A 404 will be recorded as 'generic-server-error'");
|
||||
do_check_eq(Service.checkAccount("jimdoe"), "generic-server-error");
|
||||
|
@ -19,10 +19,11 @@ add_test(function test_findCluster() {
|
||||
_("Test Service._findCluster()");
|
||||
let server;
|
||||
try {
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.identity.account = "johndoe";
|
||||
|
||||
_("_findCluster() throws on network errors (e.g. connection refused).");
|
||||
do_check_throws(function() {
|
||||
Service.serverURL = "http://dummy:9000/";
|
||||
Service.identify.account = "johndoe";
|
||||
Service._clusterManager._findCluster();
|
||||
});
|
||||
|
||||
@ -34,9 +35,6 @@ add_test(function test_findCluster() {
|
||||
"/user/1.0/joedoe/node/weave": httpd_handler(500, "Server Error", "Server Error")
|
||||
});
|
||||
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.identity.account = "johndoe";
|
||||
|
||||
_("_findCluster() returns the user's cluster node");
|
||||
let cluster = Service._clusterManager._findCluster();
|
||||
do_check_eq(cluster, "http://weave.user.node/");
|
||||
@ -78,7 +76,7 @@ add_test(function test_setCluster() {
|
||||
"/user/1.0/jimdoe/node/weave": httpd_handler(200, "OK", "null")
|
||||
});
|
||||
try {
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.identity.account = "johndoe";
|
||||
|
||||
_("Check initial state.");
|
||||
|
@ -32,7 +32,7 @@ function run_test() {
|
||||
"/user/1.0/vz6fhecgw5t3sgx3a4cektoiokyczkqd": send(500, "Server Error", "Server Error")
|
||||
});
|
||||
try {
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
|
||||
_("Create an account.");
|
||||
let res = Service.createAccount("john@doe.com", "mysecretpw",
|
||||
|
@ -66,7 +66,8 @@ add_test(function v4_upgrade() {
|
||||
Service.status.resetSync();
|
||||
|
||||
_("Logging in.");
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Service.login("johndoe", "ilovejane", passphrase);
|
||||
do_check_true(Service.isLoggedIn);
|
||||
@ -101,7 +102,8 @@ add_test(function v4_upgrade() {
|
||||
_("Syncing afresh...");
|
||||
Service.logout();
|
||||
Service.collectionKeys.clear();
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
meta_global.payload = JSON.stringify({"syncID": "foooooooooooooobbbbbbbbbbbb",
|
||||
"storageVersion": STORAGE_VERSION});
|
||||
collections.meta = Date.now() / 1000;
|
||||
@ -237,8 +239,8 @@ add_test(function v5_upgrade() {
|
||||
Service.status.resetSync();
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane", passphrase);
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
// Test an upgrade where the contents of the server would cause us to error
|
||||
// -- keys decrypted with a different sync key, for example.
|
||||
|
@ -12,20 +12,20 @@ let collections = {steam: 65.11328,
|
||||
diesel: 2.25488281};
|
||||
|
||||
function run_test() {
|
||||
setBasicCredentials("johndoe", "ilovejane");
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Log4Moz.repository.getLogger("Sync.Service").level = Log4Moz.Level.Trace;
|
||||
Log4Moz.repository.getLogger("Sync.StorageRequest").level = Log4Moz.Level.Trace;
|
||||
initTestLogging();
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane");
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(function test_success() {
|
||||
let handler = httpd_handler(200, "OK", JSON.stringify(collections));
|
||||
let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
|
||||
let request = Service.getStorageInfo("collections", function (error, info) {
|
||||
do_check_eq(error, null);
|
||||
@ -65,8 +65,6 @@ add_test(function test_network_error() {
|
||||
add_test(function test_http_error() {
|
||||
let handler = httpd_handler(500, "Oh noez", "Something went wrong!");
|
||||
let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
|
||||
let request = Service.getStorageInfo(INFO_COLLECTIONS, function (error, info) {
|
||||
do_check_eq(error.status, 500);
|
||||
@ -78,8 +76,6 @@ add_test(function test_http_error() {
|
||||
add_test(function test_invalid_json() {
|
||||
let handler = httpd_handler(200, "OK", "Invalid JSON");
|
||||
let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
|
||||
let request = Service.getStorageInfo(INFO_COLLECTIONS, function (error, info) {
|
||||
do_check_eq(error.name, "SyntaxError");
|
||||
|
@ -43,6 +43,9 @@ add_test(function test_offline() {
|
||||
});
|
||||
|
||||
function setup() {
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
let janeHelper = track_collections_helper();
|
||||
let janeU = janeHelper.with_updated_collection;
|
||||
let janeColls = janeHelper.collections;
|
||||
@ -50,7 +53,7 @@ function setup() {
|
||||
let johnU = johnHelper.with_updated_collection;
|
||||
let johnColls = johnHelper.collections;
|
||||
|
||||
let server = httpd_setup({
|
||||
return httpd_setup({
|
||||
"/1.1/johndoe/info/collections": login_handling(johnHelper.handler),
|
||||
"/1.1/janedoe/info/collections": login_handling(janeHelper.handler),
|
||||
|
||||
@ -62,9 +65,6 @@ function setup() {
|
||||
"/1.1/janedoe/storage/crypto/keys": janeU("crypto", new ServerWBO("keys").handler()),
|
||||
"/1.1/janedoe/storage/meta/global": janeU("meta", new ServerWBO("global").handler())
|
||||
});
|
||||
|
||||
Service.serverURL = server.baseURI;
|
||||
return server;
|
||||
}
|
||||
|
||||
add_test(function test_login_logout() {
|
||||
|
@ -67,7 +67,7 @@ function run_test() {
|
||||
});
|
||||
|
||||
setBasicCredentials("johndoe", JAPANESE, "irrelevant");
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
|
||||
try {
|
||||
_("Try to log in with the password.");
|
||||
|
@ -73,8 +73,8 @@ add_test(function test_removeClientData() {
|
||||
Service.startOver();
|
||||
do_check_false(engine.removed);
|
||||
|
||||
Service.serverURL = "https://localhost/";
|
||||
Service.clusterURL = Service.serverURL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
do_check_false(engine.removed);
|
||||
Service.startOver();
|
||||
|
@ -13,6 +13,8 @@ function run_test() {
|
||||
_("When imported, Service.onStartup is called");
|
||||
initTestLogging("Trace");
|
||||
|
||||
new SyncTestingInfrastructure();
|
||||
|
||||
// Test fixtures
|
||||
Service.identity.username = "johndoe";
|
||||
|
||||
|
@ -38,7 +38,7 @@ function run_test() {
|
||||
|
||||
try {
|
||||
_("Set up test fixtures.");
|
||||
new SyncTestingInfrastructure(server, "johndoe", "ilovejane", "foo");
|
||||
new SyncTestingInfrastructure("johndoe", "ilovejane", "foo");
|
||||
Service.scheduler.globalScore = GLOBAL_SCORE;
|
||||
// Avoid daily ping
|
||||
Svc.Prefs.set("lastPing", Math.floor(Date.now() / 1000));
|
||||
|
@ -65,7 +65,8 @@ function run_test() {
|
||||
|
||||
try {
|
||||
_("Log in.");
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
_("Checking Status.sync with no credentials.");
|
||||
Service.verifyAndFetchSymmetricKeys();
|
||||
@ -80,7 +81,8 @@ function run_test() {
|
||||
let syncKey = Service.identity.syncKey;
|
||||
Service.startOver();
|
||||
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.login("johndoe", "ilovejane", syncKey);
|
||||
do_check_true(Service.isLoggedIn);
|
||||
|
||||
|
@ -66,8 +66,8 @@ function sync_httpd_setup(handlers) {
|
||||
return httpd_setup(handlers);
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
new SyncTestingInfrastructure(server, "johndoe", "ilovejane",
|
||||
function setUp() {
|
||||
new SyncTestingInfrastructure("johndoe", "ilovejane",
|
||||
"abcdeabcdeabcdeabcdeabcdea");
|
||||
// Ensure that the server has valid keys so that logging in will work and not
|
||||
// result in a server wipe, rendering many of these tests useless.
|
||||
@ -95,7 +95,7 @@ add_test(function test_newAccount() {
|
||||
"/1.1/johndoe/storage/meta/global": new ServerWBO("global", {}).handler(),
|
||||
"/1.1/johndoe/storage/steam": new ServerWBO("steam", {}).handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Engine is enabled from the beginning.");
|
||||
@ -125,7 +125,7 @@ add_test(function test_enabledLocally() {
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": new ServerWBO("steam", {}).handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Enable engine locally.");
|
||||
@ -161,7 +161,7 @@ add_test(function test_disabledLocally() {
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": steamCollection.handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Disable engine locally.");
|
||||
@ -210,7 +210,7 @@ add_test(function test_disabledLocally_wipe503() {
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": service_unavailable
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
_("Disable engine locally.");
|
||||
Service._ignorePrefObserver = true;
|
||||
@ -248,7 +248,7 @@ add_test(function test_enabledRemotely() {
|
||||
"/1.1/johndoe/storage/steam":
|
||||
upd("steam", new ServerWBO("steam", {}).handler())
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// We need to be very careful how we do this, so that we don't trigger a
|
||||
// fresh start!
|
||||
@ -289,7 +289,7 @@ add_test(function test_disabledRemotelyTwoClients() {
|
||||
"/1.1/johndoe/storage/steam":
|
||||
upd("steam", new ServerWBO("steam", {}).handler())
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Enable engine locally.");
|
||||
@ -330,7 +330,7 @@ add_test(function test_disabledRemotely() {
|
||||
"/1.1/johndoe/storage/meta/global": metaWBO.handler(),
|
||||
"/1.1/johndoe/storage/steam": new ServerWBO("steam", {}).handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Enable engine locally.");
|
||||
@ -363,7 +363,7 @@ add_test(function test_dependentEnginesEnabledLocally() {
|
||||
"/1.1/johndoe/storage/steam": new ServerWBO("steam", {}).handler(),
|
||||
"/1.1/johndoe/storage/stirling": new ServerWBO("stirling", {}).handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Enable engine locally. Doing it on one is enough.");
|
||||
@ -407,7 +407,7 @@ add_test(function test_dependentEnginesDisabledLocally() {
|
||||
"/1.1/johndoe/storage/steam": steamCollection.handler(),
|
||||
"/1.1/johndoe/storage/stirling": stirlingCollection.handler()
|
||||
});
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
try {
|
||||
_("Disable engines locally. Doing it on one is enough.");
|
||||
|
@ -37,25 +37,17 @@ function run_test() {
|
||||
let johnColls = johnHelper.collections;
|
||||
|
||||
do_test_pending();
|
||||
|
||||
let server;
|
||||
function weaveHandler (request, response) {
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
let body = server.baseURI + "/api/";
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
server = httpd_setup({
|
||||
let server = httpd_setup({
|
||||
"/api/1.1/johndoe/info/collections": login_handling(johnHelper.handler),
|
||||
"/api/1.1/janedoe/info/collections": service_unavailable,
|
||||
|
||||
"/api/1.1/johndoe/storage/crypto/keys": johnU("crypto", new ServerWBO("keys").handler()),
|
||||
"/api/1.1/johndoe/storage/meta/global": johnU("meta", new ServerWBO("global").handler()),
|
||||
"/user/1.0/johndoe/node/weave": weaveHandler,
|
||||
"/user/1.0/johndoe/node/weave": httpd_handler(200, "OK", "http://localhost:8080/api/")
|
||||
});
|
||||
|
||||
try {
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
|
||||
_("Force the initial state.");
|
||||
Service.status.service = STATUS_OK;
|
||||
@ -75,7 +67,7 @@ function run_test() {
|
||||
do_check_eq(Service.status.login, LOGIN_FAILED_NO_PASSPHRASE);
|
||||
|
||||
_("verifyLogin() has found out the user's cluster URL, though.");
|
||||
do_check_eq(Service.clusterURL, server.baseURI + "/api/");
|
||||
do_check_eq(Service.clusterURL, "http://localhost:8080/api/");
|
||||
|
||||
_("Success if passphrase is set.");
|
||||
Service.status.resetSync();
|
||||
|
@ -82,7 +82,7 @@ add_test(function test_credentials_preserved() {
|
||||
_("Ensure that credentials are preserved if client is wiped.");
|
||||
|
||||
// Required for wipeClient().
|
||||
Service.clusterURL = "http://dummy:9000/";
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.account = "testaccount";
|
||||
Service.identity.basicPassword = "testpassword";
|
||||
let key = Utils.generatePassphrase();
|
||||
|
@ -28,11 +28,11 @@ FakeCollection.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function setUpTestFixtures(server) {
|
||||
function setUpTestFixtures() {
|
||||
let cryptoService = new FakeCryptoService();
|
||||
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
setBasicCredentials("johndoe", null, "aabcdeabcdeabcdeabcdeabcde");
|
||||
}
|
||||
@ -56,8 +56,8 @@ add_test(function test_wipeServer_list_success() {
|
||||
});
|
||||
|
||||
try {
|
||||
setUpTestFixtures(server);
|
||||
new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
|
||||
setUpTestFixtures();
|
||||
new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
|
||||
|
||||
_("Confirm initial environment.");
|
||||
do_check_false(steam_coll.deleted);
|
||||
@ -90,8 +90,8 @@ add_test(function test_wipeServer_list_503() {
|
||||
});
|
||||
|
||||
try {
|
||||
setUpTestFixtures(server);
|
||||
new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
|
||||
setUpTestFixtures();
|
||||
new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
|
||||
|
||||
_("Confirm initial environment.");
|
||||
do_check_false(steam_coll.deleted);
|
||||
@ -136,10 +136,10 @@ add_test(function test_wipeServer_all_success() {
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler
|
||||
});
|
||||
setUpTestFixtures(server);
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
|
||||
new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
|
||||
let returnedTimestamp = Service.wipeServer();
|
||||
do_check_true(deleted);
|
||||
do_check_eq(returnedTimestamp, serverTimestamp);
|
||||
@ -168,10 +168,10 @@ add_test(function test_wipeServer_all_404() {
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler
|
||||
});
|
||||
setUpTestFixtures(server);
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
|
||||
new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
|
||||
let returnedTimestamp = Service.wipeServer();
|
||||
do_check_true(deleted);
|
||||
do_check_eq(returnedTimestamp, serverTimestamp);
|
||||
@ -195,12 +195,12 @@ add_test(function test_wipeServer_all_503() {
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/storage": storageHandler
|
||||
});
|
||||
setUpTestFixtures(server);
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
let error;
|
||||
try {
|
||||
new SyncTestingInfrastructure(server, "johndoe", "irrelevant", "irrelevant");
|
||||
new SyncTestingInfrastructure("johndoe", "irrelevant", "irrelevant");
|
||||
Service.wipeServer();
|
||||
do_throw("Should have thrown!");
|
||||
} catch (ex) {
|
||||
@ -214,11 +214,7 @@ add_test(function test_wipeServer_all_503() {
|
||||
|
||||
add_test(function test_wipeServer_all_connectionRefused() {
|
||||
_("Service.wipeServer() throws if it encounters a network problem.");
|
||||
let server = httpd_setup({});
|
||||
setUpTestFixtures(server);
|
||||
|
||||
Service.serverURL = "http://localhost:4352/";
|
||||
Service.clusterURL = "http://localhost:4352/";
|
||||
setUpTestFixtures();
|
||||
|
||||
_("Try deletion.");
|
||||
try {
|
||||
@ -228,6 +224,6 @@ add_test(function test_wipeServer_all_connectionRefused() {
|
||||
do_check_eq(ex.result, Cr.NS_ERROR_CONNECTION_REFUSED);
|
||||
}
|
||||
|
||||
run_next_test();
|
||||
Svc.Prefs.resetBranch("");
|
||||
server.stop(run_next_test);
|
||||
});
|
||||
|
@ -10,11 +10,9 @@ function makeSteamEngine() {
|
||||
return new SyncEngine('Steam', Service);
|
||||
}
|
||||
|
||||
let server;
|
||||
|
||||
function test_url_attributes() {
|
||||
_("SyncEngine url attributes");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.clusterURL = "https://cluster/";
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
@ -28,7 +26,7 @@ function test_url_attributes() {
|
||||
|
||||
function test_syncID() {
|
||||
_("SyncEngine.syncID corresponds to preference");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
// Ensure pristine environment
|
||||
@ -48,7 +46,7 @@ function test_syncID() {
|
||||
|
||||
function test_lastSync() {
|
||||
_("SyncEngine.lastSync and SyncEngine.lastSyncLocal correspond to preferences");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
// Ensure pristine environment
|
||||
@ -78,7 +76,7 @@ function test_lastSync() {
|
||||
|
||||
function test_toFetch() {
|
||||
_("SyncEngine.toFetch corresponds to file on disk");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
const filename = "weave/toFetch/steam.json";
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
@ -108,7 +106,7 @@ function test_toFetch() {
|
||||
|
||||
function test_previousFailed() {
|
||||
_("SyncEngine.previousFailed corresponds to file on disk");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
const filename = "weave/failed/steam.json";
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
@ -138,7 +136,7 @@ function test_previousFailed() {
|
||||
|
||||
function test_resetClient() {
|
||||
_("SyncEngine.resetClient resets lastSync and toFetch");
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
let engine = makeSteamEngine();
|
||||
try {
|
||||
// Ensure pristine environment
|
||||
@ -163,6 +161,9 @@ function test_resetClient() {
|
||||
|
||||
function test_wipeServer() {
|
||||
_("SyncEngine.wipeServer deletes server data and resets the client.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
let engine = makeSteamEngine();
|
||||
|
||||
const PAYLOAD = 42;
|
||||
@ -170,7 +171,6 @@ function test_wipeServer() {
|
||||
let server = httpd_setup({
|
||||
"/1.1/foo/storage/steam": steamCollection.handler()
|
||||
});
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
do_test_pending();
|
||||
|
||||
try {
|
||||
@ -191,7 +191,6 @@ function test_wipeServer() {
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
server = httpd_setup({});
|
||||
test_url_attributes();
|
||||
test_syncID();
|
||||
test_lastSync();
|
||||
@ -199,6 +198,4 @@ function run_test() {
|
||||
test_previousFailed();
|
||||
test_resetClient();
|
||||
test_wipeServer();
|
||||
|
||||
server.stop(run_next_test);
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ function cleanAndGo(server) {
|
||||
server.stop(run_next_test);
|
||||
}
|
||||
|
||||
function configureService(server, username, password) {
|
||||
Service.clusterURL = server.baseURI;
|
||||
function configureService(username, password) {
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
Service.identity.account = username || "foo";
|
||||
Service.identity.basicPassword = password || "password";
|
||||
@ -40,15 +40,15 @@ function createServerAndConfigureClient() {
|
||||
};
|
||||
|
||||
const USER = "foo";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = USER;
|
||||
|
||||
let server = new SyncServer();
|
||||
server.registerUser(USER, "password");
|
||||
server.createContents(USER, contents);
|
||||
server.start();
|
||||
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.clusterURL = server.baseURI;
|
||||
Service.identity.username = USER;
|
||||
|
||||
return [engine, server, USER];
|
||||
}
|
||||
|
||||
@ -75,6 +75,11 @@ function run_test() {
|
||||
add_test(function test_syncStartup_emptyOrOutdatedGlobalsResetsSync() {
|
||||
_("SyncEngine._syncStartup resets sync and wipes server data if there's no or an outdated global record");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
// Some server side data that's going to be wiped
|
||||
let collection = new ServerCollection();
|
||||
collection.insert('flying',
|
||||
@ -88,9 +93,6 @@ add_test(function test_syncStartup_emptyOrOutdatedGlobalsResetsSync() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
Service.identity.username = "foo";
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
engine._store.items = {rekolok: "Rekonstruktionslokomotive"};
|
||||
try {
|
||||
@ -127,14 +129,15 @@ add_test(function test_syncStartup_emptyOrOutdatedGlobalsResetsSync() {
|
||||
add_test(function test_syncStartup_serverHasNewerVersion() {
|
||||
_("SyncEngine._syncStartup ");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let global = new ServerWBO('global', {engines: {rotary: {version: 23456}}});
|
||||
let server = httpd_setup({
|
||||
"/1.1/foo/storage/meta/global": global.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
Service.identity.username = "foo";
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
|
||||
@ -157,9 +160,11 @@ add_test(function test_syncStartup_serverHasNewerVersion() {
|
||||
add_test(function test_syncStartup_syncIDMismatchResetsClient() {
|
||||
_("SyncEngine._syncStartup resets sync if syncIDs don't match");
|
||||
|
||||
let server = sync_httpd_setup({});
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let server = sync_httpd_setup({});
|
||||
|
||||
// global record with a different syncID than our engine has
|
||||
let engine = makeRotaryEngine();
|
||||
@ -193,14 +198,16 @@ add_test(function test_syncStartup_syncIDMismatchResetsClient() {
|
||||
add_test(function test_processIncoming_emptyServer() {
|
||||
_("SyncEngine._processIncoming working with an empty server backend");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
Service.identity.username = "foo";
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
|
||||
@ -217,6 +224,13 @@ add_test(function test_processIncoming_emptyServer() {
|
||||
add_test(function test_processIncoming_createFromServer() {
|
||||
_("SyncEngine._processIncoming creates new records from server data");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
// Some server records that will be downloaded
|
||||
let collection = new ServerCollection();
|
||||
collection.insert('flying',
|
||||
@ -237,11 +251,6 @@ add_test(function test_processIncoming_createFromServer() {
|
||||
"/1.1/foo/storage/rotary/scotsman": collection.wbo("scotsman").handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
Service.identity.username = "foo";
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
@ -278,6 +287,10 @@ add_test(function test_processIncoming_createFromServer() {
|
||||
add_test(function test_processIncoming_reconcile() {
|
||||
_("SyncEngine._processIncoming updates local records");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
|
||||
// This server record is newer than the corresponding client one,
|
||||
@ -322,9 +335,6 @@ add_test(function test_processIncoming_reconcile() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
Service.identity.username = "foo";
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
engine._store.items = {newerserver: "New data, but not as new as server!",
|
||||
olderidentical: "Older but identical",
|
||||
@ -598,8 +608,11 @@ add_test(function test_processIncoming_reconcile_changed_dupe_new() {
|
||||
add_test(function test_processIncoming_mobile_batchSize() {
|
||||
_("SyncEngine._processIncoming doesn't fetch everything at once on mobile clients");
|
||||
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
|
||||
// A collection that logs each GET
|
||||
let collection = new ServerCollection();
|
||||
@ -624,8 +637,6 @@ add_test(function test_processIncoming_mobile_batchSize() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
@ -668,6 +679,9 @@ add_test(function test_processIncoming_mobile_batchSize() {
|
||||
|
||||
add_test(function test_processIncoming_store_toFetch() {
|
||||
_("If processIncoming fails in the middle of a batch on mobile, state is saved in toFetch and lastSync.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
|
||||
@ -695,16 +709,14 @@ add_test(function test_processIncoming_store_toFetch() {
|
||||
let engine = makeRotaryEngine();
|
||||
engine.enabled = true;
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment
|
||||
@ -736,6 +748,9 @@ add_test(function test_processIncoming_store_toFetch() {
|
||||
|
||||
add_test(function test_processIncoming_resume_toFetch() {
|
||||
_("toFetch and previousFailed items left over from previous syncs are fetched on the next sync, along with new items.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
const LASTSYNC = Date.now() / 1000;
|
||||
@ -769,16 +784,14 @@ add_test(function test_processIncoming_resume_toFetch() {
|
||||
engine.toFetch = ["flying", "scotsman"];
|
||||
engine.previousFailed = ["failed0", "failed1", "failed2"];
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment
|
||||
@ -805,6 +818,9 @@ add_test(function test_processIncoming_resume_toFetch() {
|
||||
|
||||
add_test(function test_processIncoming_applyIncomingBatchSize_smaller() {
|
||||
_("Ensure that a number of incoming items less than applyIncomingBatchSize is still applied.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
// Engine that doesn't like the first and last record it's given.
|
||||
@ -827,16 +843,14 @@ add_test(function test_processIncoming_applyIncomingBatchSize_smaller() {
|
||||
collection.insert(id, payload);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment
|
||||
@ -860,6 +874,8 @@ add_test(function test_processIncoming_applyIncomingBatchSize_smaller() {
|
||||
|
||||
add_test(function test_processIncoming_applyIncomingBatchSize_multiple() {
|
||||
_("Ensure that incoming items are applied according to applyIncomingBatchSize.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
const APPLY_BATCH_SIZE = 10;
|
||||
@ -883,16 +899,14 @@ add_test(function test_processIncoming_applyIncomingBatchSize_multiple() {
|
||||
collection.insert(id, payload);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment
|
||||
@ -913,6 +927,9 @@ add_test(function test_processIncoming_applyIncomingBatchSize_multiple() {
|
||||
|
||||
add_test(function test_processIncoming_notify_count() {
|
||||
_("Ensure that failed records are reported only once.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
const APPLY_BATCH_SIZE = 5;
|
||||
@ -935,16 +952,14 @@ add_test(function test_processIncoming_notify_count() {
|
||||
collection.insert(id, payload);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
// Confirm initial environment.
|
||||
do_check_eq(engine.lastSync, 0);
|
||||
@ -1002,6 +1017,9 @@ add_test(function test_processIncoming_notify_count() {
|
||||
|
||||
add_test(function test_processIncoming_previousFailed() {
|
||||
_("Ensure that failed records are retried.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
Svc.Prefs.set("client.type", "mobile");
|
||||
|
||||
@ -1025,16 +1043,14 @@ add_test(function test_processIncoming_previousFailed() {
|
||||
collection.insert(id, payload);
|
||||
}
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
// Confirm initial environment.
|
||||
do_check_eq(engine.lastSync, 0);
|
||||
@ -1088,6 +1104,9 @@ add_test(function test_processIncoming_previousFailed() {
|
||||
|
||||
add_test(function test_processIncoming_failed_records() {
|
||||
_("Ensure that failed records from _reconcile and applyIncomingBatch are refetched.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
// Let's create three and a bit batches worth of server side records.
|
||||
@ -1130,6 +1149,11 @@ add_test(function test_processIncoming_failed_records() {
|
||||
return this._applyIncoming.apply(this, arguments);
|
||||
};
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
|
||||
// Keep track of requests made of a collection.
|
||||
let count = 0;
|
||||
let uris = [];
|
||||
@ -1145,13 +1169,6 @@ add_test(function test_processIncoming_failed_records() {
|
||||
"/1.1/foo/storage/rotary": recording_handler(collection)
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment
|
||||
@ -1223,6 +1240,9 @@ add_test(function test_processIncoming_failed_records() {
|
||||
add_test(function test_processIncoming_decrypt_failed() {
|
||||
_("Ensure that records failing to decrypt are either replaced or refetched.");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
// Some good and some bogus records. One doesn't contain valid JSON,
|
||||
@ -1254,16 +1274,14 @@ add_test(function test_processIncoming_decrypt_failed() {
|
||||
engine._store.items = {nojson: "Valid JSON",
|
||||
nodecrypt: "Valid ciphertext"};
|
||||
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial state
|
||||
@ -1301,6 +1319,9 @@ add_test(function test_processIncoming_decrypt_failed() {
|
||||
add_test(function test_uploadOutgoing_toEmptyServer() {
|
||||
_("SyncEngine._uploadOutgoing uploads new records to server");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
collection._wbos.flying = new ServerWBO('flying');
|
||||
@ -1311,8 +1332,6 @@ add_test(function test_uploadOutgoing_toEmptyServer() {
|
||||
"/1.1/foo/storage/rotary/flying": collection.wbo("flying").handler(),
|
||||
"/1.1/foo/storage/rotary/scotsman": collection.wbo("scotsman").handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
@ -1360,6 +1379,9 @@ add_test(function test_uploadOutgoing_toEmptyServer() {
|
||||
add_test(function test_uploadOutgoing_failed() {
|
||||
_("SyncEngine._uploadOutgoing doesn't clear the tracker of objects that failed to upload.");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
// We only define the "flying" WBO on the server, not the "scotsman"
|
||||
@ -1370,8 +1392,6 @@ add_test(function test_uploadOutgoing_failed() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
engine.lastSync = 123; // needs to be non-zero so that tracker is queried
|
||||
engine._store.items = {flying: "LNER Class A3 4472",
|
||||
@ -1423,6 +1443,9 @@ add_test(function test_uploadOutgoing_failed() {
|
||||
add_test(function test_uploadOutgoing_MAX_UPLOAD_RECORDS() {
|
||||
_("SyncEngine._uploadOutgoing uploads in batches of MAX_UPLOAD_RECORDS");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
|
||||
@ -1453,8 +1476,6 @@ add_test(function test_uploadOutgoing_MAX_UPLOAD_RECORDS() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
try {
|
||||
|
||||
// Confirm initial environment.
|
||||
@ -1480,9 +1501,7 @@ add_test(function test_uploadOutgoing_MAX_UPLOAD_RECORDS() {
|
||||
add_test(function test_syncFinish_noDelete() {
|
||||
_("SyncEngine._syncFinish resets tracker's score");
|
||||
|
||||
let server = httpd_setup({});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
let engine = makeRotaryEngine();
|
||||
engine._delete = {}; // Nothing to delete
|
||||
engine._tracker.score = 100;
|
||||
@ -1490,13 +1509,16 @@ add_test(function test_syncFinish_noDelete() {
|
||||
// _syncFinish() will reset the engine's score.
|
||||
engine._syncFinish();
|
||||
do_check_eq(engine.score, 0);
|
||||
server.stop(run_next_test);
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
|
||||
add_test(function test_syncFinish_deleteByIds() {
|
||||
_("SyncEngine._syncFinish deletes server records slated for deletion (list of record IDs).");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
collection._wbos.flying = new ServerWBO(
|
||||
@ -1512,7 +1534,6 @@ add_test(function test_syncFinish_deleteByIds() {
|
||||
let server = httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
@ -1537,6 +1558,9 @@ add_test(function test_syncFinish_deleteByIds() {
|
||||
add_test(function test_syncFinish_deleteLotsInBatches() {
|
||||
_("SyncEngine._syncFinish deletes server records in batches of 100 (list of record IDs).");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
let collection = new ServerCollection();
|
||||
|
||||
@ -1563,8 +1587,6 @@ add_test(function test_syncFinish_deleteLotsInBatches() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
|
||||
@ -1608,13 +1630,15 @@ add_test(function test_syncFinish_deleteLotsInBatches() {
|
||||
add_test(function test_sync_partialUpload() {
|
||||
_("SyncEngine.sync() keeps changedIDs that couldn't be uploaded.");
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
let collection = new ServerCollection();
|
||||
let server = sync_httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
|
||||
let engine = makeRotaryEngine();
|
||||
@ -1681,6 +1705,9 @@ add_test(function test_sync_partialUpload() {
|
||||
|
||||
add_test(function test_canDecrypt_noCryptoKeys() {
|
||||
_("SyncEngine.canDecrypt returns false if the engine fails to decrypt items on the server, e.g. due to a missing crypto key collection.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
// Wipe collection keys so we can test the desired scenario.
|
||||
@ -1695,7 +1722,6 @@ add_test(function test_canDecrypt_noCryptoKeys() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
|
||||
@ -1708,6 +1734,9 @@ add_test(function test_canDecrypt_noCryptoKeys() {
|
||||
|
||||
add_test(function test_canDecrypt_true() {
|
||||
_("SyncEngine.canDecrypt returns true if the engine can decrypt the items on the server.");
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
@ -1721,7 +1750,6 @@ add_test(function test_canDecrypt_true() {
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
let engine = makeRotaryEngine();
|
||||
try {
|
||||
|
||||
@ -1734,6 +1762,9 @@ add_test(function test_canDecrypt_true() {
|
||||
});
|
||||
|
||||
add_test(function test_syncapplied_observer() {
|
||||
let syncTesting = new SyncTestingInfrastructure();
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.identity.username = "foo";
|
||||
|
||||
const NUMBER_OF_RECORDS = 10;
|
||||
@ -1748,16 +1779,13 @@ add_test(function test_syncapplied_observer() {
|
||||
collection.insert(id, payload);
|
||||
}
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let syncTesting = new SyncTestingInfrastructure(server);
|
||||
|
||||
let meta_global = Service.recordManager.set(engine.metaURL,
|
||||
new WBORecord(engine.metaURL));
|
||||
meta_global.payload.engines = {rotary: {version: engine.version,
|
||||
syncID: engine.syncID}};
|
||||
let server = httpd_setup({
|
||||
"/1.1/foo/storage/rotary": collection.handler()
|
||||
});
|
||||
|
||||
let numApplyCalls = 0;
|
||||
let engine_name;
|
||||
|
@ -52,9 +52,9 @@ function sync_httpd_setup() {
|
||||
});
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
function setUp() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
@ -196,7 +196,7 @@ add_test(function test_masterpassword_locked_retry_interval() {
|
||||
};
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -239,7 +239,7 @@ add_test(function test_scheduleNextSync_nowOrPast() {
|
||||
});
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// We're late for a sync...
|
||||
scheduler.scheduleNextSync(-1);
|
||||
@ -346,7 +346,7 @@ add_test(function test_scheduleNextSync_future_backoff() {
|
||||
|
||||
add_test(function test_handleSyncError() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Force sync to fail.
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
@ -404,7 +404,7 @@ add_test(function test_handleSyncError() {
|
||||
|
||||
add_test(function test_client_sync_finish_updateClientMode() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Confirm defaults.
|
||||
do_check_eq(scheduler.syncThreshold, SINGLE_USER_THRESHOLD);
|
||||
@ -445,7 +445,7 @@ add_test(function test_autoconnect_nextSync_past() {
|
||||
});
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
scheduler.delayedAutoConnect(0);
|
||||
});
|
||||
@ -477,7 +477,7 @@ add_test(function test_autoconnect_nextSync_future() {
|
||||
|
||||
add_test(function test_autoconnect_mp_locked() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Pretend user did not unlock master password.
|
||||
let origLocked = Utils.mpLocked;
|
||||
@ -512,7 +512,7 @@ add_test(function test_autoconnect_mp_locked() {
|
||||
|
||||
add_test(function test_no_autoconnect_during_wizard() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Simulate the Sync setup wizard.
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
@ -561,7 +561,7 @@ add_test(function test_autoconnectDelay_pref() {
|
||||
Svc.Prefs.set("autoconnectDelay", 1);
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
Svc.Obs.notify("weave:service:ready");
|
||||
|
||||
@ -670,9 +670,9 @@ add_test(function test_no_sync_node() {
|
||||
// Test when Status.sync == NO_SYNC_NODE_FOUND
|
||||
// it is not overwritten on sync:finish
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
|
||||
Service.sync();
|
||||
do_check_eq(Status.sync, NO_SYNC_NODE_FOUND);
|
||||
@ -692,7 +692,7 @@ add_test(function test_sync_failed_partial_500s() {
|
||||
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(setUp());
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -722,7 +722,7 @@ add_test(function test_sync_failed_partial_400s() {
|
||||
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(setUp());
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -740,7 +740,7 @@ add_test(function test_sync_failed_partial_400s() {
|
||||
|
||||
add_test(function test_sync_X_Weave_Backoff() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Use an odd value on purpose so that it doesn't happen to coincide with one
|
||||
// of the sync intervals.
|
||||
@ -795,7 +795,7 @@ add_test(function test_sync_X_Weave_Backoff() {
|
||||
|
||||
add_test(function test_sync_503_Retry_After() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
setUp();
|
||||
|
||||
// Use an odd value on purpose so that it doesn't happen to coincide with one
|
||||
// of the sync intervals.
|
||||
@ -855,8 +855,8 @@ add_test(function test_sync_503_Retry_After() {
|
||||
add_test(function test_loginError_recoverable_reschedules() {
|
||||
_("Verify that a recoverable login error schedules a new sync.");
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = "http://localhost:1234/";
|
||||
Service.clusterURL = Service.serverURL;
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.persistLogin();
|
||||
Status.resetSync(); // reset Status.login
|
||||
|
||||
@ -897,16 +897,15 @@ add_test(function test_loginError_recoverable_reschedules() {
|
||||
add_test(function test_loginError_fatal_clearsTriggers() {
|
||||
_("Verify that a fatal login error clears sync triggers.");
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.serverURL = TEST_SERVER_URL;
|
||||
Service.clusterURL = TEST_CLUSTER_URL;
|
||||
Service.persistLogin();
|
||||
Status.resetSync(); // reset Status.login
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/info/collections": httpd_handler(401, "Unauthorized")
|
||||
});
|
||||
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = Service.serverURL;
|
||||
Service.persistLogin();
|
||||
Status.resetSync(); // reset Status.login
|
||||
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
Svc.Obs.remove("weave:service:login:error", onLoginError);
|
||||
Utils.nextTick(function aLittleBitAfterLoginError() {
|
||||
|
@ -8,6 +8,8 @@ Cu.import("resource://services-sync/service.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
const STORAGE_REQUEST_RESOURCE_URL = TEST_SERVER_URL + "resource";
|
||||
|
||||
function run_test() {
|
||||
Log4Moz.repository.getLogger("Sync.RESTRequest").level = Log4Moz.Level.Trace;
|
||||
initTestLogging();
|
||||
@ -23,7 +25,7 @@ add_test(function test_user_agent_desktop() {
|
||||
" FxSync/" + WEAVE_VERSION + "." +
|
||||
Services.appinfo.appBuildID + ".desktop";
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.onComplete = function onComplete(error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -42,7 +44,7 @@ add_test(function test_user_agent_mobile() {
|
||||
" FxSync/" + WEAVE_VERSION + "." +
|
||||
Services.appinfo.appBuildID + ".mobile";
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -58,7 +60,7 @@ add_test(function test_auth() {
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane", "XXXXXXXXX");
|
||||
|
||||
let request = Service.getStorageRequest(server.baseURI + "/resource");
|
||||
let request = Service.getStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -82,7 +84,7 @@ add_test(function test_weave_timestamp() {
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
do_check_eq(SyncStorageRequest.serverTime, undefined);
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -108,7 +110,7 @@ add_test(function test_weave_backoff() {
|
||||
backoffInterval = subject;
|
||||
});
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -133,7 +135,7 @@ add_test(function test_weave_quota_notice() {
|
||||
quotaValue = subject;
|
||||
});
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 200);
|
||||
@ -158,7 +160,7 @@ add_test(function test_weave_quota_error() {
|
||||
}
|
||||
Svc.Obs.add("weave:service:quota:remaining", onQuota);
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
request.get(function (error) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(this.response.status, 400);
|
||||
@ -177,7 +179,7 @@ add_test(function test_abort() {
|
||||
}
|
||||
let server = httpd_setup({"/resource": handler});
|
||||
|
||||
let request = new SyncStorageRequest(server.baseURI + "/resource");
|
||||
let request = new SyncStorageRequest(STORAGE_REQUEST_RESOURCE_URL);
|
||||
|
||||
// Aborting a request that hasn't been sent yet is pointless and will throw.
|
||||
do_check_throws(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user