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"));
}
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();
}
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());
}
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());
}
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");
}
Aggregations