|
1 | 1 | package datadog.trace.instrumentation.tomcat7 |
2 | 2 |
|
| 3 | +import datadog.trace.api.Config |
3 | 4 | import spock.lang.Specification |
4 | 5 |
|
5 | 6 | class ParameterCollectorImplTest extends Specification { |
@@ -58,40 +59,43 @@ class ParameterCollectorImplTest extends Specification { |
58 | 59 | collector.getFilenames() == ['a.txt', 'b.txt'] |
59 | 60 | } |
60 | 61 |
|
61 | | - void 'addPart truncates content at 4096 bytes'() { |
| 62 | + void 'addPart truncates content at MAX_CONTENT_BYTES'() { |
62 | 63 | given: |
| 64 | + def maxBytes = Config.get().getAppSecMaxFileContentBytes() |
63 | 65 | def collector = new ParameterCollector.ParameterCollectorImpl(true) |
64 | | - def longContent = 'X' * 5000 |
| 66 | + def longContent = 'X' * (maxBytes + 500) |
65 | 67 |
|
66 | 68 | when: |
67 | 69 | collector.addPart(new TestPart('big.bin', longContent)) |
68 | 70 |
|
69 | 71 | then: |
70 | | - collector.getContents()[0].length() == 4096 |
| 72 | + collector.getContents()[0].length() == maxBytes |
71 | 73 | } |
72 | 74 |
|
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'() { |
74 | 76 | given: |
| 77 | + def maxBytes = Config.get().getAppSecMaxFileContentBytes() |
75 | 78 | def collector = new ParameterCollector.ParameterCollectorImpl(true) |
76 | | - def content = 'Y' * 4096 |
| 79 | + def content = 'Y' * maxBytes |
77 | 80 |
|
78 | 81 | when: |
79 | 82 | collector.addPart(new TestPart('exact.bin', content)) |
80 | 83 |
|
81 | 84 | then: |
82 | | - collector.getContents()[0].length() == 4096 |
| 85 | + collector.getContents()[0].length() == maxBytes |
83 | 86 | } |
84 | 87 |
|
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'() { |
86 | 89 | given: |
| 90 | + def maxFiles = Config.get().getAppSecMaxFileContentCount() |
87 | 91 | def collector = new ParameterCollector.ParameterCollectorImpl(true) |
88 | 92 |
|
89 | 93 | 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}")) } |
91 | 95 |
|
92 | 96 | then: |
93 | | - collector.getContents().size() == 25 |
94 | | - collector.getFilenames().size() == 26 |
| 97 | + collector.getContents().size() == maxFiles |
| 98 | + collector.getFilenames().size() == maxFiles + 1 |
95 | 99 | } |
96 | 100 |
|
97 | 101 | void 'addPart adds empty string when getInputStream throws'() { |
|
0 commit comments