Skip to content

Commit 3c9709a

Browse files
committed
test(appsec): use Config values instead of hardcoded literals in ParameterCollectorImplTest
1 parent 0d0e2f0 commit 3c9709a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

dd-java-agent/instrumentation/tomcat/tomcat-appsec/tomcat-appsec-7.0/src/test/groovy/datadog/trace/instrumentation/tomcat7/ParameterCollectorImplTest.groovy

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.tomcat7
22

3+
import datadog.trace.api.Config
34
import spock.lang.Specification
45

56
class ParameterCollectorImplTest extends Specification {
@@ -58,40 +59,43 @@ class ParameterCollectorImplTest extends Specification {
5859
collector.getFilenames() == ['a.txt', 'b.txt']
5960
}
6061

61-
void 'addPart truncates content at 4096 bytes'() {
62+
void 'addPart truncates content at MAX_CONTENT_BYTES'() {
6263
given:
64+
def maxBytes = Config.get().getAppSecMaxFileContentBytes()
6365
def collector = new ParameterCollector.ParameterCollectorImpl(true)
64-
def longContent = 'X' * 5000
66+
def longContent = 'X' * (maxBytes + 500)
6567

6668
when:
6769
collector.addPart(new TestPart('big.bin', longContent))
6870

6971
then:
70-
collector.getContents()[0].length() == 4096
72+
collector.getContents()[0].length() == maxBytes
7173
}
7274

73-
void 'addPart reads exactly 4096 bytes when content is 4096 bytes'() {
75+
void 'addPart reads exactly MAX_CONTENT_BYTES when content is exactly that size'() {
7476
given:
77+
def maxBytes = Config.get().getAppSecMaxFileContentBytes()
7578
def collector = new ParameterCollector.ParameterCollectorImpl(true)
76-
def content = 'Y' * 4096
79+
def content = 'Y' * maxBytes
7780

7881
when:
7982
collector.addPart(new TestPart('exact.bin', content))
8083

8184
then:
82-
collector.getContents()[0].length() == 4096
85+
collector.getContents()[0].length() == maxBytes
8386
}
8487

85-
void 'addPart stops collecting content after 25 files but still collects filenames'() {
88+
void 'addPart stops collecting content after MAX_FILES_TO_INSPECT files but still collects filenames'() {
8689
given:
90+
def maxFiles = Config.get().getAppSecMaxFileContentCount()
8791
def collector = new ParameterCollector.ParameterCollectorImpl(true)
8892

8993
when:
90-
(1..26).each { i -> collector.addPart(new TestPart("file${i}.txt", "content${i}")) }
94+
(1..maxFiles + 1).each { i -> collector.addPart(new TestPart("file${i}.txt", "content${i}")) }
9195

9296
then:
93-
collector.getContents().size() == 25
94-
collector.getFilenames().size() == 26
97+
collector.getContents().size() == maxFiles
98+
collector.getFilenames().size() == maxFiles + 1
9599
}
96100

97101
void 'addPart adds empty string when getInputStream throws'() {

0 commit comments

Comments
 (0)