Skip to content

Commit b7cd722

Browse files
committed
Update ApiGatewayRequestIdentity and AwsProxyRequestContext static factory methods with realistic defaults for issue #1495
1 parent b53d81c commit b7cd722

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/model/ApiGatewayRequestIdentity.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@
2828
public class ApiGatewayRequestIdentity {
2929

3030
/**
31-
* Creates an ApiGatewayRequestIdentity instance with default values.
31+
* Creates an ApiGatewayRequestIdentity instance with default values based on a typical API Gateway request.
3232
*
3333
* @return A pre-configured ApiGatewayRequestIdentity instance
3434
*/
3535
public static ApiGatewayRequestIdentity getApiGatewayRequestIdentity() {
3636
ApiGatewayRequestIdentity identity = new ApiGatewayRequestIdentity();
37-
// Set default values for all fields
38-
identity.setApiKey("");
39-
identity.setApiKeyId("");
40-
identity.setUserArn("");
41-
identity.setCognitoAuthenticationType("");
42-
identity.setCaller("");
43-
identity.setUserAgent("");
44-
identity.setUser("");
45-
identity.setCognitoIdentityPoolId("");
46-
identity.setCognitoIdentityId("");
47-
identity.setCognitoAuthenticationProvider("");
48-
identity.setSourceIp("127.0.0.1"); // Reasonable default
49-
identity.setAccountId("");
50-
identity.setAccessKey("");
37+
// Set default values based on example API Gateway request
38+
identity.setApiKey(null);
39+
identity.setApiKeyId(null);
40+
identity.setUserArn(null);
41+
identity.setCognitoAuthenticationType(null);
42+
identity.setCaller(null);
43+
identity.setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
44+
identity.setUser(null);
45+
identity.setCognitoIdentityPoolId(null);
46+
identity.setCognitoIdentityId(null);
47+
identity.setCognitoAuthenticationProvider(null);
48+
identity.setSourceIp("127.0.0.1");
49+
identity.setAccountId(null);
50+
identity.setAccessKey(null);
5151
return identity;
5252
}
5353

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/model/AwsProxyRequestContext.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@
2929
public class AwsProxyRequestContext {
3030

3131
/**
32-
* Creates an AwsProxyRequestContext instance with default values.
32+
* Creates an AwsProxyRequestContext instance with default values based on a typical API Gateway request.
3333
*
3434
* @return A pre-configured AwsProxyRequestContext instance
3535
*/
3636
public static AwsProxyRequestContext getAwsProxyRequestContext() {
3737
AwsProxyRequestContext context = new AwsProxyRequestContext();
38-
// Set default values for all fields
39-
context.setResourceId("");
40-
context.setApiId("");
41-
context.setResourcePath("");
42-
context.setHttpMethod("GET"); // Reasonable default
43-
context.setRequestId("");
38+
39+
// Set default values based on typical API Gateway request
40+
context.setAccountId("123456789012");
41+
context.setApiId("id");
42+
context.setResourceId("$default");
43+
context.setResourcePath("/my/path");
44+
context.setHttpMethod("POST");
45+
context.setRequestId("id");
4446
context.setExtendedRequestId("");
45-
context.setAccountId("");
46-
context.setStage("");
47-
context.setPath("");
48-
context.setProtocol("");
49-
context.setRequestTime("");
47+
context.setStage("$default");
48+
context.setPath("/my/path");
49+
context.setProtocol("HTTP/1.1");
5050
context.setRequestTimeEpoch(System.currentTimeMillis()); // Current time as reasonable default
5151

52-
// Create and set identity with defaults
52+
// Create and set identity with defaults (already includes sourceIp and userAgent)
5353
context.setIdentity(ApiGatewayRequestIdentity.getApiGatewayRequestIdentity());
5454

5555
// Initialize authorizer

0 commit comments

Comments
 (0)