forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-account-unlock-on-password-reset' into deploy-debug
* add-account-unlock-on-password-reset: moved changelog entry to correct position Added docs entry added changelog entry added account policy option added account unlock on password reset fix: upgrade ws from 7.4.1 to 7.4.2 (parse-community#7132) Supporting patterns in classNames for Live Queries (parse-community#7131) add api mail adapter to mail adapter list (parse-community#7126) # Conflicts: # CHANGELOG.md # src/Config.js # src/Options/Definitions.js
- Loading branch information
Showing
13 changed files
with
201 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
'use strict'; | ||
|
||
const Config = require('../lib/Config'); | ||
const Definitions = require('../lib/Options/Definitions'); | ||
const request = require('../lib/request'); | ||
|
||
const loginWithWrongCredentialsShouldFail = function (username, password) { | ||
return new Promise((resolve, reject) => { | ||
|
@@ -340,3 +342,118 @@ describe('Account Lockout Policy: ', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('lockout with password reset option', () => { | ||
let sendPasswordResetEmail; | ||
|
||
async function setup(options = {}) { | ||
const accountLockout = Object.assign( | ||
{ | ||
duration: 10000, | ||
threshold: 1, | ||
}, options | ||
); | ||
const config = { | ||
appName: 'exampleApp', | ||
accountLockout: accountLockout, | ||
publicServerURL: 'http://localhost:8378/1', | ||
emailAdapter: { | ||
sendVerificationEmail: () => Promise.resolve(), | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {}, | ||
}, | ||
}; | ||
await reconfigureServer(config); | ||
|
||
sendPasswordResetEmail = spyOn(config.emailAdapter, 'sendPasswordResetEmail').and.callThrough(); | ||
} | ||
|
||
it('accepts valid unlockOnPasswordReset option', async () => { | ||
const values = [true, false]; | ||
|
||
for (const value of values) { | ||
await expectAsync(setup({ unlockOnPasswordReset: value })).toBeResolved(); | ||
} | ||
}); | ||
|
||
it('rejects invalid unlockOnPasswordReset option', async () => { | ||
const values = ["a", 0, {}, [], null]; | ||
|
||
for (const value of values) { | ||
await expectAsync(setup({ unlockOnPasswordReset: value })).toBeRejected(); | ||
} | ||
}); | ||
|
||
it('uses default value if unlockOnPasswordReset is not set', async () => { | ||
await expectAsync(setup({ unlockOnPasswordReset: undefined })).toBeResolved(); | ||
|
||
const parseConfig = Config.get(Parse.applicationId); | ||
expect(parseConfig.accountLockout.unlockOnPasswordReset).toBe(Definitions.AccountLockoutOptions.unlockOnPasswordReset.default); | ||
}); | ||
|
||
it('allow login for locked account after password reset', async () => { | ||
await setup({ unlockOnPasswordReset: true }); | ||
const config = Config.get(Parse.applicationId); | ||
|
||
const user = new Parse.User(); | ||
const username = 'exampleUsername'; | ||
const password = 'examplePassword'; | ||
user.setUsername(username); | ||
user.setPassword(password); | ||
user.setEmail('[email protected]'); | ||
await user.signUp(); | ||
|
||
await expectAsync(Parse.User.logIn(username, 'incorrectPassword')).toBeRejected(); | ||
await expectAsync(Parse.User.logIn(username, password)).toBeRejected(); | ||
|
||
await Parse.User.requestPasswordReset(user.getEmail()); | ||
const link = sendPasswordResetEmail.calls.all()[0].args[0].link; | ||
const linkUrl = new URL(link); | ||
const token = linkUrl.searchParams.get('token'); | ||
const newPassword = 'newPassword'; | ||
await request({ | ||
method: 'POST', | ||
url: `${config.publicServerURL}/apps/test/request_password_reset`, | ||
body: `new_password=${newPassword}&token=${token}&username=${username}`, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
followRedirects: false, | ||
}); | ||
|
||
await expectAsync(Parse.User.logIn(username, newPassword)).toBeResolved(); | ||
}); | ||
|
||
it('reject login for locked account after password reset (default)', async () => { | ||
await setup(); | ||
const config = Config.get(Parse.applicationId); | ||
|
||
const user = new Parse.User(); | ||
const username = 'exampleUsername'; | ||
const password = 'examplePassword'; | ||
user.setUsername(username); | ||
user.setPassword(password); | ||
user.setEmail('[email protected]'); | ||
await user.signUp(); | ||
|
||
await expectAsync(Parse.User.logIn(username, 'incorrectPassword')).toBeRejected(); | ||
await expectAsync(Parse.User.logIn(username, password)).toBeRejected(); | ||
|
||
await Parse.User.requestPasswordReset(user.getEmail()); | ||
const link = sendPasswordResetEmail.calls.all()[0].args[0].link; | ||
const linkUrl = new URL(link); | ||
const token = linkUrl.searchParams.get('token'); | ||
const newPassword = 'newPassword'; | ||
await request({ | ||
method: 'POST', | ||
url: `${config.publicServerURL}/apps/test/request_password_reset`, | ||
body: `new_password=${newPassword}&token=${token}&username=${username}`, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
followRedirects: false, | ||
}); | ||
|
||
await expectAsync(Parse.User.logIn(username, newPassword)).toBeRejected(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters