1
1
package datadog.trace.agent.test.base
2
2
3
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_JSON
4
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
5
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
6
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
7
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
8
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
9
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
10
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
11
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
12
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
13
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
14
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
15
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
16
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
17
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
18
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
19
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
20
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
21
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
22
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.UNKNOWN
23
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
24
- import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
25
- import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
26
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
27
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
28
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
29
- import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ASYNC_TIMEOUT_ERROR
30
- import static datadog.trace.api.config.TracerConfig.HEADER_TAGS
31
- import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS
32
- import static datadog.trace.api.config.TracerConfig.RESPONSE_HEADER_TAGS
33
- import static datadog.trace.bootstrap.blocking.BlockingActionHelper.TemplateType.JSON
34
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope
35
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
36
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.get
37
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
38
- import static datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator.SERVER_PATHWAY_EDGE_TAGS
39
- import static java.nio.charset.StandardCharsets.UTF_8
40
- import static org.junit.Assume.assumeTrue
41
-
42
3
import ch.qos.logback.classic.Level
43
4
import datadog.appsec.api.blocking.Blocking
44
5
import datadog.appsec.api.blocking.BlockingContentType
@@ -90,6 +51,45 @@ import java.util.function.BiFunction
90
51
import java.util.function.Function
91
52
import java.util.function.Supplier
92
53
54
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_JSON
55
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
56
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
57
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
58
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
59
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
60
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
61
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
62
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
63
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
64
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
65
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
66
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
67
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
68
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
69
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
70
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
71
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
72
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
73
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.UNKNOWN
74
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
75
+ import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
76
+ import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
77
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
78
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
79
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
80
+ import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ASYNC_TIMEOUT_ERROR
81
+ import static datadog.trace.api.config.TracerConfig.HEADER_TAGS
82
+ import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS
83
+ import static datadog.trace.api.config.TracerConfig.RESPONSE_HEADER_TAGS
84
+ import static datadog.trace.bootstrap.blocking.BlockingActionHelper.TemplateType.JSON
85
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope
86
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
87
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.get
88
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
89
+ import static datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator.SERVER_PATHWAY_EDGE_TAGS
90
+ import static java.nio.charset.StandardCharsets.UTF_8
91
+ import static org.junit.Assume.assumeTrue
92
+
93
93
abstract class HttpServerTest <SERVER> extends WithHttpServer<SERVER> {
94
94
95
95
public static final Logger SERVER_LOGGER = LoggerFactory . getLogger(" http-server" )
@@ -209,9 +209,9 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
209
209
// Only used if hasExtraErrorInformation is true
210
210
Map<String , Serializable > expectedExtraErrorInformation (ServerEndpoint endpoint ) {
211
211
if (endpoint. errored) {
212
- [" error.message" : { it == null || it == EXCEPTION . body },
213
- " error.type" : { it == null || it == Exception . name },
214
- " error.stack" : { it == null || it instanceof String }]
212
+ [" error.message" : { it == null || it == EXCEPTION . body },
213
+ " error.type" : { it == null || it == Exception . name },
214
+ " error.stack" : { it == null || it instanceof String }]
215
215
} else {
216
216
Collections . emptyMap()
217
217
}
@@ -493,8 +493,8 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
493
493
}
494
494
495
495
private static final Map<String , ServerEndpoint > PATH_MAP = {
496
- Map<String , ServerEndpoint > map = values(). collectEntries { [it. path, it] }
497
- map. putAll(values(). collectEntries { [it. rawPath, it] })
496
+ Map<String , ServerEndpoint > map = values(). collectEntries { [it. path, it]}
497
+ map. putAll(values(). collectEntries { [it. rawPath, it]})
498
498
map
499
499
}. call()
500
500
@@ -702,9 +702,9 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
702
702
}
703
703
704
704
where :
705
- method | body | header | value | tags
706
- ' GET' | null | ' x-datadog-test-both-header' | ' foo' | [' both_header_tag' : ' foo' ]
707
- ' GET' | null | ' x-datadog-test-request-header' | ' bar' | [' request_header_tag' : ' bar' ]
705
+ method | body | header | value | tags
706
+ ' GET' | null | ' x-datadog-test-both-header' | ' foo' | [ ' both_header_tag' : ' foo' ]
707
+ ' GET' | null | ' x-datadog-test-request-header' | ' bar' | [ ' request_header_tag' : ' bar' ]
708
708
}
709
709
710
710
@Flaky (value = " https://github.com/DataDog/dd-trace-java/issues/4690" , suites = [" MuleHttpServerForkedTest" ])
@@ -716,7 +716,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
716
716
def body = null
717
717
def header = IG_RESPONSE_HEADER
718
718
def mapping = ' mapped_response_header_tag'
719
- def tags = [' mapped_response_header_tag' : " $IG_RESPONSE_HEADER_VALUE " ]
719
+ def tags = [' mapped_response_header_tag' : " $IG_RESPONSE_HEADER_VALUE " ]
720
720
721
721
injectSysConfig(HTTP_SERVER_TAG_QUERY_STRING , " true" )
722
722
injectSysConfig(RESPONSE_HEADER_TAGS , " $header :$mapping " )
@@ -799,13 +799,13 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
799
799
}
800
800
801
801
where :
802
- rawQuery | endpoint | encoded
803
- true | SUCCESS | false
804
- true | QUERY_PARAM | false
805
- true | QUERY_ENCODED_QUERY | true
806
- false | SUCCESS | false
807
- false | QUERY_PARAM | false
808
- false | QUERY_ENCODED_QUERY | true
802
+ rawQuery | endpoint | encoded
803
+ true | SUCCESS | false
804
+ true | QUERY_PARAM | false
805
+ true | QUERY_ENCODED_QUERY | true
806
+ false | SUCCESS | false
807
+ false | QUERY_PARAM | false
808
+ false | QUERY_ENCODED_QUERY | true
809
809
810
810
method = " GET"
811
811
body = null
@@ -918,7 +918,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
918
918
}
919
919
920
920
then :
921
- DDSpan span = TEST_WRITER . flatten(). find { it. operationName == ' appsec-span' }
921
+ DDSpan span = TEST_WRITER . flatten(). find {it. operationName == ' appsec-span' }
922
922
span. getTag(IG_PATH_PARAMS_TAG ) == expectedIGPathParams()
923
923
924
924
and :
@@ -1612,7 +1612,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1612
1612
then :
1613
1613
TEST_WRITER . waitForTraces(1 )
1614
1614
def trace = TEST_WRITER . get(0 )
1615
- assert trace. find { it. isError() } == null
1615
+ assert trace. find {it. isError() } == null
1616
1616
}
1617
1617
1618
1618
def ' test blocking of request for path parameters' () {
@@ -1693,8 +1693,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1693
1693
spans. find { it. tags[' appsec.blocked' ] == ' true' } != null
1694
1694
spans. find {
1695
1695
it. error &&
1696
- it. tags[' error.type' ] == BlockingException . name
1697
- } != null
1696
+ it. tags[' error.type' ] == BlockingException . name } != null
1698
1697
1699
1698
and :
1700
1699
if (isDataStreamsEnabled()) {
@@ -1874,7 +1873,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1874
1873
if (isDataStreamsEnabled()) {
1875
1874
TEST_DATA_STREAMS_WRITER . waitForGroups(1 )
1876
1875
}
1877
- DDSpan span = TEST_WRITER . flatten(). find { it. operationName == ' appsec-span' }
1876
+ DDSpan span = TEST_WRITER . flatten(). find {it. operationName == ' appsec-span' }
1878
1877
span != null
1879
1878
final sessionId = span. tags[IG_SESSION_ID_TAG ]
1880
1879
sessionId != null
0 commit comments