Merge pull request #1338 from realm/fix-accountInfo-2.0
Fix account info 2.0
This commit is contained in:
commit
7e048a9bee
|
@ -2,4 +2,4 @@ PACKAGE_NAME=realm-js
|
|||
VERSION=2.0.0-rc12
|
||||
REALM_CORE_VERSION=3.2.1
|
||||
REALM_SYNC_VERSION=2.0.0-rc24
|
||||
REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.32
|
||||
REALM_OBJECT_SERVER_VERSION=2.0.0-alpha.36
|
||||
|
|
|
@ -72,6 +72,12 @@ export function createUser(args) {
|
|||
return deserialize(undefined, result);
|
||||
}
|
||||
|
||||
export function _adminUser(args) {
|
||||
args = args.map((arg) => serialize(null, arg));
|
||||
const result = sendRequest('_adminUser', {arguments: args});
|
||||
return deserialize(undefined, result);
|
||||
}
|
||||
|
||||
export function callMethod(realmId, id, name, args) {
|
||||
if (args) {
|
||||
args = args.map((arg) => serialize(realmId, arg));
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import { createUser as createUserRPC, getAllUsers as getAllUsersRPC } from './rpc';
|
||||
import { createUser as createUserRPC, _adminUser as _adminUserRPC, getAllUsers as getAllUsersRPC } from './rpc';
|
||||
import { keys, objectTypes } from './constants';
|
||||
import { createMethods } from './util';
|
||||
|
||||
|
@ -28,6 +28,10 @@ export default class User {
|
|||
return createUserRPC(Array.from(arguments));
|
||||
}
|
||||
|
||||
static _adminUser(adminToken, server) {
|
||||
return _adminUserRPC(Array.from(arguments));
|
||||
}
|
||||
|
||||
static get all() {
|
||||
return getAllUsersRPC();
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ const instanceMethods = {
|
|||
retrieveAccount(provider, provider_id) {
|
||||
checkTypes(arguments, ['string', 'string']);
|
||||
const url = url_parse(this.server);
|
||||
url.set('pathname', `/api/providers/${provider}/accounts/${provider_id}`);
|
||||
url.set('pathname', `/auth/users/${provider}/${provider_id}`);
|
||||
const headers = {
|
||||
Authorization: this.token
|
||||
};
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
exit 0
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
[ "$(uname -s)" != "Darwin" ] && exit
|
||||
|
|
21
src/rpc.cpp
21
src/rpc.cpp
|
@ -191,6 +191,27 @@ RPCServer::RPCServer() {
|
|||
JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values);
|
||||
return (json){{"result", serialize_json_value(user_object)}};
|
||||
};
|
||||
m_requests["/_adminUser"] = [this](const json dict) {
|
||||
JSObjectRef realm_constructor = m_session_id ? JSObjectRef(m_objects[m_session_id]) : NULL;
|
||||
if (!realm_constructor) {
|
||||
throw std::runtime_error("Realm constructor not found!");
|
||||
}
|
||||
|
||||
JSObjectRef sync_constructor = (JSObjectRef)jsc::Object::get_property(m_context, realm_constructor, "Sync");
|
||||
JSObjectRef user_constructor = (JSObjectRef)jsc::Object::get_property(m_context, sync_constructor, "User");
|
||||
JSObjectRef create_user_method = (JSObjectRef)jsc::Object::get_property(m_context, user_constructor, "_adminUser");
|
||||
|
||||
json::array_t args = dict["arguments"];
|
||||
size_t arg_count = args.size();
|
||||
JSValueRef arg_values[arg_count];
|
||||
|
||||
for (size_t i = 0; i < arg_count; i++) {
|
||||
arg_values[i] = deserialize_json_value(args[i]);
|
||||
}
|
||||
|
||||
JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values);
|
||||
return (json){{"result", serialize_json_value(user_object)}};
|
||||
};
|
||||
m_requests["/call_method"] = [this](const json dict) {
|
||||
JSObjectRef object = m_objects[dict["id"].get<RPCObjectID>()];
|
||||
std::string method_string = dict["name"].get<std::string>();
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
|
||||
const Realm = require('realm');
|
||||
|
||||
// FIXME: sync testing needs to be updated for ROS 2.0
|
||||
global.enableSyncTests = Realm.Sync && false;
|
||||
global.enableSyncTests = Realm.Sync;
|
||||
|
||||
var TESTS = {
|
||||
ListTests: require('./list-tests'),
|
||||
|
@ -48,7 +47,7 @@ if (global.enableSyncTests) {
|
|||
if (typeof navigator === 'undefined' ||
|
||||
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
|
||||
|
||||
TESTS.PermissionTests = require('./permission-tests');
|
||||
//TESTS.PermissionTests = require('./permission-tests');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ module.exports = {
|
|||
|
||||
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
|
||||
try {
|
||||
assertIsAuthError(error, 613, "The account cannot be registered as it exists already.");
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid or the user does not exist.");
|
||||
TestCase.assertUndefined(user);
|
||||
resolve();
|
||||
} catch(e) {
|
||||
|
@ -209,7 +209,7 @@ module.exports = {
|
|||
|
||||
testLoginNonExistingUser() {
|
||||
return callbackTest((callback) => Realm.Sync.User.login('http://localhost:9080', 'does_not', 'exist', callback), (error, user) => {
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid.");
|
||||
assertIsAuthError(error, 611, "The provided credentials are invalid or the user does not exist.");
|
||||
TestCase.assertUndefined(user);
|
||||
});
|
||||
},
|
||||
|
@ -322,20 +322,10 @@ module.exports = {
|
|||
|
||||
user.retrieveAccount('password', global.testAdminUserInfo.username)
|
||||
.then(account => {
|
||||
// {
|
||||
// "provider_id": "admin",
|
||||
// "provider": "password",
|
||||
// "user": {
|
||||
// "id": "07ac9a0a-a97a-4ee1-b53c-b05a6542035a",
|
||||
// "isAdmin": true,
|
||||
// }
|
||||
// }
|
||||
|
||||
TestCase.assertEqual(account.provider_id, global.testAdminUserInfo.username);
|
||||
TestCase.assertEqual(account.provider, 'password');
|
||||
TestCase.assertTrue(account.user);
|
||||
TestCase.assertTrue(account.user.isAdmin !== undefined);
|
||||
TestCase.assertTrue(account.user.id);
|
||||
TestCase.assertEqual(account.accounts[0].provider_id, global.testAdminUserInfo.username);
|
||||
TestCase.assertEqual(account.accounts[0].provider, 'password');
|
||||
TestCase.assertTrue(account.is_admin);
|
||||
TestCase.assertTrue(account.user_id);
|
||||
resolve();
|
||||
})
|
||||
.catch(e => reject(e));
|
||||
|
@ -367,7 +357,10 @@ module.exports = {
|
|||
})
|
||||
.catch(e => {
|
||||
try {
|
||||
TestCase.assertEqual(e.code, 404);
|
||||
TestCase.assertEqual(e.status, 404);
|
||||
TestCase.assertEqual(e.code, 612);
|
||||
TestCase.assertEqual(e.message, "The account does not exist.");
|
||||
TestCase.assertEqual(e.type, "https://realm.io/docs/object-server/problems/unknown-account");
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
|
|
Loading…
Reference in New Issue