@@ -210,10 +210,10 @@ func TestApiGatewayRestApiOpenApiRequestMarshaling(t *testing.T) {
210210 assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
211211}
212212
213- func TestApiGatewayV2HTTPRequestMarshaling (t * testing.T ) {
213+ func TestApiGatewayV2HTTPRequestJWTAuthorizerMarshaling (t * testing.T ) {
214214
215215 // read json from file
216- inputJSON , err := ioutil .ReadFile ("./testdata/apigw-v2-request.json" )
216+ inputJSON , err := ioutil .ReadFile ("./testdata/apigw-v2-request-jwt-authorizer .json" )
217217 if err != nil {
218218 t .Errorf ("could not open test file. details: %v" , err )
219219 }
@@ -245,6 +245,100 @@ func TestApiGatewayV2HTTPRequestMarshaling(t *testing.T) {
245245 assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
246246}
247247
248+ func TestApiGatewayV2HTTPRequestLambdaAuthorizerMarshaling (t * testing.T ) {
249+
250+ // read json from file
251+ inputJSON , err := ioutil .ReadFile ("./testdata/apigw-v2-request-lambda-authorizer.json" )
252+ if err != nil {
253+ t .Errorf ("could not open test file. details: %v" , err )
254+ }
255+
256+ // de-serialize into Go object
257+ var inputEvent APIGatewayV2HTTPRequest
258+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
259+ t .Errorf ("could not unmarshal event. details: %v" , err )
260+ }
261+
262+ // validate custom authorizer context
263+ authContext := inputEvent .RequestContext .Authorizer
264+ if authContext .Lambda ["key" ] != "value" {
265+ t .Errorf ("could not extract authorizer information from Lambda authorizer: %v" , authContext )
266+ }
267+
268+ // validate HTTP details
269+ http := inputEvent .RequestContext .HTTP
270+ if http .Path != "/my/path" {
271+ t .Errorf ("could not extract HTTP details: %v" , http )
272+ }
273+
274+ // serialize to json
275+ outputJSON , err := json .Marshal (inputEvent )
276+ if err != nil {
277+ t .Errorf ("could not marshal event. details: %v" , err )
278+ }
279+
280+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
281+ }
282+
283+ func TestApiGatewayV2HTTPRequestIAMMarshaling (t * testing.T ) {
284+
285+ // read json from file
286+ inputJSON , err := ioutil .ReadFile ("./testdata/apigw-v2-request-iam.json" )
287+ if err != nil {
288+ t .Errorf ("could not open test file. details: %v" , err )
289+ }
290+
291+ // de-serialize into Go object
292+ var inputEvent APIGatewayV2HTTPRequest
293+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
294+ t .Errorf ("could not unmarshal event. details: %v" , err )
295+ }
296+
297+ // validate custom authorizer context
298+ authContext := inputEvent .RequestContext .Authorizer
299+ if authContext .IAM .AccessKey != "ARIA2ZJZYVUEREEIHAKY" {
300+ t .Errorf ("could not extract accessKey from IAM authorizer: %v" , authContext )
301+ }
302+ if authContext .IAM .AccountID != "1234567890" {
303+ t .Errorf ("could not extract accountId from IAM authorizer: %v" , authContext )
304+ }
305+ if authContext .IAM .CallerID != "AROA7ZJZYVRE7C3DUXHH6:CognitoIdentityCredentials" {
306+ t .Errorf ("could not extract callerId from IAM authorizer: %v" , authContext )
307+ }
308+ if authContext .IAM .CognitoIdentity .AMR [0 ] != "foo" {
309+ t .Errorf ("could not extract amr from CognitoIdentity: %v" , authContext )
310+ }
311+ if authContext .IAM .CognitoIdentity .IdentityID != "us-east-1:3f291106-8703-466b-8f2b-3ecee1ca56ce" {
312+ t .Errorf ("could not extract identityId from CognitoIdentity: %v" , authContext )
313+ }
314+ if authContext .IAM .CognitoIdentity .IdentityPoolID != "us-east-1:4f291106-8703-466b-8f2b-3ecee1ca56ce" {
315+ t .Errorf ("could not extract identityPoolId from CognitoIdentity: %v" , authContext )
316+ }
317+ if authContext .IAM .PrincipalOrgID != "AwsOrgId" {
318+ t .Errorf ("could not extract principalOrgId from IAM authorizer: %v" , authContext )
319+ }
320+ if authContext .IAM .UserARN != "arn:aws:iam::1234567890:user/Admin" {
321+ t .Errorf ("could not extract userArn from IAM authorizer: %v" , authContext )
322+ }
323+ if authContext .IAM .UserID != "AROA2ZJZYVRE7Y3TUXHH6" {
324+ t .Errorf ("could not extract userId from IAM authorizer: %v" , authContext )
325+ }
326+
327+ // validate HTTP details
328+ http := inputEvent .RequestContext .HTTP
329+ if http .Path != "/my/path" {
330+ t .Errorf ("could not extract HTTP details: %v" , http )
331+ }
332+
333+ // serialize to json
334+ outputJSON , err := json .Marshal (inputEvent )
335+ if err != nil {
336+ t .Errorf ("could not marshal event. details: %v" , err )
337+ }
338+
339+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
340+ }
341+
248342func TestApiGatewayV2HTTPRequestNoAuthorizerMarshaling (t * testing.T ) {
249343
250344 // read json from file
0 commit comments