Search in sources :

Example 1 with UserDto

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

the class UserUpdaterTest method update_user.

@Test
public void update_user() {
    UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com").setScmAccounts(asList("ma", "marius33")).setSalt("79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365").setCryptedPassword("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg").setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").setScmAccounts(newArrayList("ma2")));
    session.commit();
    UserDto updatedUser = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(updatedUser.isActive()).isTrue();
    assertThat(updatedUser.getName()).isEqualTo("Marius2");
    assertThat(updatedUser.getEmail()).isEqualTo("marius2@mail.com");
    assertThat(updatedUser.getScmAccountsAsList()).containsOnly("ma2");
    assertThat(updatedUser.getSalt()).isNotEqualTo(user.getSalt());
    assertThat(updatedUser.getCryptedPassword()).isNotEqualTo(user.getCryptedPassword());
    assertThat(updatedUser.getCreatedAt()).isEqualTo(PAST);
    assertThat(updatedUser.getUpdatedAt()).isEqualTo(NOW);
    List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.INDEX_TYPE_USER);
    assertThat(indexUsers).hasSize(1);
    assertThat(indexUsers.get(0).getSource()).contains(entry("login", DEFAULT_LOGIN), entry("name", "Marius2"), entry("email", "marius2@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)

Example 2 with UserDto

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

the class DeactivateActionTest method deactivate_user_and_delete_his_related_data.

@Test
public void deactivate_user_and_delete_his_related_data() throws Exception {
    UserDto user = insertUser(newUserDto().setLogin("ada.lovelace").setEmail("ada.lovelace@noteg.com").setName("Ada Lovelace").setScmAccounts(singletonList("al")));
    logInAsSystemAdministrator();
    String json = deactivate(user.getLogin()).getInput();
    // scm accounts, groups and email are deleted
    assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString());
    assertThat(index.getNullableByLogin(user.getLogin()).active()).isFalse();
    verifyThatUserIsDeactivated(user.getLogin());
    assertThat(dbClient.userTokenDao().selectByLogin(dbSession, user.getLogin())).isEmpty();
    assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId().intValue()).build(), dbSession)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 3 with UserDto

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

the class DeactivateActionTest method fail_to_deactivate_last_administrator_of_default_organization.

@Test
public void fail_to_deactivate_last_administrator_of_default_organization() throws Exception {
    UserDto admin = createUser();
    db.users().insertPermissionOnUser(admin, ADMINISTER);
    logInAsSystemAdministrator();
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("User is last administrator, and cannot be deactivated");
    deactivate(admin.getLogin());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 4 with UserDto

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

the class DeactivateActionTest method fail_to_deactivate_last_administrator_of_organization.

@Test
public void fail_to_deactivate_last_administrator_of_organization() throws Exception {
    // user1 is the unique administrator of org1 and org2.
    // user1 and user2 are both administrators of org3
    UserDto user1 = createUser();
    OrganizationDto org1 = db.organizations().insert(newOrganizationDto().setKey("org1"));
    OrganizationDto org2 = db.organizations().insert(newOrganizationDto().setKey("org2"));
    OrganizationDto org3 = db.organizations().insert(newOrganizationDto().setKey("org3"));
    db.users().insertPermissionOnUser(org1, user1, SYSTEM_ADMIN);
    db.users().insertPermissionOnUser(org2, user1, SYSTEM_ADMIN);
    db.users().insertPermissionOnUser(org3, user1, SYSTEM_ADMIN);
    UserDto user2 = createUser();
    db.users().insertPermissionOnUser(org3, user2, SYSTEM_ADMIN);
    logInAsSystemAdministrator();
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("User is last administrator of organizations [org1, org2], and cannot be deactivated");
    deactivate(user1.getLogin());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) OrganizationTesting.newOrganizationDto(org.sonar.db.organization.OrganizationTesting.newOrganizationDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 5 with UserDto

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

the class UserUpdaterTest method update_scm_accounts_with_same_values.

@Test
public void update_scm_accounts_with_same_values() {
    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(newArrayList("ma", "marius33")));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
}
Also used : 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