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