Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 5317c97

Browse files
fixed password reset by removing case sensitivity on email
1 parent d4030ce commit 5317c97

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

server/services/auth-management/auth-management.hooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const isEnabled = require('../../hooks/is-enabled');
22
const { authenticate } = require('@feathersjs/authentication').hooks;
3-
const { iff } = require('feathers-hooks-common');
3+
const { iff, lowerCase } = require('feathers-hooks-common');
44

55
const isAction = () => {
66
let args = Array.from(arguments);
@@ -9,7 +9,9 @@ const isAction = () => {
99

1010
module.exports = {
1111
before: {
12-
all: [],
12+
all: [
13+
lowerCase('value.email', 'value.username')
14+
],
1315
find: [],
1416
get: [],
1517
create: [

test/services/auth-management.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ describe('\'authManagement\' service', () => {
5555
});
5656
assert.ok(result, 'password can be reset');
5757
});
58+
59+
it('ignores uppercase email on password reset', async () => {
60+
await service.create({
61+
action: 'sendResetPwd',
62+
value: {
63+
email: user.email.toUpperCase()
64+
}
65+
});
66+
67+
const token = await getTokenFromMail();
68+
69+
const result = await service.create({
70+
action: 'resetPwdLong',
71+
value: {
72+
token,
73+
password: '123456'
74+
}
75+
});
76+
assert.ok(result, 'password can be reset with upper case email');
77+
});
5878
});
5979

6080
const waitFor = (ms) => {
@@ -70,14 +90,18 @@ const getTokenFromMail = async () => {
7090
const mailDir = path.join(__dirname, '../../tmp/emails');
7191
// wait for the mail to be created first
7292
await waitFor(50);
73-
const fileName = await fs.readdirSync(mailDir)[0];
93+
const fileName = await fs.readdirSync(mailDir).pop();
7494
const mailFile = path.join(mailDir, fileName);
7595
const mailContent = await fs.readFileSync(mailFile, 'utf8');
7696
const $ = await cheerio.load(mailContent);
7797
let url;
7898
await $('a.btn-primary').each((i, el) => {
7999
url = el.attribs['href'];
80100
});
101+
102+
// delete mail
103+
// await fs.unlinkSync(mailFile);
104+
81105
const token = url.split('/').pop();
82106
return token;
83107
};

0 commit comments

Comments
 (0)