use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method deleteProjectPermissionOfAnyUser_has_no_effect_if_specified_component_has_no_permission_at_all.
@Test
public void deleteProjectPermissionOfAnyUser_has_no_effect_if_specified_component_has_no_permission_at_all() {
UserDto user = insertUser();
db.users().insertPermissionOnUser(user, SCAN);
ComponentDto project = randomPublicOrPrivateProject();
int deletedCount = underTest.deleteProjectPermissionOfAnyUser(dbSession, SCAN.getKey(), project);
assertThat(deletedCount).isZero();
assertThat(underTest.selectGlobalPermissionsOfUser(dbSession, user.getUuid())).containsOnly(SCAN.getKey());
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class UserPermissionDaoTest method deleteGlobalPermission.
@Test
public void deleteGlobalPermission() {
UserDto user1 = insertUser();
UserDto user2 = insertUser();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
addGlobalPermission("perm1", user1);
addGlobalPermission("perm2", user1);
addProjectPermission("perm1", user1, project1);
addProjectPermission("perm3", user2, project1);
addProjectPermission("perm4", user2, project2);
// user2 does not have global permissions -> do nothing
underTest.deleteGlobalPermission(dbSession, user2, "perm1");
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5);
// global permission is not granted -> do nothing
underTest.deleteGlobalPermission(dbSession, user1, "notGranted");
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5);
// permission is on project -> do nothing
underTest.deleteGlobalPermission(dbSession, user1, "perm3");
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5);
// global permission exists -> delete it, but not the project permission with the same name !
underTest.deleteGlobalPermission(dbSession, user1, "perm1");
assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='perm1' and component_uuid is null")).isZero();
assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method countUsersWithGlobalPermissionExcludingGroupMember.
@Test
public void countUsersWithGlobalPermissionExcludingGroupMember() {
// u1 has the direct permission, u2 and u3 have the permission through their group
UserDto u1 = db.users().insertUser();
db.users().insertPermissionOnUser(u1, A_PERMISSION);
db.users().insertPermissionOnGroup(group1, A_PERMISSION);
db.users().insertPermissionOnGroup(group1, "another-permission");
UserDto u2 = db.users().insertUser();
db.users().insertMember(group1, u2);
UserDto u3 = db.users().insertUser();
db.users().insertMember(group1, u3);
// excluding u2 membership --> remain u1 and u3
int count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, A_PERMISSION, group1.getUuid(), u2.getUuid());
assertThat(count).isEqualTo(2);
// excluding unknown memberships
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, A_PERMISSION, group1.getUuid(), MISSING_UUID);
assertThat(count).isEqualTo(3);
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, A_PERMISSION, MISSING_UUID, u2.getUuid());
assertThat(count).isEqualTo(3);
// another permission
count = underTest.countUsersWithGlobalPermissionExcludingGroupMember(dbSession, DOES_NOT_EXIST, group1.getUuid(), u2.getUuid());
assertThat(count).isZero();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedProjectUuids_returns_public_project_if_user_is_granted_project_permission_directly.
@Test
public void keepAuthorizedProjectUuids_returns_public_project_if_user_is_granted_project_permission_directly() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto otherProject = db.components().insertPublicProject();
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, randomPermission, project);
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getUuid(), randomPermission)).isEmpty();
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getUuid(), randomPermission)).isEmpty();
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getUuid(), randomPermission)).containsOnly(project.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getUuid(), "another perm")).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedUsersForRoleAndProject_returns_user_if_granted_project_permission_by_group_on_public_project.
@Test
public void keepAuthorizedUsersForRoleAndProject_returns_user_if_granted_project_permission_by_group_on_public_project() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto otherProject = db.components().insertPublicProject();
UserDto otherUser = db.users().insertUser();
db.users().insertMember(group1, user);
db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getUuid()), randomPermission, project.uuid())).containsOnly(user.getUuid());
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getUuid()), "another perm", project.uuid())).isEmpty();
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getUuid()), randomPermission, otherProject.uuid())).isEmpty();
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(otherUser.getUuid()), randomPermission, project.uuid())).isEmpty();
}
Aggregations