Fix token refresh and session bugs in chrome debugging (#831)

This commit is contained in:
Yavor Georgiev 2017-02-01 23:44:56 +01:00 committed by GitHub
parent 70437745f0
commit b2da398559
4 changed files with 23 additions and 9 deletions

View File

@ -141,7 +141,7 @@ function serialize(realmId, value) {
return {type: objectTypes.DICT, keys, values}; return {type: objectTypes.DICT, keys, values};
} }
function deserialize(realmId, info) { export function deserialize(realmId, info) {
let type = info.type; let type = info.type;
let handler = type && typeConverters[type]; let handler = type && typeConverters[type];
if (handler) { if (handler) {

View File

@ -20,12 +20,13 @@
import { keys, objectTypes } from './constants'; import { keys, objectTypes } from './constants';
import { getterForProperty, createMethods } from './util'; import { getterForProperty, createMethods } from './util';
import { deserialize } from './rpc';
export default class Session { } export default class Session { }
Object.defineProperties(Session.prototype, { Object.defineProperties(Session.prototype, {
url: getterForProperty('url'), url: { get: getterForProperty('url') },
state: getterForProperty('state') state: { get: getterForProperty('state') }
}); });
createMethods(Session.prototype, objectTypes.SESSION, [ createMethods(Session.prototype, objectTypes.SESSION, [
@ -42,7 +43,8 @@ export function createSession(realmId, info) {
sessionProxy[keys.id] = info.id; sessionProxy[keys.id] = info.id;
sessionProxy[keys.type] = objectTypes.SESSION; sessionProxy[keys.type] = objectTypes.SESSION;
Object.assign(sessionProxy, info.data); sessionProxy.user = deserialize(realmId, info.data.user);
sessionProxy.config = deserialize(realmId, info.data.config)
return sessionProxy; return sessionProxy;
} }

View File

@ -58,10 +58,18 @@ function authenticateRealm(user, fileUrl, realmUrl) {
if (response.status != 200) { if (response.status != 200) {
//FIXME: propagate error to session error handler //FIXME: propagate error to session error handler
} else { } else {
return response.json().then((body) => { return response.json().then(function(body) {
// Look up a fresh instance of the user.
// We do this because in React Native Remote Debugging
// `Realm.clearTestState()` will have invalidated the user object
let newUser = user.constructor.all[user.identity];
if (newUser) {
let session = newUser._sessionForOnDiskPath(fileUrl);
if (session) {
parsedRealmUrl.set('pathname', body.access_token.token_data.path); parsedRealmUrl.set('pathname', body.access_token.token_data.path);
let session = user._sessionForOnDiskPath(fileUrl);
session._refreshAccessToken(body.access_token.token, parsedRealmUrl.href); session._refreshAccessToken(body.access_token.token, parsedRealmUrl.href);
}
}
}); });
} }
}); });

View File

@ -66,7 +66,11 @@ module.exports = {
TestCase.assertEqual(session.state, 'active'); TestCase.assertEqual(session.state, 'active');
// give the session enough time to refresh its access token and bind itself // give the session enough time to refresh its access token and bind itself
return wait(500).then(() => { let timeout = 500;
if (typeof window !== 'undefined') {
timeout = 2500; // need a longer timeout under React Native because remote debugging
}
return wait(timeout).then(() => {
TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`); TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`);
}); });
}); });