Skip to content

Commit

Permalink
bug #930: added email property check, ensuring the correct response. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-rahulbhadoriya authored Jan 29, 2025
1 parent be5d3aa commit fc940ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/resources/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = (service, endpoint) => {

// TODO/SECURITY: subtle timing attack here.
service.post('/users/reset/initiate', endpoint(({ Users, mail }, { auth, body, query }) =>
Users.getByEmail(body.email)
(!body.email ? Problem.user.missingParameter({ field: 'email' }) : Users.getByEmail(body.email)
.then((maybeUser) => maybeUser
.map((user) => ((isTrue(query.invalidate))
? auth.canOrReject('user.password.invalidate', user.actor)
Expand All @@ -71,7 +71,7 @@ module.exports = (service, endpoint) => {
.then((existed) => ((existed === true)
? mail(body.email, 'accountResetDeleted')
: resolve()))))
.then(success))));
.then(success)))));

// TODO: some standard URL structure for RPC-style methods.
service.post('/users/reset/verify', endpoint(({ Actors, Sessions, Users }, { body, auth }) =>
Expand Down
10 changes: 10 additions & 0 deletions test/integration/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ describe('api: /users', () => {
asAlice.post('/v1/users/reset/verify')
.send({ new: 'coolpassword' })
.expect(403))));

it('should fail the request if email field is sent blank in request body', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/users/reset/initiate')
.send({ email: '' })
.expect(400)
.then(({ body: { code, details } }) => {
details.should.eql({ field: 'email' });
code.should.eql(400.2);
}))));
});
}
});
Expand Down

0 comments on commit fc940ff

Please sign in to comment.