-
Notifications
You must be signed in to change notification settings - Fork 315
Extract Spring json body response schemas #8938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sezen-datadog
merged 5 commits into
master
from
sezen.leblay/APPSEC-57259-extract-schema-spring
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
57fd21c
HTTP response schema collection and data classification for spring
sezen-datadog 8390078
comments
sezen-datadog d8e424c
Merge branch 'master' into sezen.leblay/APPSEC-57259-extract-schema-s…
sezen-datadog 50bda1b
Merge branch 'master' into sezen.leblay/APPSEC-57259-extract-schema-s…
sezen-datadog 7df3be0
Merge branch 'master' into sezen.leblay/APPSEC-57259-extract-schema-s…
sezen-datadog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...gboot/src/test/groovy/datadog/smoketest/appsec/AppSecHttpMessageConverterSmokeTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package datadog.smoketest.appsec | ||
|
|
||
| import groovy.json.JsonOutput | ||
| import groovy.json.JsonSlurper | ||
| import okhttp3.MediaType | ||
| import okhttp3.Request | ||
| import okhttp3.RequestBody | ||
|
|
||
| import java.util.zip.GZIPInputStream | ||
|
|
||
| class AppSecHttpMessageConverterSmokeTest extends AbstractAppSecServerSmokeTest { | ||
|
|
||
| @Override | ||
| def logLevel() { | ||
| 'DEBUG' | ||
| } | ||
|
|
||
| @Override | ||
| ProcessBuilder createProcessBuilder() { | ||
| String springBootShadowJar = System.getProperty("datadog.smoketest.appsec.springboot.shadowJar.path") | ||
|
|
||
| List<String> command = new ArrayList<>() | ||
| command.add(javaPath()) | ||
| command.addAll(defaultJavaProperties) | ||
| command.addAll(defaultAppSecProperties) | ||
| command.addAll((String[]) [ | ||
| "-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()},DDAgentWriter", | ||
| "-jar", | ||
| springBootShadowJar, | ||
| "--server.port=${httpPort}" | ||
| ]) | ||
| ProcessBuilder processBuilder = new ProcessBuilder(command) | ||
| processBuilder.directory(new File(buildDirectory)) | ||
| } | ||
|
|
||
| @Override | ||
| File createTemporaryFile() { | ||
| return new File("${buildDirectory}/tmp/trace-structure-http-converter.out") | ||
| } | ||
|
|
||
| void 'test response schema extraction'() { | ||
sezen-datadog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| given: | ||
| def url = "http://localhost:${httpPort}/api_security/response" | ||
| def body = [ | ||
| "main" : [["key": "id001", "value": 1345.67], ["value": 1567.89, "key": "id002"]], | ||
| "nullable": null, | ||
| ] | ||
| def request = new Request.Builder() | ||
| .url(url) | ||
| .post(RequestBody.create(MediaType.get('application/json'), JsonOutput.toJson(body))) | ||
| .build() | ||
|
|
||
| when: | ||
| final response = client.newCall(request).execute() | ||
| waitForTraceCount(1) | ||
|
|
||
| then: | ||
| response.code() == 200 | ||
| def span = rootSpans.first() | ||
| span.meta.containsKey('_dd.appsec.s.res.headers') | ||
| span.meta.containsKey('_dd.appsec.s.res.body') | ||
| final schema = new JsonSlurper().parse(unzip(span.meta.get('_dd.appsec.s.res.body'))) | ||
| assert schema == [["main": [[[["key": [8], "value": [16]]]], ["len": 2]], "nullable": [1]]] | ||
| } | ||
|
|
||
| private static byte[] unzip(final String text) { | ||
| final inflaterStream = new GZIPInputStream(new ByteArrayInputStream(text.decodeBase64())) | ||
| return inflaterStream.getBytes() | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.