-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathOracleInjectionForkedTest.groovy
More file actions
77 lines (62 loc) · 2.48 KB
/
OracleInjectionForkedTest.groovy
File metadata and controls
77 lines (62 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import datadog.trace.agent.test.InstrumentationSpecification
import datadog.trace.api.config.TraceInstrumentationConfig
import test.TestConnection
import test.TestDatabaseMetaData
import test.TestPreparedStatement
import test.TestStatement
/**
* Tests that Oracle DBM SQL comment injection produces the correct dddbs and dddb tags.
*
* Bug 1: dddbs was populated with the generic type string "oracle" instead of the SID/service name.
* Bug 2: dddb was never injected because the Oracle URL parser sets instance, not db.
*/
abstract class OracleInjectionTestBase extends InstrumentationSpecification {
@Override
void configurePreAgent() {
super.configurePreAgent()
injectSysConfig(TraceInstrumentationConfig.DB_DBM_PROPAGATION_MODE_MODE, "full")
injectSysConfig("service.name", "my_service_name")
}
static query = "SELECT 1"
// Note: the URL parser lowercases the full URL before extraction, so identifiers are lowercase.
static sidUrl = "jdbc:oracle:thin:@localhost:1521:BENEDB"
static serviceNameUrl = "jdbc:oracle:thin:@//localhost:1521/MYSERVICE"
static sidInjection = "ddps='my_service_name',dddbs='benedb',ddh='localhost',dddb='benedb'"
static serviceNameInjection = "ddps='my_service_name',dddbs='myservice',ddh='localhost',dddb='myservice'"
TestConnection createOracleConnection(String url) {
def connection = new TestConnection(false)
def metadata = new TestDatabaseMetaData()
metadata.setURL(url)
connection.setMetaData(metadata)
return connection
}
}
class OracleInjectionForkedTest extends OracleInjectionTestBase {
def "Oracle prepared statement injects instance name in dddbs and dddb"() {
setup:
def connection = createOracleConnection(url)
when:
def statement = connection.prepareStatement(query) as TestPreparedStatement
statement.execute()
then:
statement.sql == "/*${expected}*/ ${query}"
where:
url | expected
sidUrl | sidInjection
serviceNameUrl | serviceNameInjection
}
def "Oracle single statement injects instance name in dddbs and dddb"() {
setup:
def connection = createOracleConnection(url)
when:
def statement = connection.createStatement() as TestStatement
statement.executeQuery(query)
then:
// Oracle uses v$session.action for trace context, so no traceparent in comment
statement.sql == "/*${expected}*/ ${query}"
where:
url | expected
sidUrl | sidInjection
serviceNameUrl | serviceNameInjection
}
}