@@ -2,17 +2,12 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda'
22
33import { getAuthenticationContext } from '../index'
44
5- export const createMockedEvent = ( {
6- authProvider,
7- } : {
8- authProvider : string
9- } ) : APIGatewayProxyEvent => {
5+ export const createMockedEvent = (
6+ headers : Record < string , string >
7+ ) : APIGatewayProxyEvent => {
108 return {
119 body : null ,
12- headers : {
13- 'auth-provider' : authProvider ,
14- authorization : 'Bearer auth-test-token' ,
15- } ,
10+ headers,
1611 multiValueHeaders : { } ,
1712 httpMethod : 'POST' ,
1813 isBase64Encoded : false ,
@@ -55,7 +50,7 @@ export const createMockedEvent = ({
5550 }
5651}
5752
58- describe ( 'getAuthenticationContext' , ( ) => {
53+ describe ( 'getAuthenticationContext with bearer tokens ' , ( ) => {
5954 it ( 'Can take a single auth decoder for the given provider' , async ( ) => {
6055 const authDecoderOne = async ( _token : string , type : string ) => {
6156 if ( type !== 'one' ) {
@@ -70,7 +65,10 @@ describe('getAuthenticationContext', () => {
7065
7166 const result = await getAuthenticationContext ( {
7267 authDecoder : authDecoderOne ,
73- event : createMockedEvent ( { authProvider : 'one' } ) ,
68+ event : createMockedEvent ( {
69+ 'auth-provider' : 'one' ,
70+ authorization : 'Bearer auth-test-token' ,
71+ } ) ,
7472 context : { } as Context ,
7573 } )
7674
@@ -103,7 +101,10 @@ describe('getAuthenticationContext', () => {
103101
104102 const result = await getAuthenticationContext ( {
105103 authDecoder : authDecoderOne ,
106- event : createMockedEvent ( { authProvider : 'some-other' } ) ,
104+ event : createMockedEvent ( {
105+ 'auth-provider' : 'some-other' ,
106+ authorization : 'Bearer auth-test-token' ,
107+ } ) ,
107108 context : { } as Context ,
108109 } )
109110
@@ -122,7 +123,10 @@ describe('getAuthenticationContext', () => {
122123 it ( 'Can take an empty array of auth decoders' , async ( ) => {
123124 const result = await getAuthenticationContext ( {
124125 authDecoder : [ ] ,
125- event : createMockedEvent ( { authProvider : 'two' } ) ,
126+ event : createMockedEvent ( {
127+ 'auth-provider' : 'two' ,
128+ authorization : 'Bearer auth-test-token' ,
129+ } ) ,
126130 context : { } as Context ,
127131 } )
128132
@@ -163,7 +167,10 @@ describe('getAuthenticationContext', () => {
163167
164168 const result = await getAuthenticationContext ( {
165169 authDecoder : [ authDecoderOne , authDecoderTwo ] ,
166- event : createMockedEvent ( { authProvider : 'two' } ) ,
170+ event : createMockedEvent ( {
171+ 'auth-provider' : 'two' ,
172+ authorization : 'Bearer auth-test-token' ,
173+ } ) ,
167174 context : { } as Context ,
168175 } )
169176
@@ -184,7 +191,10 @@ describe('getAuthenticationContext', () => {
184191
185192 it ( 'Works even without any auth decoders' , async ( ) => {
186193 const result = await getAuthenticationContext ( {
187- event : createMockedEvent ( { authProvider : 'two' } ) ,
194+ event : createMockedEvent ( {
195+ 'auth-provider' : 'two' ,
196+ authorization : 'Bearer auth-test-token' ,
197+ } ) ,
188198 context : { } as Context ,
189199 } )
190200
@@ -200,3 +210,6 @@ describe('getAuthenticationContext', () => {
200210 expect ( token ) . toEqual ( 'auth-test-token' )
201211 } )
202212} )
213+
214+ // @TODO add tests for requests with Cookie headers
215+ describe ( 'getAuthenticationContext with cookies' , ( ) => { } )
0 commit comments