Skip to content

Commit 2ace51c

Browse files
committed
Add test case to reproduce invalid body parsing with malformed body
1 parent 44bdff0 commit 2ace51c

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

tests/Event/Http/CommonHttpTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,24 @@ public function test POST request with multipart form data containing ar
357357
]);
358358
}
359359

360+
/**
361+
* @dataProvider provide API Gateway versions
362+
*/
363+
public function test POST request with malformed multipart form data(int $version)
364+
{
365+
$this->fromFixture(__DIR__ . "/Fixture/ag-v$version-body-form-multipart-arrays-malformed.json");
366+
367+
$this->assertContentType('multipart/form-data; boundary=testBoundary');
368+
$body = "--testBoundary\r
369+
Content-Disposition: form-data; name=\"key0[key1][key2][\"\r
370+
\r
371+
123\r
372+
--testBoundary--\r
373+
";
374+
$this->assertBody($body);
375+
$this->assertParsedBody(['key0' => ['key1' => ['key2' => '123']]]);
376+
}
377+
360378
/**
361379
* @dataProvider provide API Gateway versions
362380
*/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"version": "1.0",
3+
"resource": "/path",
4+
"path": "/path",
5+
"httpMethod": "POST",
6+
"headers": {
7+
"Accept": "*/*",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Cache-Control": "no-cache",
10+
"Content-Type": "multipart/form-data; boundary=testBoundary",
11+
"Host": "example.org",
12+
"User-Agent": "PostmanRuntime/7.20.1",
13+
"X-Amzn-Trace-Id": "Root=1-ffffffff-ffffffffffffffffffffffff",
14+
"X-Forwarded-For": "1.1.1.1",
15+
"X-Forwarded-Port": "443",
16+
"X-Forwarded-Proto": "https"
17+
},
18+
"queryStringParameters": null,
19+
"pathParameters": null,
20+
"stageVariables": null,
21+
"requestContext": {
22+
"resourceId": "xxxxxx",
23+
"resourcePath": "/path",
24+
"httpMethod": "PUT",
25+
"extendedRequestId": "XXXXXX-xxxxxxxx=",
26+
"requestTime": "24/Nov/2019:18:55:08 +0000",
27+
"path": "/path",
28+
"accountId": "123400000000",
29+
"protocol": "HTTP/1.1",
30+
"stage": "dev",
31+
"domainPrefix": "dev",
32+
"requestTimeEpoch": 1574621708700,
33+
"requestId": "ffffffff-ffff-4fff-ffff-ffffffffffff",
34+
"identity": {
35+
"cognitoIdentityPoolId": null,
36+
"accountId": null,
37+
"cognitoIdentityId": null,
38+
"caller": null,
39+
"sourceIp": "1.1.1.1",
40+
"principalOrgId": null,
41+
"accessKey": null,
42+
"cognitoAuthenticationType": null,
43+
"cognitoAuthenticationProvider": null,
44+
"userArn": null,
45+
"userAgent": "PostmanRuntime/7.20.1",
46+
"user": null
47+
},
48+
"domainName": "example.org",
49+
"apiId": "xxxxxxxxxx"
50+
},
51+
"body": "--testBoundary\r\nContent-Disposition: form-data; name=\"key0[key1][key2][\"\r\n\r\n123\r\n--testBoundary--\r\n",
52+
"isBase64Encoded": false
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0",
3+
"routeKey": "ANY /path",
4+
"rawPath": "/path",
5+
"rawQueryString": "",
6+
"headers": {
7+
"Accept": "*/*",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Cache-Control": "no-cache",
10+
"Content-Type": "multipart/form-data; boundary=testBoundary",
11+
"Host": "example.org",
12+
"User-Agent": "PostmanRuntime/7.20.1",
13+
"X-Amzn-Trace-Id": "Root=1-ffffffff-ffffffffffffffffffffffff",
14+
"X-Forwarded-For": "1.1.1.1",
15+
"X-Forwarded-Port": "443",
16+
"X-Forwarded-Proto": "https"
17+
},
18+
"queryStringParameters": null,
19+
"stageVariables": null,
20+
"requestContext": {
21+
"accountId": "123400000000",
22+
"apiId": "xxxxxxxxxx",
23+
"domainName": "example.org",
24+
"domainPrefix": "0000000000",
25+
"http": {
26+
"method": "POST",
27+
"path": "/path",
28+
"protocol": "HTTP/1.1",
29+
"sourceIp": "1.1.1.1",
30+
"userAgent": "PostmanRuntime/7.20.1"
31+
},
32+
"requestId": "JTHoQgr2oAMEPMg=",
33+
"routeId": "47matwk",
34+
"routeKey": "ANY /path",
35+
"stage": "$default",
36+
"time": "24/Nov/2019:18:55:08 +0000",
37+
"timeEpoch": 1574621708700
38+
},
39+
"body": "--testBoundary\r\nContent-Disposition: form-data; name=\"key0[key1][key2][\"\r\n\r\n123\r\n--testBoundary--\r\n",
40+
"isBase64Encoded": false
41+
}

0 commit comments

Comments
 (0)