use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_return_users_with_quality_profile_administrator_permission.
@Test
public void selectQualityProfileAdministratorLogins_return_users_with_quality_profile_administrator_permission() {
UserDto user1 = db.users().insertUser(withEmail("user1"));
db.users().insertPermissionOnUser(user1, ADMINISTER_QUALITY_PROFILES);
UserDto user2 = db.users().insertUser(withEmail("user2"));
db.users().insertPermissionOnUser(user2, ADMINISTER_QUALITY_PROFILES);
Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1), globalEmailSubscriberOf(user2));
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedProjectUuids_returns_public_projects_if_permission_USER_or_CODEVIEWER.
@Test
public void keepAuthorizedProjectUuids_returns_public_projects_if_permission_USER_or_CODEVIEWER() {
ComponentDto publicProject = db.components().insertPublicProject();
UserDto user = db.users().insertUser();
// logged-in user
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), user.getUuid(), UserRole.CODEVIEWER)).containsOnly(publicProject.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), user.getUuid(), UserRole.USER)).containsOnly(publicProject.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), user.getUuid(), UserRole.ADMIN)).isEmpty();
// anonymous
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), null, UserRole.CODEVIEWER)).containsOnly(publicProject.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), null, UserRole.USER)).containsOnly(publicProject.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(publicProject.uuid()), null, UserRole.ADMIN)).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method countUsersWithGlobalPermissionExcludingUser.
@Test
public void countUsersWithGlobalPermissionExcludingUser() {
// group g1 has the permission p1 and has members user1 and user2
// user3 has the permission
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
UserDto user3 = db.users().insertUser();
GroupDto group1 = db.users().insertGroup("g1");
db.users().insertPermissionOnGroup(group1, "p1");
db.users().insertPermissionOnGroup(group1, "p2");
db.users().insertMember(group1, user1);
db.users().insertMember(group1, user2);
db.users().insertPermissionOnUser(user3, "p1");
db.users().insertPermissionOnAnyone("p1");
// excluding user1 -> remain user2 and user3
assertThat(underTest.countUsersWithGlobalPermissionExcludingUser(db.getSession(), "p1", user1.getUuid())).isEqualTo(2);
// excluding user3 -> remain the members of group g1
assertThat(underTest.countUsersWithGlobalPermissionExcludingUser(db.getSession(), "p1", user3.getUuid())).isEqualTo(2);
// excluding unknown user
assertThat(underTest.countUsersWithGlobalPermissionExcludingUser(db.getSession(), "p1", "-1")).isEqualTo(3);
// nobody has the permission
assertThat(underTest.countUsersWithGlobalPermissionExcludingUser(db.getSession(), "missingPermission", user1.getUuid())).isZero();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedProjectUuids_filters_projects_authorized_to_logged_in_user_by_direct_permission.
@Test
public void keepAuthorizedProjectUuids_filters_projects_authorized_to_logged_in_user_by_direct_permission() {
ComponentDto privateProject = db.components().insertPrivateProject();
ComponentDto publicProject = db.components().insertPublicProject();
UserDto user = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, privateProject);
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(privateProject.uuid(), publicProject.uuid()), user.getUuid(), UserRole.ADMIN)).containsOnly(privateProject.uuid());
// user does not have the permission "issueadmin"
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(privateProject.uuid(), publicProject.uuid()), user.getUuid(), UserRole.ISSUE_ADMIN)).isEmpty();
}
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_by_group.
@Test
public void keepAuthorizedProjectUuids_returns_public_project_if_user_is_granted_project_permission_by_group() {
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.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getUuid(), randomPermission)).containsOnly(project.uuid());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(otherProject.uuid()), user.getUuid(), randomPermission)).isEmpty();
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), otherUser.getUuid(), randomPermission)).isEmpty();
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, singleton(project.uuid()), user.getUuid(), "another perm")).isEmpty();
}
Aggregations