Search in sources :

Example 11 with UserIdentity

use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.

the class RealmAuthenticatorTest method authenticate_with_group_sync.

@Test
public void authenticate_with_group_sync() throws Exception {
    when(externalGroupsProvider.doGetGroups(any(ExternalGroupsProvider.Context.class))).thenReturn(asList("group1", "group2"));
    when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
    executeStartWithGroupSync();
    executeAuthenticate();
    verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
    UserIdentity userIdentity = userIdentityArgumentCaptor.getValue();
    assertThat(userIdentity.shouldSyncGroups()).isTrue();
    assertThat(userIdentity.getGroups()).containsOnly("group1", "group2");
    verify(authenticationEvent).loginSuccess(request, LOGIN, Source.realm(BASIC, REALM_NAME));
}
Also used : UserIdentity(org.sonar.api.server.authentication.UserIdentity) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) Source(org.sonar.server.authentication.event.AuthenticationEvent.Source) Test(org.junit.Test)

Example 12 with UserIdentity

use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.

the class RealmAuthenticatorTest method does_not_user_downcase_login.

@Test
public void does_not_user_downcase_login() throws Exception {
    settings.setProperty("sonar.authenticator.downcase", false);
    when(userIdentityAuthenticator.authenticate(any(UserIdentity.class), any(IdentityProvider.class), any(Source.class))).thenReturn(USER);
    executeStartWithoutGroupSync();
    executeAuthenticate("LoGiN");
    verify(userIdentityAuthenticator).authenticate(userIdentityArgumentCaptor.capture(), identityProviderArgumentCaptor.capture(), sourceCaptor.capture());
    UserIdentity userIdentity = userIdentityArgumentCaptor.getValue();
    assertThat(userIdentity.getLogin()).isEqualTo("LoGiN");
    assertThat(userIdentity.getProviderLogin()).isEqualTo("LoGiN");
    verify(authenticationEvent).loginSuccess(request, "LoGiN", Source.realm(BASIC, REALM_NAME));
}
Also used : UserIdentity(org.sonar.api.server.authentication.UserIdentity) IdentityProvider(org.sonar.api.server.authentication.IdentityProvider) Source(org.sonar.server.authentication.event.AuthenticationEvent.Source) Test(org.junit.Test)

Example 13 with UserIdentity

use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.

the class UserIdentityFactoryImplTest method null_name_is_replaced_by_provider_login.

@Test
public void null_name_is_replaced_by_provider_login() {
    GsonUser gson = new GsonUser("ABCD", "octocat", null, "octocat@github.com");
    UserIdentity identity = underTest.create(gson, null, null);
    assertThat(identity.getName()).isEqualTo("octocat");
}
Also used : UserIdentity(org.sonar.api.server.authentication.UserIdentity) Test(org.junit.Test)

Example 14 with UserIdentity

use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.

the class UserIdentityFactoryImplTest method no_email.

@Test
public void no_email() {
    GsonUser gson = new GsonUser("ABCD", "octocat", "monalisa octocat", null);
    UserIdentity identity = underTest.create(gson, null, null);
    assertThat(identity.getProviderLogin()).isEqualTo("octocat");
    assertThat(identity.getName()).isEqualTo("monalisa octocat");
    assertThat(identity.getEmail()).isNull();
}
Also used : UserIdentity(org.sonar.api.server.authentication.UserIdentity) Test(org.junit.Test)

Example 15 with UserIdentity

use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.

the class UserIdentityFactoryImplTest method empty_name_is_replaced_by_provider_login.

@Test
public void empty_name_is_replaced_by_provider_login() {
    GsonUser gson = new GsonUser("ABCD", "octocat", "", "octocat@github.com");
    UserIdentity identity = underTest.create(gson, null, null);
    assertThat(identity.getName()).isEqualTo("octocat");
}
Also used : UserIdentity(org.sonar.api.server.authentication.UserIdentity) Test(org.junit.Test)

Aggregations

UserIdentity (org.sonar.api.server.authentication.UserIdentity)18 Test (org.junit.Test)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Source (org.sonar.server.authentication.event.AuthenticationEvent.Source)5 IdentityProvider (org.sonar.api.server.authentication.IdentityProvider)4 MockResponse (okhttp3.mockwebserver.MockResponse)3 OAuth2IdentityProvider (org.sonar.api.server.authentication.OAuth2IdentityProvider)3 UserDto (org.sonar.db.user.UserDto)3 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)3 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)2 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)2 UserDetails (org.sonar.api.security.UserDetails)1