Skip to content

Commit

Permalink
fix(authentication-local): adds error handling for undefined/null pas…
Browse files Browse the repository at this point in the history
…sword field (#2444)
  • Loading branch information
mohitmayank committed Sep 12, 2021
1 parent 6c972f0 commit 4323f98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/authentication-local/src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ export class LocalStrategy extends AuthenticationBaseStrategy {
}

async authenticate (data: AuthenticationRequest, params: Params) {
const { passwordField, usernameField, entity } = this.configuration;
const { passwordField, usernameField, entity, errorMessage } = this.configuration;
const username = data[usernameField];
const password = data[passwordField];

if (!password) { // exit early if there is no password
throw new NotAuthenticated(errorMessage);
}

const result = await this.findEntity(username, omit(params, 'provider'));

await this.comparePassword(result, password);
Expand Down
14 changes: 14 additions & 0 deletions packages/authentication-local/test/strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ describe('@feathersjs/authentication-local/strategy', () => {
}
});

it('fails when password is not provided', async () => {
const authService = app.service('authentication');
try {
await authService.create({
strategy: 'local',
email,
});
assert.fail('Should never get here');
} catch (error) {
assert.strictEqual(error.name, 'NotAuthenticated');
assert.strictEqual(error.message, 'Invalid login');
}
});

it('fails when password field is not available', async () => {
const userEmail = 'someuser@localtest.com';
const authService = app.service('authentication');
Expand Down

0 comments on commit 4323f98

Please sign in to comment.