aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-auth/src/it/java/org/sonar
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-webserver-auth/src/it/java/org/sonar')
-rw-r--r--server/sonar-webserver-auth/src/it/java/org/sonar/server/authentication/UserSessionInitializerIT.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/sonar-webserver-auth/src/it/java/org/sonar/server/authentication/UserSessionInitializerIT.java b/server/sonar-webserver-auth/src/it/java/org/sonar/server/authentication/UserSessionInitializerIT.java
index 294edb1194c..02601ed7aa7 100644
--- a/server/sonar-webserver-auth/src/it/java/org/sonar/server/authentication/UserSessionInitializerIT.java
+++ b/server/sonar-webserver-auth/src/it/java/org/sonar/server/authentication/UserSessionInitializerIT.java
@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.slf4j.MDC;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.authentication.BaseIdentityProvider;
import org.sonar.api.server.http.Cookie;
@@ -215,6 +216,37 @@ public class UserSessionInitializerIT {
verify(response).addHeader("SonarQube-Authentication-Token-Expiration", formatDateTime(expirationTimestamp));
}
+ @Test
+ public void initUserSession_shouldPutLoginInMDC() {
+ when(threadLocalSession.isLoggedIn()).thenReturn(false);
+ when(authenticator.authenticate(request, response)).thenReturn(new MockUserSession("user"));
+
+ underTest.initUserSession(request, response);
+
+ assertThat(MDC.get("LOGIN")).isEqualTo("user");
+ }
+
+ @Test
+ public void initUserSession_whenSessionLoginIsNull_shouldPutDefaultLoginValueInMDC() {
+ when(threadLocalSession.isLoggedIn()).thenReturn(false);
+ when(authenticator.authenticate(request, response)).thenReturn(new AnonymousMockUserSession());
+
+ underTest.initUserSession(request, response);
+
+ assertThat(MDC.get("LOGIN")).isEqualTo("-");
+ }
+
+ @Test
+ public void removeUserSession_shoudlRemoveMDCLogin() {
+ when(threadLocalSession.isLoggedIn()).thenReturn(false);
+ when(authenticator.authenticate(request, response)).thenReturn(new MockUserSession("user"));
+ underTest.initUserSession(request, response);
+
+ underTest.removeUserSession();
+
+ assertThat(MDC.get("LOGIN")).isNull();
+ }
+
private void assertPathIsIgnored(String path) {
when(request.getRequestURI()).thenReturn(path);