Skip to content

Commit

Permalink
fix(authentication): Improve JWT strategy configuration error message (
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Mar 2, 2020
1 parent ecdd0c9 commit 2c771db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/authentication/src/jwt.ts
Expand Up @@ -69,6 +69,10 @@ export class JWTStrategy extends AuthenticationBaseStrategy {
throw new Error(`Invalid JwtStrategy option 'authentication.${this.name}.${key}'. Did you mean to set it in 'authentication.jwtOptions'?`);
}
}

if (typeof this.configuration.header !== 'string') {
throw new Error(`The 'header' option for the ${this.name} strategy must be a string`);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/authentication/test/jwt.test.ts
Expand Up @@ -306,6 +306,16 @@ describe('authentication/jwt', () => {
assert.strictEqual(error.message, `Invalid JwtStrategy option 'authentication.otherJwt.expiresIn'. Did you mean to set it in 'authentication.jwtOptions'?`);
}
});

it('errors when `header` option is an object`', () => {
app.get('authentication').otherJwt = {
header: { message: 'This is wrong' }
};

assert.throws(() => app.service('authentication').register('otherJwt', new JWTStrategy()), {
message: `The 'header' option for the otherJwt strategy must be a string`
});
});
});

describe('parse', () => {
Expand Down

0 comments on commit 2c771db

Please sign in to comment.