Update CorrelationIdFilterTest.java

This commit is contained in:
Ludy87 2025-08-10 12:30:23 +02:00
parent 1973c86720
commit cf2f366e8e
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -22,12 +22,11 @@ import jakarta.servlet.ServletResponse;
/** /**
* Tests for {@link CorrelationIdFilter}. * Tests for {@link CorrelationIdFilter}.
* *
* <p>Important notes: * <p>Important notes: - The filter sets MDC in the try block and clears it in the finally block.
* - The filter sets MDC in the try block and clears it in the finally block. Therefore, * Therefore, we capture the MDC values inside a special FilterChain before the clear happens
* we capture the MDC values inside a special FilterChain before the clear happens (snapshot). * (snapshot). - The response header is sanitized via Newlines.stripAll(id). The current code does
* - The response header is sanitized via Newlines.stripAll(id). * NOT sanitize the value stored in the MDC or the request attribute. These tests reflect the
* The current code does NOT sanitize the value stored in the MDC or the request attribute. * current behavior.
* These tests reflect the current behavior.
*/ */
class CorrelationIdFilterTest { class CorrelationIdFilterTest {
@ -133,7 +132,8 @@ class CorrelationIdFilterTest {
assertTrue(chain.called); assertTrue(chain.called);
// Consistency: same value in MDC, request attribute, and response header (no newline removal needed) // Consistency: same value in MDC, request attribute, and response header (no newline
// removal needed)
String mdcId = chain.capturedMdc.get(CorrelationIdFilter.MDC_KEY); String mdcId = chain.capturedMdc.get(CorrelationIdFilter.MDC_KEY);
assertNotNull(mdcId); assertNotNull(mdcId);
assertEquals(mdcId, chain.requestAttr); assertEquals(mdcId, chain.requestAttr);