Skip to content

Commit

Permalink
Send request body only if sendDefaultPii is set to true
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Jul 15, 2021
1 parent 296312b commit 52a79ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected void doFilterInternal(

private @NotNull HttpServletRequest resolveHttpServletRequest(
final @NotNull HttpServletRequest request) {
if (qualifiesForCaching(request, hub.getOptions().getMaxRequestBodySize())) {
if (hub.getOptions().isSendDefaultPii()
&& qualifiesForCaching(request, hub.getOptions().getMaxRequestBodySize())) {
try {
return new CachedBodyHttpServletRequest(request);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ class SentrySpringFilterTest {

@Test
fun `caches request depending on the maxRequestBodySize value and request body length`() {
data class TestParams(val maxRequestBodySize: SentryOptions.RequestSize, val body: String, val contentType: String = "application/json", val expectedToBeCached: Boolean)
data class TestParams(val sendDefaultPii: Boolean = true, val maxRequestBodySize: SentryOptions.RequestSize, val body: String, val contentType: String = "application/json", val expectedToBeCached: Boolean)

val params = listOf(
TestParams(maxRequestBodySize = NONE, body = "xxx", expectedToBeCached = false),
TestParams(maxRequestBodySize = SMALL, body = "xxx", expectedToBeCached = false, sendDefaultPii = false),
TestParams(maxRequestBodySize = SMALL, body = "xxx", expectedToBeCached = true),
TestParams(maxRequestBodySize = SMALL, body = "xxx", contentType = "application/octet-stream", expectedToBeCached = false),
TestParams(maxRequestBodySize = SMALL, body = "x".repeat(1001), expectedToBeCached = false),
Expand All @@ -205,6 +206,7 @@ class SentrySpringFilterTest {
val fixture = Fixture()
val sentryOptions = SentryOptions().apply {
maxRequestBodySize = param.maxRequestBodySize
isSendDefaultPii = param.sendDefaultPii
}

val listener = fixture.getSut(request = MockMvcRequestBuilders
Expand Down

0 comments on commit 52a79ab

Please sign in to comment.