|
| 1 | +package datadog.smoketest |
| 2 | + |
| 3 | +import com.github.javaparser.utils.StringEscapeUtils |
| 4 | +import okhttp3.FormBody |
| 5 | +import okhttp3.Request |
| 6 | + |
| 7 | +import static datadog.trace.api.config.IastConfig.IAST_DEBUG_ENABLED |
| 8 | +import static datadog.trace.api.config.IastConfig.IAST_DETECTION_MODE |
| 9 | +import static datadog.trace.api.config.IastConfig.IAST_ENABLED |
| 10 | + |
| 11 | +abstract class AbstractIast17SpringBootTest extends AbstractIastServerSmokeTest { |
| 12 | + |
| 13 | + @Override |
| 14 | + ProcessBuilder createProcessBuilder() { |
| 15 | + String springBootShadowJar = System.getProperty('datadog.smoketest.springboot.shadowJar.path') |
| 16 | + |
| 17 | + List<String> command = [] |
| 18 | + command.add(javaPath()) |
| 19 | + command.addAll(defaultJavaProperties) |
| 20 | + command.addAll(iastJvmOpts()) |
| 21 | + command.addAll((String[]) ['-jar', springBootShadowJar, "--server.port=${httpPort}"]) |
| 22 | + ProcessBuilder processBuilder = new ProcessBuilder(command) |
| 23 | + processBuilder.directory(new File(buildDirectory)) |
| 24 | + // Spring will print all environment variables to the log, which may pollute it and affect log assertions. |
| 25 | + processBuilder.environment().clear() |
| 26 | + return processBuilder |
| 27 | + } |
| 28 | + |
| 29 | + protected List<String> iastJvmOpts() { |
| 30 | + return [ |
| 31 | + withSystemProperty(IAST_ENABLED, true), |
| 32 | + withSystemProperty(IAST_DETECTION_MODE, 'FULL'), |
| 33 | + withSystemProperty(IAST_DEBUG_ENABLED, true), |
| 34 | + ] |
| 35 | + } |
| 36 | + |
| 37 | + void 'test String translateEscapes'() { |
| 38 | + setup: |
| 39 | + final url = "http://localhost:${httpPort}/string/translateEscapes" |
| 40 | + final body = new FormBody.Builder() |
| 41 | + .add('parameter', value) |
| 42 | + .build() |
| 43 | + final request = new Request.Builder().url(url).post(body).build() |
| 44 | + |
| 45 | + |
| 46 | + when: |
| 47 | + client.newCall(request).execute() |
| 48 | + |
| 49 | + then: |
| 50 | + hasTainted { tainted -> |
| 51 | + tainted.value == expected |
| 52 | + } |
| 53 | + |
| 54 | + where: |
| 55 | + value | expected |
| 56 | + "withEscape\ttab" | "withEscape" + Character.toString((char)9) + "tab" |
| 57 | + "withEscape\nnewline" | "withEscape" + StringEscapeUtils.unescapeJava("\\u000A")+ "newline" |
| 58 | + "withEscape\bbackline" | "withEscape" + StringEscapeUtils.unescapeJava("\\u0008")+ "backline" |
| 59 | + } |
| 60 | +} |
0 commit comments