Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Add User.changePassword(id, old, new, cb)#3299
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -117,6 +117,67 @@ describe('users - integration', function() { | ||
| .set('Authorization', 'unknown-token') | ||
| .expect(401, done); | ||
| }); | ||
| it('updates the user\'s password', function() { | ||
| const User = app.models.User; | ||
| const credentials = {email: 'change@example.com', password: 'pass'}; | ||
| return User.create(credentials) | ||
| .then(u => { | ||
| this.user = u; | ||
| return User.login(credentials); | ||
| }) | ||
| .then(token => { | ||
| return this.post('/api/users/change-password') | ||
Contributor 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. PUT? | ||
| .set('Authorization', token.id) | ||
| .send({ | ||
| oldPassword: credentials.password, | ||
| newPassword: 'new password', | ||
| }) | ||
| .expect(204); | ||
| }) | ||
| .then(() => { | ||
| return User.findById(this.user.id); | ||
| }) | ||
| .then(user => { | ||
| return user.hasPassword('new password'); | ||
| }) | ||
| .then(isMatch => expect(isMatch, 'user has new password').to.be.true()); | ||
| }); | ||
| it('rejects unauthenticated change password request', function() { | ||
| return this.post('/api/users/change-password') | ||
Contributor 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. PUT | ||
| .send({ | ||
| oldPassword: 'old password', | ||
| newPassword: 'new password', | ||
| }) | ||
| .expect(401); | ||
| }); | ||
| it('injects change password options from remoting context', function() { | ||
| const User = app.models.User; | ||
| const credentials = {email: 'inject@example.com', password: 'pass'}; | ||
| let injectedOptions; | ||
| User.observe('before save', (ctx, next) => { | ||
| injectedOptions = ctx.options; | ||
| next(); | ||
| }); | ||
| return User.create(credentials) | ||
| .then(u => User.login(credentials)) | ||
| .then(token => { | ||
| return this.post('/api/users/change-password') | ||
Contributor 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. put | ||
| .set('Authorization', token.id) | ||
| .send({ | ||
| oldPassword: credentials.password, | ||
| newPassword: 'new password', | ||
| }) | ||
| .expect(204); | ||
| }) | ||
| .then(() => { | ||
| expect(injectedOptions).to.have.property('accessToken'); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('sub-user', function() { | ||
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.
PUT?
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.
We typically use
POSTfor non-RESTful actions, see e.g.login,logoutorresetPassword.