Skip to content

Commit 46c97fa

Browse files
Tolseeacinader
authored andcommitted
Cannot change password when maxPasswordHistory is 1 (parse-community#5191)
* Negitive to zero and positive to same value * add failing test
1 parent eca442b commit 46c97fa

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

spec/PasswordPolicy.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,4 +1633,38 @@ describe('Password Policy: ', () => {
16331633
});
16341634
});
16351635
});
1636+
1637+
it('should not infinitely loop if maxPasswordHistory is 1 (#4918)', async () => {
1638+
const user = new Parse.User();
1639+
const query = new Parse.Query(Parse.User);
1640+
1641+
await reconfigureServer({
1642+
appName: 'passwordPolicy',
1643+
verifyUserEmails: false,
1644+
passwordPolicy: {
1645+
maxPasswordHistory: 1,
1646+
},
1647+
publicServerURL: 'http://localhost:8378/1',
1648+
});
1649+
user.setUsername('user1');
1650+
user.setPassword('user1');
1651+
user.set('email', '[email protected]');
1652+
await user.signUp();
1653+
1654+
user.setPassword('user2');
1655+
await user.save();
1656+
1657+
const result1 = await query.get(user.id, { useMasterKey: true });
1658+
expect(result1.get('_password_history').length).toBe(1);
1659+
1660+
user.setPassword('user3');
1661+
await user.save();
1662+
1663+
const result2 = await query.get(user.id, { useMasterKey: true });
1664+
expect(result2.get('_password_history').length).toBe(1);
1665+
1666+
expect(result1.get('_password_history')).not.toEqual(
1667+
result2.get('_password_history')
1668+
);
1669+
});
16361670
});

src/RestWrite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
12841284
//n-1 passwords go into history including last password
12851285
while (
12861286
oldPasswords.length >
1287-
this.config.passwordPolicy.maxPasswordHistory - 2
1287+
Math.max(0, this.config.passwordPolicy.maxPasswordHistory - 2)
12881288
) {
12891289
oldPasswords.shift();
12901290
}

0 commit comments

Comments
 (0)