Skip to content

Commit

Permalink
Fixes #935, cleans up authData null keys on login for android crash
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 11, 2016
1 parent d42d359 commit 1ed868b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
37 changes: 37 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var request = require('request');
var passwordCrypto = require('../src/password');
var Config = require('../src/Config');

function verifyACL(user) {
const ACL = user.getACL();
Expand Down Expand Up @@ -1780,5 +1781,41 @@ describe('Parse.User testing', () => {
}
});
});

// Sometimes the authData still has null on that keys
// https://github.com/ParsePlatform/parse-server/issues/935
it('should cleanup null authData keys', (done) => {
let database = new Config(Parse.applicationId).database;
database.create('_User', {
username: 'user',
password: '$2a$10$8/wZJyEuiEaobBBqzTG.jeY.XSFJd0rzaN//ososvEI4yLqI.4aie',
_auth_data_facebook: null
}, {}).then(() => {
return new Promise((resolve, reject) => {
request.get({
url: 'http://localhost:8378/1/login?username=user&password=test',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
json: true
}, (err, res, body) => {
if (err) {
reject(err);
} else {
resolve(body);
}
})
})
}).then((user) => {
let authData = user.authData;
expect(user.username).toEqual('user');
expect(authData).toBeUndefined();
done();
}).catch((err) => {
fail('this should not fail');
done();
})
});
});

15 changes: 14 additions & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ export class UsersRouter extends ClassesRouter {
let token = 'r:' + cryptoUtils.newToken();
user.sessionToken = token;
delete user.password;


This comment has been minimized.

Copy link
@yuzeh

yuzeh Mar 15, 2016

Contributor

Shouldn't this cleanup also be done on the get/save as well? If I'm reading the code correctly, the Android SDK doesn't use the signUp REST endpoint if an Anonymous user has already been saved to the cloud. It uses the save endpoint instead.

https://github.com/ParsePlatform/Parse-SDK-Android/blob/7d908f3d1cbed3c89addfac49419c6c2f1859d62/Parse/src/main/java/com/parse/ParseUser.java#L605

// Sometimes the authData still has null on that keys
// https://github.com/ParsePlatform/parse-server/issues/935
if (user.authData) {
Object.keys(user.authData).forEach((provider) => {
if (user.authData[provider] === null) {
delete user.authData[provider];
}
});
if (Object.keys(user.authData).length == 0) {
delete user.authData;
}
}

req.config.filesController.expandFilesInObject(req.config, user);

let expiresAt = new Date();
Expand Down

0 comments on commit 1ed868b

Please sign in to comment.