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