Skip to content

Commit 4014786

Browse files
committed
test(appsec): add integration tests for file content size and count limits
1 parent 619e7b9 commit 4014786

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,56 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
16741674
response.close()
16751675
}
16761676

1677+
def 'test instrumentation gateway file upload content truncated at max size'() {
1678+
setup:
1679+
assumeTrue(testBodyFilesContent())
1680+
def maxContentBytes = 4096
1681+
def body = new MultipartBody.Builder()
1682+
.setType(MultipartBody.FORM)
1683+
.addFormDataPart('file', 'large.bin',
1684+
RequestBody.create(MediaType.parse('application/octet-stream'), 'X' * (maxContentBytes + 500)))
1685+
.build()
1686+
def httpRequest = request(BODY_MULTIPART, 'POST', body).build()
1687+
def response = client.newCall(httpRequest).execute()
1688+
1689+
when:
1690+
TEST_WRITER.waitForTraces(1)
1691+
1692+
then:
1693+
TEST_WRITER.get(0).any { span ->
1694+
span.getTag('request.body.files_content') == '[' + 'X' * maxContentBytes + ']'
1695+
}
1696+
1697+
cleanup:
1698+
response.close()
1699+
}
1700+
1701+
def 'test instrumentation gateway file upload content max files limit'() {
1702+
setup:
1703+
assumeTrue(testBodyFilesContent())
1704+
def maxFilesToInspect = 25
1705+
def bodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM)
1706+
(1..maxFilesToInspect + 1).each { i ->
1707+
bodyBuilder.addFormDataPart("file$i", "file${i}.bin",
1708+
RequestBody.create(MediaType.parse('application/octet-stream'), "content_of_file_$i"))
1709+
}
1710+
def httpRequest = request(BODY_MULTIPART, 'POST', bodyBuilder.build()).build()
1711+
def response = client.newCall(httpRequest).execute()
1712+
1713+
when:
1714+
TEST_WRITER.waitForTraces(1)
1715+
1716+
then:
1717+
TEST_WRITER.get(0).any { span ->
1718+
def tag = span.getTag('request.body.files_content') as String
1719+
tag?.contains("content_of_file_$maxFilesToInspect") &&
1720+
!tag.contains("content_of_file_${maxFilesToInspect + 1}")
1721+
}
1722+
1723+
cleanup:
1724+
response.close()
1725+
}
1726+
16771727
def 'test instrumentation gateway json request body'() {
16781728
setup:
16791729
assumeTrue(testBodyJson())

0 commit comments

Comments
 (0)