From 2c771dbb22d53d4f7de3c3f514e57afa1a186322 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Mon, 2 Mar 2020 08:21:04 -0800 Subject: [PATCH] fix(authentication): Improve JWT strategy configuration error message (#1844) --- packages/authentication/src/jwt.ts | 4 ++++ packages/authentication/test/jwt.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/authentication/src/jwt.ts b/packages/authentication/src/jwt.ts index 9b933d1c81..af267e2652 100644 --- a/packages/authentication/src/jwt.ts +++ b/packages/authentication/src/jwt.ts @@ -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`); + } } /** diff --git a/packages/authentication/test/jwt.test.ts b/packages/authentication/test/jwt.test.ts index 728e4e52f6..94606927aa 100644 --- a/packages/authentication/test/jwt.test.ts +++ b/packages/authentication/test/jwt.test.ts @@ -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', () => {