Search in sources :

Example 11 with UserDto

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

the class UserUpdaterTest method update_only_user_name.

@Test
public void update_only_user_name() {
    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).setName("Marius2"));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getName()).isEqualTo("Marius2");
    // Following fields has not changed
    assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
    assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
    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 12 with UserDto

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

the class UserUpdaterTest method update_external_provider_when_reactivating_user.

@Test
public void update_external_provider_when_reactivating_user() {
    db.users().insertUser(newDisabledUser(DEFAULT_LOGIN).setLocal(true).setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    underTest.create(NewUser.builder().setLogin(DEFAULT_LOGIN).setName("Marius2").setExternalIdentity(new ExternalIdentity("github", "john")).build());
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getExternalIdentity()).isEqualTo("john");
    assertThat(dto.getExternalIdentityProvider()).isEqualTo("github");
    assertThat(dto.isLocal()).isFalse();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 13 with UserDto

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

the class UserUpdaterTest method update_user_with_scm_accounts_containing_blank_entry.

@Test
public void update_user_with_scm_accounts_containing_blank_entry() {
    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).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").setScmAccounts(newArrayList("ma2", "", null)));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 14 with UserDto

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

the class UserUpdaterTest method associate_default_groups_when_reactivating_user.

@Test
public void associate_default_groups_when_reactivating_user() {
    UserDto userDto = db.users().insertUser(newDisabledUser(DEFAULT_LOGIN).setLocal(true).setCreatedAt(PAST).setUpdatedAt(PAST));
    db.organizations().insertForUuid("org1");
    GroupDto groupDto = db.users().insertGroup(GroupTesting.newGroupDto().setName("sonar-devs").setOrganizationUuid("org1"));
    db.users().insertMember(groupDto, userDto);
    createDefaultGroup();
    underTest.create(NewUser.builder().setLogin(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").build());
    session.commit();
    Multimap<String, String> 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) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 15 with UserDto

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

the class UserUpdaterTest method create_user.

@Test
public void create_user() {
    createDefaultGroup();
    UserDto dto = underTest.create(NewUser.builder().setLogin("user").setName("User").setEmail("user@mail.com").setPassword("PASSWORD").setScmAccounts(ImmutableList.of("u1", "u_1", "User 1")).build());
    assertThat(dto.getId()).isNotNull();
    assertThat(dto.getLogin()).isEqualTo("user");
    assertThat(dto.getName()).isEqualTo("User");
    assertThat(dto.getEmail()).isEqualTo("user@mail.com");
    assertThat(dto.getScmAccountsAsList()).containsOnly("u1", "u_1", "User 1");
    assertThat(dto.isActive()).isTrue();
    assertThat(dto.isLocal()).isTrue();
    assertThat(dto.getSalt()).isNotNull();
    assertThat(dto.getCryptedPassword()).isNotNull();
    assertThat(dto.getCreatedAt()).isEqualTo(1418215735482L);
    assertThat(dto.getUpdatedAt()).isEqualTo(1418215735482L);
    assertThat(dbClient.userDao().selectByLogin(session, "user").getId()).isEqualTo(dto.getId());
    List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.INDEX_TYPE_USER);
    assertThat(indexUsers).hasSize(1);
    assertThat(indexUsers.get(0).getSource()).contains(entry("login", "user"), entry("name", "User"), entry("email", "user@mail.com"));
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) 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