Skip to content

Commit b3fcf2b

Browse files
lsohnflovilmart
authored andcommitted
Check usernameOnly parameter in passwordMatches (#609)
* Check usernameOnly parameter in passwordMatches * Added test for 'authenticates valid user with valid username and usernameOnly and encrypted passwords'
1 parent 285902f commit b3fcf2b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Parse-Dashboard/Authentication.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function authenticate(userToTest, usernameOnly) {
8888
this.validUsers.find(user => {
8989
let isAuthenticated = false;
9090
let usernameMatches = userToTest.name == user.user;
91-
let passwordMatches = this.useEncryptedPasswords ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
91+
let passwordMatches = this.useEncryptedPasswords && !usernameOnly ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
9292
if (usernameMatches && (usernameOnly || passwordMatches)) {
9393
isAuthenticated = true;
9494
matchingUsername = user.user;

src/lib/tests/Authentication.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ describe('Authentication', () => {
101101
expect(authentication.authenticate({name: 'parse.dashboard'}))
102102
.toEqual(createAuthenticationResult(false, null, null));
103103
});
104+
105+
it('authenticates valid user with valid username and usernameOnly and encrypted password', () => {
106+
let authentication = new Authentication(encryptedUsers, true);
107+
expect(authentication.authenticate({name: 'parse.dashboard'}, true))
108+
.toEqual(createAuthenticationResult(true, 'parse.dashboard', null));
109+
});
104110
});

0 commit comments

Comments
 (0)