mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-04 10:43:29 +00:00
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:
parent
30b60aa993
commit
2ea71934d0
@ -4,8 +4,7 @@ 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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user