From 6dc95afea675becc964b3073d76b652fcf636910 Mon Sep 17 00:00:00 2001 From: piotrekwitkowski Date: Tue, 12 Apr 2022 17:31:13 +0200 Subject: [PATCH] Fix type mismatch of the status code (#35) * Fix type mismatch of the status code * Adjust tests Co-authored-by: Piotrek Witkowski --- __tests__/index.test.ts | 2 +- src/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 43fde33..376a4fc 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -263,7 +263,7 @@ describe('handle', () => { authenticator._jwtVerifier.verify.mockImplementationOnce(async () => { throw new Error();}); return expect(authenticator.handle(getCloudfrontRequest())).resolves.toEqual( { - status: 302, + status: '302', headers: { 'location': [{ key: 'Location', diff --git a/src/index.ts b/src/index.ts index 1fc3482..dc7570c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import axios from 'axios'; import { parse, stringify } from 'querystring'; import pino from 'pino'; import { CognitoJwtVerifier } from 'aws-jwt-verify'; -import { CloudFrontRequestEvent } from 'aws-lambda'; +import { CloudFrontRequestEvent, CloudFrontRequestResult } from 'aws-lambda'; interface AuthenticatorParams { region: string; @@ -193,7 +193,7 @@ export class Authenticator { * @param {Object} event Lambda@Edge event. * @return {Promise} CloudFront response. */ - async handle(event: CloudFrontRequestEvent) { + async handle(event: CloudFrontRequestEvent): Promise { this._logger.debug({ msg: 'Handling Lambda@Edge event', event }); const { request } = event.Records[0].cf; @@ -220,7 +220,7 @@ export class Authenticator { const userPoolUrl = `https://${this._userPoolDomain}/authorize?redirect_uri=${redirectURI}&response_type=code&client_id=${this._userPoolAppId}&state=${redirectPath}`; this._logger.debug(`Redirecting user to Cognito User Pool URL ${userPoolUrl}`); return { - status: 302, + status: '302', headers: { 'location': [{ key: 'Location',