mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Added test_service, which currently tests the case in which the server's meta/version and private/privkey files are correct, as well as all authentication information.
This commit is contained in:
parent
99e6994409
commit
b0ca747fe2
100
services/sync/tests/unit/test_service.js
Normal file
100
services/sync/tests/unit/test_service.js
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
Cu.import("resource://weave/log4moz.js");
|
||||||
|
Cu.import("resource://weave/wrap.js");
|
||||||
|
Cu.import("resource://weave/async.js");
|
||||||
|
Cu.import("resource://weave/util.js");
|
||||||
|
Cu.import("resource://weave/dav.js");
|
||||||
|
Cu.import("resource://weave/crypto.js");
|
||||||
|
Cu.import("resource://weave/identity.js");
|
||||||
|
|
||||||
|
Function.prototype.async = Async.sugar;
|
||||||
|
|
||||||
|
function makeFakeAsyncFunc(retval) {
|
||||||
|
function fakeAsyncFunc() {
|
||||||
|
let self = yield;
|
||||||
|
|
||||||
|
Utils.makeTimerForCall(self.cb);
|
||||||
|
yield;
|
||||||
|
|
||||||
|
self.done(retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fakeAsyncFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Crypto.__proto__ = {
|
||||||
|
RSAkeydecrypt: function fake_RSAkeydecrypt(identity) {
|
||||||
|
let self = yield;
|
||||||
|
|
||||||
|
if (identity.password == "passphrase" &&
|
||||||
|
identity.privkey == "fake private key")
|
||||||
|
self.done("fake public key");
|
||||||
|
else
|
||||||
|
throw new Error("Unexpected identity information.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DAV.__proto__ = {
|
||||||
|
checkLogin: makeFakeAsyncFunc(true),
|
||||||
|
|
||||||
|
__contents: {"meta/version" : "2",
|
||||||
|
"private/privkey" : "fake private key"},
|
||||||
|
|
||||||
|
GET: function fake_GET(path, onComplete) {
|
||||||
|
Log4Moz.Service.rootLogger.info("Retrieving " + path);
|
||||||
|
var result = {status: 404};
|
||||||
|
if (path in this.__contents)
|
||||||
|
result = {status: 200, responseText: this.__contents[path]};
|
||||||
|
|
||||||
|
return makeFakeAsyncFunc(result).async(this, onComplete);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function FakeID(realm, username, password) {
|
||||||
|
this.realm = realm;
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.setTempPassword = function FID_setTempPassword(value) {
|
||||||
|
if (typeof value != "undefined")
|
||||||
|
this.password = value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ID.__proto__ = {
|
||||||
|
__contents: {WeaveID: new FakeID("", "foo", "bar"),
|
||||||
|
WeaveCryptoID: new FakeID("", "", "passphrase")},
|
||||||
|
|
||||||
|
get: function fake_ID_get(name) {
|
||||||
|
return this.__contents[name];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let Service = loadInSandbox("resource://weave/service.js");
|
||||||
|
|
||||||
|
function TestService() {
|
||||||
|
this._startupFinished = false;
|
||||||
|
this._log = Log4Moz.Service.getLogger("Service.Main");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestService.prototype = {
|
||||||
|
};
|
||||||
|
TestService.prototype.__proto__ = Service.WeaveSvc.prototype;
|
||||||
|
|
||||||
|
function test_login_works() {
|
||||||
|
var fts = new FakeTimerService();
|
||||||
|
var logStats = initTestLogging();
|
||||||
|
var testService = new TestService();
|
||||||
|
var finished = false;
|
||||||
|
var successful = false;
|
||||||
|
var onComplete = function(result) {
|
||||||
|
finished = true;
|
||||||
|
successful = result;
|
||||||
|
};
|
||||||
|
|
||||||
|
testService.login(onComplete);
|
||||||
|
|
||||||
|
while (fts.processCallback()) {}
|
||||||
|
|
||||||
|
do_check_true(finished);
|
||||||
|
do_check_true(successful);
|
||||||
|
do_check_eq(logStats.errorsLogged, 0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user