-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for optional Password Policy #3032
Merged
cherukumilli
merged 26 commits into
parse-community:master
from
bhaskaryasa:password-policy
Nov 17, 2016
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
05cc0d9
Introducing passwordPolicy with resetTokenValidityDuration
bhaskaryasa bbd5d37
validator added to passwordPolicy
bhaskaryasa 96920bd
Add some unit tests for passwordPolicy.validator
bhaskaryasa e7307be
Add unit test for reset password failure for non-conformance
bhaskaryasa 3206b34
Update README.md for passwordPolicy
bhaskaryasa 052d6eb
Added code to handle Parse.Error from rest.update in UserController.u…
bhaskaryasa 6bbdbbe
Merge branch 'password-policy' of https://github.com/bhaskaryasa/pars…
bhaskaryasa 838d7cb
Added optional setting to disallow username in password
bhaskaryasa 54bf4d1
fdescribe -> describe
bhaskaryasa 59fb9d7
updated PasswordPolicy.spec.js to use request-promise
bhaskaryasa e82e1bf
passwordPolicy.validator split into two separate options - RegExp and…
bhaskaryasa 2f0fcd7
Introducing passwordPolicy with resetTokenValidityDuration
bhaskaryasa f41747b
validator added to passwordPolicy
bhaskaryasa 3cd904e
Add some unit tests for passwordPolicy.validator
bhaskaryasa f385f6a
Add unit test for reset password failure for non-conformance
bhaskaryasa 5b868f6
Update README.md for passwordPolicy
bhaskaryasa 1c1a515
Added code to handle Parse.Error from rest.update in UserController.u…
bhaskaryasa bd1673d
Added optional setting to disallow username in password
bhaskaryasa 45ee8b5
fdescribe -> describe
bhaskaryasa f7ce2c7
updated PasswordPolicy.spec.js to use request-promise
bhaskaryasa 838eb27
passwordPolicy.validator split into two separate options - RegExp and…
bhaskaryasa a9f55f8
fixed some typos
bhaskaryasa 7401000
expect username parameter in redirect to password_reset_success
bhaskaryasa 4ce59aa
pull from origin
bhaskaryasa 9ed141c
Fix postgres issue for _perishable_token_expires_at
bhaskaryasa 72a0670
fix for _perishable_token_expires_at
bhaskaryasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
const request = require('request'); | ||
const Config = require('../src/Config'); | ||
|
||
describe("Password Policy: ", () => { | ||
fdescribe("Password Policy: ", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry!! corrected that. |
||
|
||
it('should show the invalid link page if the user clicks on the password reset link after the token expires', done => { | ||
const user = new Parse.User(); | ||
|
@@ -446,4 +446,252 @@ describe("Password Policy: ", () => { | |
}); | ||
}); | ||
|
||
it('should fail if passwordPolicy.doNotAllowUsername is not a boolean value', (done) => { | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
passwordPolicy: { | ||
doNotAllowUsername: 'no' | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}) | ||
.then(() => { | ||
fail('passwordPolicy.doNotAllowUsername type test failed'); | ||
done(); | ||
}) | ||
.catch(err => { | ||
expect(err).toEqual('passwordPolicy.doNotAllowUsername must be a boolean value.'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('signup should fail if password contains the username and is not allowed by policy', (done) => { | ||
const user = new Parse.User(); | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
passwordPolicy: { | ||
validator: /[0-9]+/, | ||
doNotAllowUsername: true | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}).then(() => { | ||
user.setUsername("user1"); | ||
user.setPassword("@user11"); | ||
user.set('email', '[email protected]'); | ||
user.signUp().then(() => { | ||
fail('Should have failed as password contains username.'); | ||
done(); | ||
}, (error) => { | ||
expect(error.code).toEqual(142); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
|
||
it('signup should succeed if password does not contain the username and is not allowed by policy', (done) => { | ||
const user = new Parse.User(); | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
passwordPolicy: { | ||
doNotAllowUsername: true | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}).then(() => { | ||
user.setUsername("user1"); | ||
user.setPassword("r@nd0m"); | ||
user.set('email', '[email protected]'); | ||
user.signUp().then(() => { | ||
done(); | ||
}, (error) => { | ||
fail('Should have succeeded as password does not contain username.'); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
|
||
it('signup should succeed if password contains the username and it is allowed by policy', (done) => { | ||
const user = new Parse.User(); | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
passwordPolicy: { | ||
validator: /[0-9]+/ | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}).then(() => { | ||
user.setUsername("user1"); | ||
user.setPassword("user1"); | ||
user.set('email', '[email protected]'); | ||
user.signUp().then(() => { | ||
done(); | ||
}, (error) => { | ||
fail('Should have succeeded as policy allows username in password.'); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
|
||
it('should fail to reset password if the new password contains username and not allowed by password policy', done => { | ||
var user = new Parse.User(); | ||
var emailAdapter = { | ||
sendVerificationEmail: () => Promise.resolve(), | ||
sendPasswordResetEmail: options => { | ||
request.get(options.link, { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
if (error) { | ||
jfail(error); | ||
fail("Failed to get the reset link"); | ||
return; | ||
} | ||
expect(response.statusCode).toEqual(302); | ||
var re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/; | ||
var match = response.body.match(re); | ||
if (!match) { | ||
fail("should have a token"); | ||
done(); | ||
return; | ||
} | ||
var token = match[1]; | ||
|
||
request.post({ | ||
url: "http://localhost:8378/1/apps/test/request_password_reset", | ||
body: `new_password=xuser12&token=${token}&username=user1`, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
if (error) { | ||
jfail(error); | ||
fail("Failed to POST request password reset"); | ||
return; | ||
} | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual(`Found. Redirecting to http://localhost:8378/1/apps/choose_password?username=user1&token=${token}&id=test&error=Password%20does%20not%20confirm%20to%20the%20Password%20Policy.&app=passwordPolicy`); | ||
|
||
Parse.User.logIn("user1", "r@nd0m").then(function (user) { | ||
done(); | ||
}, (err) => { | ||
jfail(err); | ||
fail("should login with old password"); | ||
done(); | ||
}); | ||
|
||
}); | ||
}); | ||
}, | ||
sendMail: () => { | ||
} | ||
} | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
verifyUserEmails: false, | ||
emailAdapter: emailAdapter, | ||
passwordPolicy: { | ||
doNotAllowUsername: true | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}) | ||
.then(() => { | ||
user.setUsername("user1"); | ||
user.setPassword("r@nd0m"); | ||
user.set('email', '[email protected]'); | ||
user.signUp().then(() => { | ||
Parse.User.requestPasswordReset('[email protected]', { | ||
error: (err) => { | ||
jfail(err); | ||
fail("Reset password request should not fail"); | ||
done(); | ||
} | ||
}); | ||
}, error => { | ||
jfail(error); | ||
fail("signUp should not fail"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should reset password even if the new password contains user name while the policy allows', done => { | ||
var user = new Parse.User(); | ||
var emailAdapter = { | ||
sendVerificationEmail: () => Promise.resolve(), | ||
sendPasswordResetEmail: options => { | ||
request.get(options.link, { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
if (error) { | ||
jfail(error); | ||
fail("Failed to get the reset link"); | ||
return; | ||
} | ||
expect(response.statusCode).toEqual(302); | ||
var re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=user1/; | ||
var match = response.body.match(re); | ||
if (!match) { | ||
fail("should have a token"); | ||
done(); | ||
return; | ||
} | ||
var token = match[1]; | ||
|
||
request.post({ | ||
url: "http://localhost:8378/1/apps/test/request_password_reset", | ||
body: `new_password=uuser11&token=${token}&username=user1`, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
if (error) { | ||
jfail(error); | ||
fail("Failed to POST request password reset"); | ||
return; | ||
} | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html'); | ||
|
||
Parse.User.logIn("user1", "uuser11").then(function (user) { | ||
done(); | ||
}, (err) => { | ||
jfail(err); | ||
fail("should login with new password"); | ||
done(); | ||
}); | ||
|
||
}); | ||
}); | ||
}, | ||
sendMail: () => { | ||
} | ||
} | ||
reconfigureServer({ | ||
appName: 'passwordPolicy', | ||
verifyUserEmails: false, | ||
emailAdapter: emailAdapter, | ||
passwordPolicy: { | ||
validator: /[0-9]+/, | ||
doNotAllowUsername: false | ||
}, | ||
publicServerURL: "http://localhost:8378/1" | ||
}) | ||
.then(() => { | ||
user.setUsername("user1"); | ||
user.setPassword("has 1 digit"); | ||
user.set('email', '[email protected]'); | ||
user.signUp().then(() => { | ||
Parse.User.requestPasswordReset('[email protected]', { | ||
error: (err) => { | ||
jfail(err); | ||
fail("Reset password request should not fail"); | ||
done(); | ||
} | ||
}); | ||
}, error => { | ||
jfail(error); | ||
fail("signUp should not fail"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhaskaryasa
Can you please use
request-promise
orrequest-promise-native
instead of justrequest
?