Search in sources :

Example 1 with AnonymousMockUserSession

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

the class SetSeverityActionTest method fail_if_parameter_not_found.

@Test
public void fail_if_parameter_not_found() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Missing parameter : 'severity'");
    action.verify(ImmutableMap.of("unknwown", MINOR), Lists.newArrayList(), new AnonymousMockUserSession());
}
Also used : AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) Test(org.junit.Test)

Example 2 with AnonymousMockUserSession

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

the class UserSessionInitializerTest method return_code_401_when_not_authenticated_and_with_force_authentication.

@Test
public void return_code_401_when_not_authenticated_and_with_force_authentication() {
    ArgumentCaptor<AuthenticationException> exceptionArgumentCaptor = ArgumentCaptor.forClass(AuthenticationException.class);
    when(threadLocalSession.isLoggedIn()).thenReturn(false);
    when(authenticator.authenticate(request, response)).thenReturn(new AnonymousMockUserSession());
    assertThat(underTest.initUserSession(request, response)).isTrue();
    verifyNoMoreInteractions(response);
    verify(authenticationEvent).loginFailure(eq(request), exceptionArgumentCaptor.capture());
    verifyNoMoreInteractions(threadLocalSession);
    AuthenticationException authenticationException = exceptionArgumentCaptor.getValue();
    assertThat(authenticationException.getSource()).isEqualTo(Source.local(Method.BASIC));
    assertThat(authenticationException.getLogin()).isNull();
    assertThat(authenticationException.getMessage()).isEqualTo("User must be authenticated");
    assertThat(authenticationException.getPublicMessage()).isNull();
}
Also used : AuthenticationException(org.sonar.server.authentication.event.AuthenticationException) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) Test(org.junit.Test)

Example 3 with AnonymousMockUserSession

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

the class RequestAuthenticatorImplTest method setUp.

@Before
public void setUp() {
    when(sessionFactory.create(A_USER)).thenReturn(new MockUserSession(A_USER));
    when(sessionFactory.createAnonymous()).thenReturn(new AnonymousMockUserSession());
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) Before(org.junit.Before)

Example 4 with AnonymousMockUserSession

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

the class CommentActionTest method should_verify_fail_if_parameter_not_found.

@Test
public void should_verify_fail_if_parameter_not_found() {
    Map<String, Object> properties = singletonMap("unknwown", "unknown value");
    try {
        action.verify(properties, new ArrayList<>(), new AnonymousMockUserSession());
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Missing parameter : 'comment'");
    }
    verifyZeroInteractions(issueUpdater);
}
Also used : AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) Test(org.junit.Test)

Example 5 with AnonymousMockUserSession

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

the class ThreadLocalUserSessionTest method get_session_for_anonymous.

@Test
public void get_session_for_anonymous() {
    AnonymousMockUserSession expected = new AnonymousMockUserSession();
    threadLocalUserSession.set(expected);
    UserSession session = threadLocalUserSession.get();
    assertThat(session).isSameAs(expected);
    assertThat(threadLocalUserSession.getLogin()).isNull();
    assertThat(threadLocalUserSession.isLoggedIn()).isFalse();
    assertThat(threadLocalUserSession.shouldResetPassword()).isFalse();
    assertThat(threadLocalUserSession.getGroups()).isEmpty();
}
Also used : MockUserSession(org.sonar.server.tester.MockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) AnonymousMockUserSession(org.sonar.server.tester.AnonymousMockUserSession) 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