Merge branch 'master' into fix-partial-sync-config-ts-definition

This commit is contained in:
blagoev 2017-10-16 15:17:19 +03:00 committed by GitHub
commit 863e80643b
6 changed files with 78 additions and 25 deletions

View File

@ -7,7 +7,8 @@ X.Y.Z Release notes
* None * None
### Bug fixes ### Bug fixes
* Fix Typescript definition for partial sync configuration object * Fix Typescript definition for partial sync configuration object.
* `Realm.Sync.User.adminUser()` will now throw an exception if either token or server argument is invalid.
### Internal ### Internal
* None * None

View File

@ -209,6 +209,7 @@ class User {
* @param {string} adminToken - existing admin token * @param {string} adminToken - existing admin token
* @param {string} server - authentication server * @param {string} server - authentication server
* @return {User} - admin user populated with the given token and server * @return {User} - admin user populated with the given token and server
* @throws {Error} If adminToken or server is invalid.
*/ */
static adminUser(adminToken, server) {} static adminUser(adminToken, server) {}

View File

@ -187,7 +187,19 @@ const staticMethods = {
adminUser(token, server) { adminUser(token, server) {
checkTypes(arguments, ['string', 'string']); checkTypes(arguments, ['string', 'string']);
return this._adminUser(server, token); const user = this._adminUser(server, token);
// FIXME: find a better way to detect that token or server is invalid
// check if object is empty
var isEmpty = true;
for(var prop in user) {
if (user.hasOwnProperty(prop)) {
isEmpty = false;
}
}
if (isEmpty) {
throw new Error('Invalid adminToken or server.');
}
return user;
}, },
register(server, username, password, callback) { register(server, username, password, callback) {

View File

@ -71,14 +71,22 @@ module.exports = {
}, },
}; };
if (global.enableSyncTests) { if (global.enableSyncTests) {
module.exports.testEncryptionWithSync = function() { module.exports.testEncryptionWithSync = function() {
Realm.Sync.User.login('http://localhost:9080', global.testAdminUserInfo.username, global.testAdminUserInfo.password, (error, user) => {
if (error) {
reject(error);
}
new Realm({ new Realm({
encryptionKey: new Int8Array(64), encryptionKey: new Int8Array(64),
sync: { sync: {
user: Realm.Sync.User.adminUser('fake-token', 'http://fake-server'), user: user,
url: 'realm://fake-server' url: 'realm://localhost:9080'
} }
}); });
}; user.logout(); // FIXME: clearTestState() doesn't clean up enough and Realm.Sync.User.current might not work
resolve();
});
}
} }

View File

@ -371,6 +371,38 @@ module.exports = {
}); });
}, },
testAdminUser() {
return new Promise((resolve, reject) => {
if (!isNodeProcess) {
resolve();
}
// FIXME: check if adminUser() returns user iff valid token/server
let didThrow = false;
try {
let user = Realm.Sync.User.adminUser('THIS_IS_INVALID', 'http://localhost:9080');
}
catch (e) {
didThrow = true;
TestCase.assertTrue(e.message === 'Invalid adminToken or server.');
}
TestCase.assertTrue(didThrow);
// FIXME: find a way to set up a proper admin token
didThrow = false;
try {
Realm.Sync.User.adminUser('THIS_IS_VALID', 'http://foo.bar:9080');
}
catch (e) {
didThrow = true;
TestCase.assertTrue(e.message === 'Invalid adminToken or server.');
}
TestCase.assertTrue(didThrow);
resolve();
});
}
/* This test fails because of realm-object-store #243 . We should use 2 users. /* This test fails because of realm-object-store #243 . We should use 2 users.
testSynchronizeChangesWithTwoClientsAndOneUser() { testSynchronizeChangesWithTwoClientsAndOneUser() {
// Test Schema // Test Schema
@ -432,4 +464,3 @@ module.exports = {
}, */ }, */
}; };