Search in sources :

Example 6 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserUpdaterTest method update_only_scm_accounts.

@Test
public void update_only_scm_accounts() {
    db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@lesbronzes.fr").setScmAccounts(asList("ma", "marius33")).setSalt("salt").setCryptedPassword("crypted password").setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setScmAccounts(newArrayList("ma2")));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
    // Following fields has not changed
    assertThat(dto.getName()).isEqualTo("Marius");
    assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
    assertThat(dto.getSalt()).isEqualTo("salt");
    assertThat(dto.getCryptedPassword()).isEqualTo("crypted password");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 7 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserUpdaterTest method reactivate_user_when_creating_user_with_existing_login.

@Test
public void reactivate_user_when_creating_user_with_existing_login() {
    db.users().insertUser(newDisabledUser(DEFAULT_LOGIN).setLocal(false).setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    UserDto dto = underTest.create(NewUser.builder().setLogin(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").build());
    session.commit();
    assertThat(dto.isActive()).isTrue();
    assertThat(dto.getName()).isEqualTo("Marius2");
    assertThat(dto.getEmail()).isEqualTo("marius2@mail.com");
    assertThat(dto.getScmAccounts()).isNull();
    assertThat(dto.isLocal()).isTrue();
    assertThat(dto.getSalt()).isNotNull().isNotEqualTo("79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365");
    assertThat(dto.getCryptedPassword()).isNotNull().isNotEqualTo("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg");
    assertThat(dto.getCreatedAt()).isEqualTo(PAST);
    assertThat(dto.getUpdatedAt()).isEqualTo(NOW);
    assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).isActive()).isTrue();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 8 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserUpdaterTest method remove_scm_accounts.

@Test
public void remove_scm_accounts() {
    db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@lesbronzes.fr").setScmAccounts(asList("ma", "marius33")).setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setScmAccounts(null));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getScmAccounts()).isNull();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 9 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserUpdaterTest method does_not_update_user_when_no_change_and_scm_account_reordered.

@Test
public void does_not_update_user_when_no_change_and_scm_account_reordered() {
    UserDto user = UserTesting.newExternalUser(DEFAULT_LOGIN, "Marius", "marius@email.com").setExternalIdentity("john").setExternalIdentityProvider("github").setScmAccounts(asList("ma1", "ma2")).setCreatedAt(PAST).setUpdatedAt(PAST);
    db.users().insertUser(user);
    createDefaultGroup();
    underTest.update(session, UpdateUser.create(user.getLogin()).setName(user.getName()).setEmail(user.getEmail()).setScmAccounts(asList("ma2", "ma1")).setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalIdentity())));
    session.commit();
    assertThat(dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN).getUpdatedAt()).isEqualTo(PAST);
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 10 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserUpdaterTest method not_associate_default_group_when_updating_user_if_already_existing.

@Test
public void not_associate_default_group_when_updating_user_if_already_existing() {
    UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com"));
    GroupDto defaultGroup = createDefaultGroup();
    db.users().insertMember(defaultGroup, user);
    // User is already associate to the default group
    Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
    assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).as("Current user groups : %s", groups.get(DEFAULT_GROUP)).isTrue();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").setScmAccounts(newArrayList("ma2")));
    session.commit();
    // Nothing as changed
    groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
    assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).isTrue();
}
Also used : UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerException(org.sonar.server.exceptions.ServerException) Multimap(com.google.common.collect.Multimap) TestDefaultOrganizationProvider(org.sonar.server.organization.TestDefaultOrganizationProvider) DbSession(org.sonar.db.DbSession) BadRequestException(org.sonar.server.exceptions.BadRequestException) Collections.singletonList(java.util.Collections.singletonList) Strings(com.google.common.base.Strings) ArgumentCaptor(org.mockito.ArgumentCaptor) OrganizationCreation(org.sonar.server.organization.OrganizationCreation) UserTesting.newDisabledUser(org.sonar.db.user.UserTesting.newDisabledUser) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) GroupTesting(org.sonar.db.user.GroupTesting) Assert.fail(org.junit.Assert.fail) NewUserHandler(org.sonar.api.platform.NewUserHandler) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) SearchHit(org.elasticsearch.search.SearchHit) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserIndexDefinition(org.sonar.server.user.index.UserIndexDefinition) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserTesting.newLocalUser(org.sonar.db.user.UserTesting.newLocalUser) Mockito.verify(org.mockito.Mockito.verify) UserIndexer(org.sonar.server.user.index.UserIndexer) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SQ_AUTHORITY(org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) UserTesting(org.sonar.db.user.UserTesting) MapEntry.entry(org.assertj.core.data.MapEntry.entry) CORE_DEFAULT_GROUP(org.sonar.api.CoreProperties.CORE_DEFAULT_GROUP) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41