Search in sources :

Example 6 with AnonymousMockUserSession

use of org.sonar.server.tester.AnonymousMockUserSession in project sonarqube by SonarSource.

the class UserSessionInitializerTest method assertPathIsIgnoredWithAnonymousAccess.

private void assertPathIsIgnoredWithAnonymousAccess(String path) {
    when(request.getRequestURI()).thenReturn(path);
    UserSession session = new AnonymousMockUserSession();
    when(authenticator.authenticate(request, response)).thenReturn(session);
    assertThat(underTest.initUserSession(request, response)).isTrue();
    verify(threadLocalSession).set(session);
    reset(threadLocalSession, authenticator);
}
Also used : ThreadLocalUserSession(org.sonar.server.user.ThreadLocalUserSession) MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) UserSession(org.sonar.server.user.UserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession)

Example 7 with AnonymousMockUserSession

use of org.sonar.server.tester.AnonymousMockUserSession in project sonarqube by SonarSource.

the class UserSessionInitializerTest method does_not_return_code_401_when_not_authenticated_and_with_force_authentication_off.

@Test
public void does_not_return_code_401_when_not_authenticated_and_with_force_authentication_off() {
    when(threadLocalSession.isLoggedIn()).thenReturn(false);
    when(authenticator.authenticate(request, response)).thenReturn(new AnonymousMockUserSession());
    settings.setProperty("sonar.forceAuthentication", false);
    assertThat(underTest.initUserSession(request, response)).isTrue();
    verifyNoMoreInteractions(response);
}
Also used : AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) Test(org.junit.Test)

Example 8 with AnonymousMockUserSession

use of org.sonar.server.tester.AnonymousMockUserSession in project sonarqube by SonarSource.

the class SystemWsTest method define.

@Test
public void define() {
    RestartAction action1 = new RestartAction(mock(UserSession.class), mock(ProcessCommandWrapper.class), mock(RestartFlagHolder.class), mock(WebServer.class));
    InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), mock(SystemInfoWriter.class));
    SystemWs ws = new SystemWs(action1, action2);
    WebService.Context context = new WebService.Context();
    ws.define(context);
    assertThat(context.controllers()).hasSize(1);
    assertThat(context.controller("api/system").actions()).hasSize(2);
    assertThat(context.controller("api/system").action("info")).isNotNull();
}
Also used : ProcessCommandWrapper(org.sonar.server.app.ProcessCommandWrapper) WebServer(org.sonar.server.platform.WebServer) WebService(org.sonar.api.server.ws.WebService) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) UserSession(org.sonar.server.user.UserSession) SystemInfoWriter(org.sonar.server.platform.SystemInfoWriter) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) RestartFlagHolder(org.sonar.server.app.RestartFlagHolder) Test(org.junit.Test)

Aggregations

AnonymousMockUserSession (org.sonar.server.tester.AnonymousMockUserSession)8 Test (org.junit.Test)6 MockUserSession (org.sonar.server.tester.MockUserSession)3 UserSession (org.sonar.server.user.UserSession)2 Before (org.junit.Before)1 WebService (org.sonar.api.server.ws.WebService)1 ProcessCommandWrapper (org.sonar.server.app.ProcessCommandWrapper)1 RestartFlagHolder (org.sonar.server.app.RestartFlagHolder)1 AuthenticationException (org.sonar.server.authentication.event.AuthenticationException)1 SystemInfoWriter (org.sonar.server.platform.SystemInfoWriter)1 WebServer (org.sonar.server.platform.WebServer)1 ThreadLocalUserSession (org.sonar.server.user.ThreadLocalUserSession)1