Logging in using admin token should also return a promise (#2038)

* Logging in using admin token should also return a promise
* use the node_require trick
This commit is contained in:
Kenneth Geisshirt 2018-09-21 14:24:37 +02:00 committed by GitHub
parent 30b60aa993
commit 2ea71934d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -4,14 +4,13 @@ x.x.x Release notes (yyyy-MM-dd)
* None
### Fixes
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None
* Fixed a bug in creating credentials using an admin token. ([#2037](https://github.com/realm/realm-js/issues/2037), since v2.16.0-rc.2
### Compatibility
* File format: ver. 7 (upgrades automatically from previous formats)
* Realm Object Server: 3.11.0 or later.
* APIs are backwards compatible with all previous release of realm in the 2.x.y series.
### Internal
* None

View File

@ -381,7 +381,8 @@ const staticMethods = {
checkTypes(arguments, ['string', 'object']);
if (credentials.identityProvider === 'adminToken') {
return this._adminUser(server, credenitals.token);
let u = this._adminUser(server, credentials.token);
return Promise.resolve(u);
}
return _authenticate(this, server, credentials);

View File

@ -24,6 +24,16 @@ const Realm = require('realm');
const TestCase = require('./asserts');
const isNodeProcess = typeof process === 'object' && process + '' === '[object process]';
const require_method = require;
function node_require(module) {
return require_method(module);
}
let fs;
if (isNodeProcess) {
fs = node_require('fs');
}
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
@ -186,6 +196,24 @@ module.exports = {
.catch((e) => { Promise.reject(e) } )
},
testAuthenticateAdminToken() {
if (!isNodeProcess) {
return
}
// read admin token from ROS
let obj = JSON.parse(fs.readFileSync('../realm-object-server-data/keys/admin.json', 'utf8'));
let token = obj['ADMIN_TOKEN'];
let credentials = Realm.Sync.Credentials.adminToken(token);
return Realm.Sync.User.login('http://localhost:9080', credentials)
.then((user) => {
TestCase.assertTrue(user.isAdmin);
Promise.resolve();
})
.catch((e) => { Promise.reject(e) } );
},
testAll() {
const all = Realm.Sync.User.all;
TestCase.assertArrayLength(Object.keys(all), 0);