10
10
import org .springframework .mock .web .MockHttpServletRequest ;
11
11
import org .springframework .mock .web .MockHttpServletResponse ;
12
12
import org .zalando .logbook .Correlation ;
13
+ import org .zalando .logbook .ForwardingHttpRequest ;
13
14
14
15
import static org .assertj .core .api .Assertions .assertThat ;
15
16
@@ -49,6 +50,18 @@ void shouldUsernameContainedIfRemoteUserIsNotNull(CapturedOutput capturedOutput)
49
50
assertThat (
capturedOutput .
toString ()).
contains (
"username=\" [email protected] \" " );
50
51
}
51
52
53
+ @ Test
54
+ void shouldUsernameContainedIfRemoteUserIsNotNullForForwardingRequest (CapturedOutput capturedOutput )
55
+ throws Exception {
56
+ ServletAwareAccessLoggerSink sink = new ServletAwareAccessLoggerSink ();
57
+ MockHttpServletRequest mockRequest = new MockHttpServletRequest ();
58
+ mockRequest .
setRemoteUser (
"[email protected] " );
59
+ RemoteRequest request = new RemoteRequest (mockRequest , FormRequestMode .OFF );
60
+ LocalResponse response = new LocalResponse (new MockHttpServletResponse (), "2.0" );
61
+ sink .write (correlation , (ForwardingHttpRequest ) () -> request , response );
62
+ assertThat (
capturedOutput .
toString ()).
contains (
"username=\" [email protected] \" " );
63
+ }
64
+
52
65
@ Test
53
66
void shouldNotUsernameContainedIfRemoteUserIsNull (CapturedOutput capturedOutput ) throws Exception {
54
67
ServletAwareAccessLoggerSink sink = new ServletAwareAccessLoggerSink ();
@@ -59,4 +72,15 @@ void shouldNotUsernameContainedIfRemoteUserIsNull(CapturedOutput capturedOutput)
59
72
assertThat (capturedOutput .toString ()).doesNotContain ("username=" );
60
73
}
61
74
75
+ @ Test
76
+ void shouldNotUsernameContainedIfRemoteUserIsNullForFowardingRequest (CapturedOutput capturedOutput )
77
+ throws Exception {
78
+ ServletAwareAccessLoggerSink sink = new ServletAwareAccessLoggerSink ();
79
+ MockHttpServletRequest mockRequest = new MockHttpServletRequest ();
80
+ RemoteRequest request = new RemoteRequest (mockRequest , FormRequestMode .OFF );
81
+ LocalResponse response = new LocalResponse (new MockHttpServletResponse (), "2.0" );
82
+ sink .write (correlation , (ForwardingHttpRequest ) () -> request , response );
83
+ assertThat (capturedOutput .toString ()).doesNotContain ("username=" );
84
+ }
85
+
62
86
}
0 commit comments