|
1 | 1 | package io.sentry.spring.jakarta |
2 | 2 |
|
3 | 3 | import io.sentry.Breadcrumb |
| 4 | +import io.sentry.HttpBodyType |
4 | 5 | import io.sentry.IScope |
5 | 6 | import io.sentry.IScopes |
6 | 7 | import io.sentry.ISentryLifecycleToken |
@@ -318,6 +319,52 @@ class SentrySpringFilterTest { |
318 | 319 | } |
319 | 320 | } |
320 | 321 |
|
| 322 | + @Test |
| 323 | + fun `data collection can enable request body when sendDefaultPii is false`() { |
| 324 | + val options = |
| 325 | + SentryOptions().apply { |
| 326 | + isSendDefaultPii = false |
| 327 | + maxRequestBodySize = SMALL |
| 328 | + dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_REQUEST) |
| 329 | + } |
| 330 | + val listener = |
| 331 | + fixture.getSut( |
| 332 | + request = |
| 333 | + MockMvcRequestBuilders.post(URI.create("http://example.com")) |
| 334 | + .content("xxx") |
| 335 | + .contentType("application/json") |
| 336 | + .buildRequest(MockServletContext()), |
| 337 | + options = options, |
| 338 | + ) |
| 339 | + |
| 340 | + listener.doFilter(fixture.request, fixture.response, fixture.chain) |
| 341 | + |
| 342 | + verify(fixture.chain).doFilter(check { assertTrue(it is ContentCachingRequestWrapper) }, any()) |
| 343 | + } |
| 344 | + |
| 345 | + @Test |
| 346 | + fun `data collection can disable request body when sendDefaultPii is true`() { |
| 347 | + val options = |
| 348 | + SentryOptions().apply { |
| 349 | + isSendDefaultPii = true |
| 350 | + maxRequestBodySize = SMALL |
| 351 | + dataCollection.httpBodies = emptySet() |
| 352 | + } |
| 353 | + val listener = |
| 354 | + fixture.getSut( |
| 355 | + request = |
| 356 | + MockMvcRequestBuilders.post(URI.create("http://example.com")) |
| 357 | + .content("xxx") |
| 358 | + .contentType("application/json") |
| 359 | + .buildRequest(MockServletContext()), |
| 360 | + options = options, |
| 361 | + ) |
| 362 | + |
| 363 | + listener.doFilter(fixture.request, fixture.response, fixture.chain) |
| 364 | + |
| 365 | + verify(fixture.chain).doFilter(check { assertFalse(it is ContentCachingRequestWrapper) }, any()) |
| 366 | + } |
| 367 | + |
321 | 368 | private fun servletContextWithCustomCookieName(name: String): ServletContext = |
322 | 369 | MockServletContext().also { it.sessionCookieConfig.name = name } |
323 | 370 | } |
0 commit comments