@@ -129,11 +129,55 @@ public class HttpApiV2ProxyRequestTest {
129
129
" \" isBase64Encoded\" : false,\n " +
130
130
" \" stageVariables\" : {\" stageVariable1\" : \" value1\" , \" stageVariable2\" : \" value2\" }\n " +
131
131
" }\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 " ;
132
175
133
176
@ Test
134
177
void deserialize_fromJsonString_authorizerPopulatedCorrectly () {
135
178
try {
136
- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST , HttpApiV2ProxyRequest .class );
179
+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST ,
180
+ HttpApiV2ProxyRequest .class );
137
181
assertTrue (req .getRequestContext ().getAuthorizer ().getJwtAuthorizer ().getClaims ().containsKey ("claim1" ));
138
182
assertEquals (2 , req .getRequestContext ().getAuthorizer ().getJwtAuthorizer ().getScopes ().size ());
139
183
assertEquals (RequestSource .API_GATEWAY , req .getRequestSource ());
@@ -146,10 +190,12 @@ void deserialize_fromJsonString_authorizerPopulatedCorrectly() {
146
190
@ Test
147
191
void deserialize_fromJsonString_authorizerEmptyMap () {
148
192
try {
149
- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY , HttpApiV2ProxyRequest .class );
193
+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY ,
194
+ HttpApiV2ProxyRequest .class );
150
195
assertNotNull (req .getRequestContext ().getAuthorizer ());
151
196
assertFalse (req .getRequestContext ().getAuthorizer ().isJwt ());
152
197
assertFalse (req .getRequestContext ().getAuthorizer ().isLambda ());
198
+ assertFalse (req .getRequestContext ().getAuthorizer ().isIam ());
153
199
} catch (JsonProcessingException e ) {
154
200
e .printStackTrace ();
155
201
fail ("Exception while parsing request" + e .getMessage ());
@@ -159,7 +205,8 @@ void deserialize_fromJsonString_authorizerEmptyMap() {
159
205
@ Test
160
206
void deserialize_fromJsonString_lambdaAuthorizer () {
161
207
try {
162
- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (LAMBDA_AUTHORIZER , HttpApiV2ProxyRequest .class );
208
+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (LAMBDA_AUTHORIZER ,
209
+ HttpApiV2ProxyRequest .class );
163
210
assertNotNull (req .getRequestContext ().getAuthorizer ());
164
211
assertFalse (req .getRequestContext ().getAuthorizer ().isJwt ());
165
212
assertTrue (req .getRequestContext ().getAuthorizer ().isLambda ());
@@ -171,10 +218,38 @@ void deserialize_fromJsonString_lambdaAuthorizer() {
171
218
}
172
219
}
173
220
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
+
174
248
@ Test
175
249
void deserialize_fromJsonString_isBase64EncodedPopulates () {
176
250
try {
177
- HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST , HttpApiV2ProxyRequest .class );
251
+ HttpApiV2ProxyRequest req = LambdaContainerHandler .getObjectMapper ().readValue (BASE_PROXY_REQUEST ,
252
+ HttpApiV2ProxyRequest .class );
178
253
assertFalse (req .isBase64Encoded ());
179
254
req = LambdaContainerHandler .getObjectMapper ().readValue (NO_AUTH_PROXY , HttpApiV2ProxyRequest .class );
180
255
assertTrue (req .isBase64Encoded ());
@@ -207,4 +282,4 @@ void serialize_toJsonString_authorizerPopulatesCorrectly() {
207
282
fail ("Exception while serializing request" + e .getMessage ());
208
283
}
209
284
}
210
- }
285
+ }
0 commit comments