From 1ed868b99c696e05f73df3555f9cd802f4a7613b Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 11 Mar 2016 09:33:09 -0500 Subject: [PATCH] Fixes #935, cleans up authData null keys on login for android crash --- spec/ParseUser.spec.js | 37 +++++++++++++++++++++++++++++++++++++ src/Routers/UsersRouter.js | 15 ++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index a74644ae90..cb8e94346c 100644 --- a/spec/ParseUser.spec.js +++ b/spec/ParseUser.spec.js @@ -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(); @@ -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(); + }) + }); }); diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index 21dc80ba3f..ac1d1007dd 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -102,7 +102,20 @@ export class UsersRouter extends ClassesRouter { let token = 'r:' + cryptoUtils.newToken(); user.sessionToken = token; delete user.password; - + + // 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();