Skip to content

Commit 0b3f7ad

Browse files
committed
Merge pull request #184 from ParsePlatform/login_force_string
Reject login when invalid username or password type is provided
2 parents bdfa36d + e6a1e56 commit 0b3f7ad

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/ParseUser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ export default class ParseUser extends ParseObject {
539539
* the login completes.
540540
*/
541541
static logIn(username, password, options) {
542+
if (typeof username !== 'string') {
543+
return ParsePromise.error(
544+
new ParseError(
545+
ParseError.OTHER_CAUSE,
546+
'Username must be a string.'
547+
)
548+
);
549+
} else if (typeof password !== 'string') {
550+
return ParsePromise.error(
551+
new ParseError(
552+
ParseError.OTHER_CAUSE,
553+
'Password must be a string.'
554+
)
555+
);
556+
}
542557
var user = new ParseUser();
543558
user._finishFetch({ username: username, password: password });
544559
return user.logIn(options);

src/__tests__/ParseUser-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ describe('ParseUser', () => {
179179
});
180180
}));
181181

182+
it('fail login when invalid username or password is used', asyncHelper((done) => {
183+
ParseUser.enableUnsafeCurrentUser();
184+
ParseUser._clearCache();
185+
ParseUser.logIn({}, 'password').then(null, (err) => {
186+
expect(err.code).toBe(ParseError.OTHER_CAUSE);
187+
expect(err.message).toBe('Username must be a string.');
188+
189+
return ParseUser.logIn('username', {});
190+
}).then(null, (err) => {
191+
expect(err.code).toBe(ParseError.OTHER_CAUSE);
192+
expect(err.message).toBe('Password must be a string.');
193+
194+
done();
195+
});
196+
}));
197+
182198
it('preserves changes when logging in', asyncHelper((done) => {
183199
ParseUser.enableUnsafeCurrentUser();
184200
ParseUser._clearCache();

0 commit comments

Comments
 (0)