@@ -129,11 +129,55 @@ public class HttpApiV2ProxyRequestTest {
129129 " \" isBase64Encoded\" : false,\n " +
130130 " \" stageVariables\" : {\" stageVariable1\" : \" value1\" , \" stageVariable2\" : \" value2\" }\n " +
131131 " }\n " ;
132+ private static final String IAM_AUTHORIZER = "{\n " +
133+ " \" version\" : \" 2.0\" ,\n " +
134+ " \" routeKey\" : \" $default\" ,\n " +
135+ " \" rawPath\" : \" /my/path\" ,\n " +
136+ " \" rawQueryString\" : \" parameter1=value1¶meter1=value2¶meter2=value\" ,\n " +
137+ " \" cookies\" : [ \" cookie1\" , \" cookie2\" ],\n " +
138+ " \" headers\" : {\n " +
139+ " \" Header1\" : \" value1\" ,\n " +
140+ " \" Header2\" : \" value2\" \n " +
141+ " },\n " +
142+ " \" queryStringParameters\" : { \" parameter1\" : \" value1,value2\" , \" parameter2\" : \" value\" },\n " +
143+ " \" requestContext\" : {\n " +
144+ " \" accountId\" : \" 123456789012\" ,\n " +
145+ " \" apiId\" : \" api-id\" ,\n " +
146+ " \" authorizer\" : { \" iam\" : {\n " +
147+ " \" accessKey\" : \" AKIAIOSFODNN7EXAMPLE\" ,\n " +
148+ " \" accountId\" : \" 123456789012\" ,\n " +
149+ " \" callerId\" : \" AIDACKCEVSQ6C2EXAMPLE\" ,\n " +
150+ " \" cognitoIdentity\" : null,\n " +
151+ " \" principalOrgId\" : \" AIDACKCEVSQORGEXAMPLE\" ,\n " +
152+ " \" userArn\" : \" arn:aws:iam::111122223333:user/example-user\" ,\n " +
153+ " \" userId\" : \" AIDACOSFODNN7EXAMPLE2\" \n " +
154+ " }" +
155+ " },\n " +
156+ " \" domainName\" : \" id.execute-api.us-east-1.amazonaws.com\" ,\n " +
157+ " \" domainPrefix\" : \" id\" ,\n " +
158+ " \" http\" : {\n " +
159+ " \" method\" : \" POST\" ,\n " +
160+ " \" path\" : \" /my/path\" ,\n " +
161+ " \" protocol\" : \" HTTP/1.1\" ,\n " +
162+ " \" sourceIp\" : \" IP\" ,\n " +
163+ " \" userAgent\" : \" agent\" \n " +
164+ " },\n " +
165+ " \" requestId\" : \" id\" ,\n " +
166+ " \" routeKey\" : \" $default\" ,\n " +
167+ " \" stage\" : \" $default\" ,\n " +
168+ " \" time\" : \" 12/Mar/2020:19:03:58 +0000\" ,\n " +
169+ " \" timeEpoch\" : 1583348638390\n " +
170+ " },\n " +
171+ " \" body\" : \" Hello from Lambda\" ,\n " +
172+ " \" isBase64Encoded\" : false,\n " +
173+ " \" stageVariables\" : {\" stageVariable1\" : \" value1\" , \" stageVariable2\" : \" value2\" }\n " +
174+ " }\n " ;
132175
133176 @ Test
134177 void deserialize_fromJsonString_authorizerPopulatedCorrectly () {
135178 try {
136- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST , HttpApiV2ProxyRequest .class );
179+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST ,
180+ HttpApiV2ProxyRequest .class );
137181 assertTrue (req .getRequestContext ().getAuthorizer ().getJwtAuthorizer ().getClaims ().containsKey ("claim1" ));
138182 assertEquals (2 , req .getRequestContext ().getAuthorizer ().getJwtAuthorizer ().getScopes ().size ());
139183 assertEquals (RequestSource .API_GATEWAY , req .getRequestSource ());
@@ -146,10 +190,12 @@ void deserialize_fromJsonString_authorizerPopulatedCorrectly() {
146190 @ Test
147191 void deserialize_fromJsonString_authorizerEmptyMap () {
148192 try {
149- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY , HttpApiV2ProxyRequest .class );
193+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY ,
194+ HttpApiV2ProxyRequest .class );
150195 assertNotNull (req .getRequestContext ().getAuthorizer ());
151196 assertFalse (req .getRequestContext ().getAuthorizer ().isJwt ());
152197 assertFalse (req .getRequestContext ().getAuthorizer ().isLambda ());
198+ assertFalse (req .getRequestContext ().getAuthorizer ().isIam ());
153199 } catch (JsonProcessingException e ) {
154200 e .printStackTrace ();
155201 fail ("Exception while parsing request" + e .getMessage ());
@@ -159,7 +205,8 @@ void deserialize_fromJsonString_authorizerEmptyMap() {
159205 @ Test
160206 void deserialize_fromJsonString_lambdaAuthorizer () {
161207 try {
162- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (LAMBDA_AUTHORIZER , HttpApiV2ProxyRequest .class );
208+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (LAMBDA_AUTHORIZER ,
209+ HttpApiV2ProxyRequest .class );
163210 assertNotNull (req .getRequestContext ().getAuthorizer ());
164211 assertFalse (req .getRequestContext ().getAuthorizer ().isJwt ());
165212 assertTrue (req .getRequestContext ().getAuthorizer ().isLambda ());
@@ -171,10 +218,38 @@ void deserialize_fromJsonString_lambdaAuthorizer() {
171218 }
172219 }
173220
221+ @ Test
222+ void deserialize_fromJsonString_iamAuthorizer () {
223+ try {
224+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (IAM_AUTHORIZER ,
225+ HttpApiV2ProxyRequest .class );
226+ assertNotNull (req .getRequestContext ().getAuthorizer ());
227+ assertFalse (req .getRequestContext ().getAuthorizer ().isJwt ());
228+ assertFalse (req .getRequestContext ().getAuthorizer ().isLambda ());
229+ assertTrue (req .getRequestContext ().getAuthorizer ().isIam ());
230+ assertEquals ("AKIAIOSFODNN7EXAMPLE" ,
231+ req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getAccessKey ());
232+ assertEquals ("123456789012" , req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getAccountId ());
233+ assertEquals ("AIDACKCEVSQ6C2EXAMPLE" ,
234+ req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getCallerId ());
235+ assertNull (req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getCognitoIdentity ());
236+ assertEquals ("AIDACKCEVSQORGEXAMPLE" ,
237+ req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getPrincipalOrgId ());
238+ assertEquals ("arn:aws:iam::111122223333:user/example-user" ,
239+ req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getUserArn ());
240+ assertEquals ("AIDACOSFODNN7EXAMPLE2" ,
241+ req .getRequestContext ().getAuthorizer ().getIamAuthorizer ().getUserId ());
242+ } catch (JsonProcessingException e ) {
243+ e .printStackTrace ();
244+ fail ("Exception while parsing request" + e .getMessage ());
245+ }
246+ }
247+
174248 @ Test
175249 void deserialize_fromJsonString_isBase64EncodedPopulates () {
176250 try {
177- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST , HttpApiV2ProxyRequest .class );
251+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST ,
252+ HttpApiV2ProxyRequest .class );
178253 assertFalse (req .isBase64Encoded ());
179254 req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY , HttpApiV2ProxyRequest .class );
180255 assertTrue (req .isBase64Encoded ());
@@ -207,4 +282,4 @@ void serialize_toJsonString_authorizerPopulatesCorrectly() {
207282 fail ("Exception while serializing request" + e .getMessage ());
208283 }
209284 }
210- }
285+ }
0 commit comments