use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQuery_is_sorted_by_insensitive_name.
@Test
public void selectUserUuidsByQuery_is_sorted_by_insensitive_name() {
UserDto user1 = insertUser(u -> u.setName("user1"));
addGlobalPermission(PROVISIONING, user1);
UserDto user3 = insertUser(u -> u.setName("user3"));
addGlobalPermission(SYSTEM_ADMIN, user3);
UserDto user2 = insertUser(u -> u.setName("User2"));
addGlobalPermission(PROVISIONING, user2);
assertThat(underTest.selectUserUuidsByQuery(dbSession, PermissionQuery.builder().build())).containsExactly(user1.getUuid(), user2.getUuid(), user3.getUuid());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQuery_is_paginated.
@Test
public void selectUserUuidsByQuery_is_paginated() {
List<String> userUuids = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String name = "user-" + i;
UserDto user = insertUser(u -> u.setName(name));
addGlobalPermission(PROVISIONING, user);
addGlobalPermission(SYSTEM_ADMIN, user);
userUuids.add(user.getUuid());
}
assertThat(underTest.selectUserUuidsByQuery(dbSession, PermissionQuery.builder().setPageSize(3).setPageIndex(1).build())).containsExactly(userUuids.get(0), userUuids.get(1), userUuids.get(2));
assertThat(underTest.selectUserUuidsByQuery(dbSession, PermissionQuery.builder().setPageSize(2).setPageIndex(3).build())).containsExactly(userUuids.get(4), userUuids.get(5));
assertThat(underTest.selectUserUuidsByQuery(dbSession, PermissionQuery.builder().setPageSize(50).setPageIndex(1).build())).hasSize(10);
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method deleteProjectPermission.
@Test
public void deleteProjectPermission() {
UserDto user1 = insertUser();
UserDto user2 = insertUser();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
addGlobalPermission("perm", user1);
addProjectPermission("perm", user1, project1);
addProjectPermission("perm", user1, project2);
addProjectPermission("perm", user2, project1);
// no such provision -> ignore
underTest.deleteProjectPermission(dbSession, user1, "anotherPerm", project1);
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
underTest.deleteProjectPermission(dbSession, user1, "perm", project1);
assertThatProjectPermissionDoesNotExist(user1, "perm", project1);
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3);
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase_when_high_number_of_users_for_project_permissions.
@Test
public void selectUserUuidsByQuery_is_ordering_by_users_having_permissions_first_then_by_name_lowercase_when_high_number_of_users_for_project_permissions() {
IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
UserDto user = insertUser(u -> u.setLogin("login" + i).setName("" + i));
// Add global permission to be sure they are excluded
addGlobalPermission(SYSTEM_ADMIN, user);
});
String lastLogin = "login" + (DEFAULT_PAGE_SIZE + 1);
UserDto lastUser = db.getDbClient().userDao().selectByLogin(dbSession, lastLogin);
ComponentDto project = db.components().insertPrivateProject();
db.users().insertProjectPermissionOnUser(lastUser, SCAN.getKey(), project);
PermissionQuery query = PermissionQuery.builder().setComponent(project).build();
assertThat(underTest.selectUserUuidsByQueryAndScope(dbSession, query)).hasSize(DEFAULT_PAGE_SIZE).startsWith(lastUser.getUuid());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedLoginsOnProject_return_correct_users_on_branch.
@Test
public void keepAuthorizedLoginsOnProject_return_correct_users_on_branch() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, c -> c.setBranchType(BranchType.BRANCH));
GroupDto userGroup = db.users().insertGroup("USERS");
GroupDto adminGroup = db.users().insertGroup("ADMIN");
db.users().insertProjectPermissionOnGroup(userGroup, UserRole.USER, project);
db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
// admin with "direct" ADMIN role
UserDto admin1 = db.users().insertUser();
db.users().insertProjectPermissionOnUser(admin1, UserRole.ADMIN, project);
// admin2 with ADMIN role through group
UserDto admin2 = db.users().insertUser();
db.users().insertMember(adminGroup, admin2);
// user1 with "direct" USER role
UserDto user1 = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project);
// user2 with USER role through group
UserDto user2 = db.users().insertUser();
db.users().insertMember(userGroup, user2);
// user without role
UserDto userWithNoRole = db.users().insertUser();
assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), branch.getKey(), UserRole.USER)).isEmpty();
assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), branch.getKey(), UserRole.USER)).containsOnly(user1.getLogin());
Set<String> allLogins = newHashSet(admin1.getLogin(), admin2.getLogin(), user1.getLogin(), user2.getLogin(), userWithNoRole.getLogin());
// Admin does not have the USER permission set
assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.USER)).containsOnly(user1.getLogin(), user2.getLogin());
assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.ADMIN)).containsOnly(admin1.getLogin(), admin2.getLogin());
}
Aggregations