Merge pull request #1338 from realm/fix-accountInfo-2.0

Fix account info 2.0
This commit is contained in:
blagoev 2017-09-28 10:08:47 +03:00 committed by GitHub
commit 7e048a9bee
8 changed files with 46 additions and 25 deletions

View File

@ -2,4 +2,4 @@ PACKAGE_NAME=realm-js
VERSION=2.0.0-rc12 VERSION=2.0.0-rc12
REALM_CORE_VERSION=3.2.1 REALM_CORE_VERSION=3.2.1
REALM_SYNC_VERSION=2.0.0-rc24 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

View File

@ -72,6 +72,12 @@ export function createUser(args) {
return deserialize(undefined, result); 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) { export function callMethod(realmId, id, name, args) {
if (args) { if (args) {
args = args.map((arg) => serialize(realmId, arg)); args = args.map((arg) => serialize(realmId, arg));

View File

@ -19,7 +19,7 @@
'use strict'; '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 { keys, objectTypes } from './constants';
import { createMethods } from './util'; import { createMethods } from './util';
@ -28,6 +28,10 @@ export default class User {
return createUserRPC(Array.from(arguments)); return createUserRPC(Array.from(arguments));
} }
static _adminUser(adminToken, server) {
return _adminUserRPC(Array.from(arguments));
}
static get all() { static get all() {
return getAllUsersRPC(); return getAllUsersRPC();
} }

View File

@ -279,7 +279,7 @@ const instanceMethods = {
retrieveAccount(provider, provider_id) { retrieveAccount(provider, provider_id) {
checkTypes(arguments, ['string', 'string']); checkTypes(arguments, ['string', 'string']);
const url = url_parse(this.server); 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 = { const headers = {
Authorization: this.token Authorization: this.token
}; };

View File

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
exit 0
set -eo pipefail set -eo pipefail
[ "$(uname -s)" != "Darwin" ] && exit [ "$(uname -s)" != "Darwin" ] && exit

View File

@ -191,6 +191,27 @@ RPCServer::RPCServer() {
JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values); JSObjectRef user_object = (JSObjectRef)jsc::Function::call(m_context, create_user_method, arg_count, arg_values);
return (json){{"result", serialize_json_value(user_object)}}; 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) { m_requests["/call_method"] = [this](const json dict) {
JSObjectRef object = m_objects[dict["id"].get<RPCObjectID>()]; JSObjectRef object = m_objects[dict["id"].get<RPCObjectID>()];
std::string method_string = dict["name"].get<std::string>(); std::string method_string = dict["name"].get<std::string>();

View File

@ -20,8 +20,7 @@
const Realm = require('realm'); const Realm = require('realm');
// FIXME: sync testing needs to be updated for ROS 2.0 global.enableSyncTests = Realm.Sync;
global.enableSyncTests = Realm.Sync && false;
var TESTS = { var TESTS = {
ListTests: require('./list-tests'), ListTests: require('./list-tests'),
@ -48,7 +47,7 @@ if (global.enableSyncTests) {
if (typeof navigator === 'undefined' || if (typeof navigator === 'undefined' ||
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef !/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
TESTS.PermissionTests = require('./permission-tests'); //TESTS.PermissionTests = require('./permission-tests');
} }
} }

View File

@ -130,7 +130,7 @@ module.exports = {
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => { Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
try { 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); TestCase.assertUndefined(user);
resolve(); resolve();
} catch(e) { } catch(e) {
@ -209,7 +209,7 @@ module.exports = {
testLoginNonExistingUser() { testLoginNonExistingUser() {
return callbackTest((callback) => Realm.Sync.User.login('http://localhost:9080', 'does_not', 'exist', callback), (error, user) => { 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); TestCase.assertUndefined(user);
}); });
}, },
@ -322,20 +322,10 @@ module.exports = {
user.retrieveAccount('password', global.testAdminUserInfo.username) user.retrieveAccount('password', global.testAdminUserInfo.username)
.then(account => { .then(account => {
// { TestCase.assertEqual(account.accounts[0].provider_id, global.testAdminUserInfo.username);
// "provider_id": "admin", TestCase.assertEqual(account.accounts[0].provider, 'password');
// "provider": "password", TestCase.assertTrue(account.is_admin);
// "user": { TestCase.assertTrue(account.user_id);
// "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);
resolve(); resolve();
}) })
.catch(e => reject(e)); .catch(e => reject(e));
@ -367,7 +357,10 @@ module.exports = {
}) })
.catch(e => { .catch(e => {
try { 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) { catch (e) {
reject(e); reject(e);