diff options
author | antoine.vinot <antoine.vinot@sonarsource.com> | 2023-12-12 09:07:34 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-19 20:02:55 +0000 |
commit | 6a2f77f0e34e09ddd7202e92e685948229570f3f (patch) | |
tree | 676d6a86b5a26dfc936359ee6f6c53b75425a691 /server/sonar-webserver-auth/src/it/java/org/sonar | |
parent | 7fe24812e4dccac7aebff9b2c5109727a76af56c (diff) | |
download | sonarqube-6a2f77f0e34e09ddd7202e92e685948229570f3f.tar.gz sonarqube-6a2f77f0e34e09ddd7202e92e685948229570f3f.zip |
SONAR-21227 Configure a new Logger file for deprecated API usages
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.java | 32 |
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); |