Skip to content

Commit f7c95b2

Browse files
committed
Added null path check and unit tests to address #130.
1 parent 650e54b commit f7c95b2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ private Map<String, Part> getMultipartFormParametersMap() {
704704

705705

706706
private String cleanUri(String uri) {
707-
String finalUri = uri;
707+
String finalUri = (uri == null ? "" : uri);
708708

709709
if (!finalUri.startsWith("/")) {
710710
finalUri = "/" + finalUri;

aws-serverless-java-container-spark/src/test/java/com/amazonaws/serverless/proxy/spark/HelloWorldSparkStreamTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ public void helloRequest_basicStream_populatesOutputSuccessfully() {
7878
}
7979
}
8080

81+
@Test
82+
public void nullPathRequest_doesntFail_expectA404() {
83+
InputStream req = new AwsProxyRequestBuilder().method("GET").path(null).buildStream();
84+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
85+
try {
86+
handler.proxyStream(req, outputStream, new MockLambdaContext());
87+
AwsProxyResponse response = LambdaContainerHandler.getObjectMapper().readValue(outputStream.toByteArray(), AwsProxyResponse.class);
88+
89+
assertEquals(404, response.getStatusCode());
90+
} catch (IOException e) {
91+
e.printStackTrace();
92+
fail();
93+
}
94+
}
95+
8196
private static void configureRoutes() {
8297
get("/hello", (req, res) -> {
8398
res.status(200);

0 commit comments

Comments
 (0)