Skip to content

Commit 6a0bbf7

Browse files
authored
Check how content-length is reported when zero content-length (#3922)
1 parent 0f53344 commit 6a0bbf7

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/CommonTests.groovy

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ trait CommonTests {
271271
@Test
272272
void 'trace without event'() {
273273
def respContentType = null
274-
def respContentLength = null
275274
def trace = container.traceFromRequest('/hello.php') { HttpResponse<InputStream> resp ->
276275
assert resp.statusCode() == 200
277276
def headerContentType = resp.headers().firstValue('Content-Type')
@@ -288,6 +287,28 @@ trait CommonTests {
288287
assert span.meta."http.response.headers.content-language" == 'en'
289288
}
290289

290+
@Test
291+
void 'response with zero content-length'() {
292+
def trace = container.traceFromRequest('/zero_content_length.php') { HttpResponse<InputStream> resp ->
293+
assert resp.statusCode() == 200
294+
}
295+
296+
def spanContentLength = trace.first().meta."http.response.headers.content-length"
297+
assert spanContentLength instanceof String
298+
assert spanContentLength == '0'
299+
}
300+
301+
@Test
302+
void 'response with non-zero content-length'() {
303+
def trace = container.traceFromRequest('/non_zero_content_length.php') { HttpResponse<InputStream> resp ->
304+
assert resp.statusCode() == 200
305+
}
306+
307+
def spanContentLength = trace.first().meta."http.response.headers.content-length"
308+
assert spanContentLength instanceof String
309+
assert spanContentLength == '12'
310+
}
311+
291312
@Test
292313
void 'trace with an attack'() {
293314
HttpRequest req = container.buildReq('/hello.php')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
$content = 'Hello world!';
3+
header('Content-Length: ' . strlen($content));
4+
header('Content-Type: text/plain');
5+
echo $content;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
header('Content-Length: 0');
3+
header('Content-Type: text/plain');

0 commit comments

Comments
 (0)