use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method countUsersWithGlobalPermissionExcludingUserPermission.
@Test
public void countUsersWithGlobalPermissionExcludingUserPermission() {
// u1 and u2 have the direct permission, u3 has the permission through his group
UserDto u1 = db.users().insertUser();
db.users().insertPermissionOnUser(u1, A_PERMISSION);
UserDto u2 = db.users().insertUser();
db.users().insertPermissionOnUser(u2, A_PERMISSION);
db.users().insertPermissionOnGroup(group1, A_PERMISSION);
UserDto u3 = db.users().insertUser();
db.users().insertMember(group1, u3);
// excluding u2 permission --> remain u1 and u3
int count = underTest.countUsersWithGlobalPermissionExcludingUserPermission(dbSession, A_PERMISSION, u2.getUuid());
assertThat(count).isEqualTo(2);
// excluding unknown user
count = underTest.countUsersWithGlobalPermissionExcludingUserPermission(dbSession, A_PERMISSION, MISSING_UUID);
assertThat(count).isEqualTo(3);
// another permission
count = underTest.countUsersWithGlobalPermissionExcludingUserPermission(dbSession, DOES_NOT_EXIST, u2.getUuid());
assertThat(count).isZero();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_does_not_return_non_quality_profile_administrator.
@Test
public void selectQualityProfileAdministratorLogins_does_not_return_non_quality_profile_administrator() {
UserDto user1 = db.users().insertUser(withEmail("user1"));
db.users().insertPermissionOnUser(user1, ADMINISTER);
db.users().insertUser(withoutEmail("user2"));
Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
assertThat(subscribers).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method group_should_be_authorized.
@Test
public void group_should_be_authorized() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
ComponentDto project3 = db.components().insertPrivateProject();
UserDto user1 = db.users().insertUser("u1");
GroupDto group = db.users().insertGroup();
db.users().insertMembers(group, user1);
db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project1);
db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project2);
db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project3);
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid(), project3.uuid()), user1.getUuid(), UserRole.USER)).containsOnly(project2.uuid(), project3.uuid());
// group does not have the role "admin"
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project2.uuid(), project3.uuid()), user1.getUuid(), UserRole.ADMIN)).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_does_not_return_quality_profile_administrator_without_email.
@Test
public void selectQualityProfileAdministratorLogins_does_not_return_quality_profile_administrator_without_email() {
UserDto user1NoEmail = db.users().insertUser(withoutEmail("user1NoEmail"));
db.users().insertPermissionOnUser(user1NoEmail, ADMINISTER_QUALITY_PROFILES);
UserDto user1WithEmail = db.users().insertUser(withEmail("user1WithEmail"));
db.users().insertPermissionOnUser(user1WithEmail, ADMINISTER_QUALITY_PROFILES);
GroupDto qualityProfileAdministratorGroup1 = db.users().insertGroup();
db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup1, ADMINISTER_QUALITY_PROFILES);
UserDto user2NoEmail = db.users().insertUser(withoutEmail("user2NoEmail"));
db.users().insertMember(qualityProfileAdministratorGroup1, user2NoEmail);
UserDto user2WithEmail = db.users().insertUser(withEmail("user2WithEmail"));
db.users().insertMember(qualityProfileAdministratorGroup1, user2WithEmail);
GroupDto qualityProfileAdministratorGroup2 = db.users().insertGroup();
db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup2, ADMINISTER_QUALITY_PROFILES);
UserDto user3NoEmail = db.users().insertUser(withoutEmail("user3NoEmail"));
db.users().insertMember(qualityProfileAdministratorGroup2, user3NoEmail);
UserDto user3WithEmail = db.users().insertUser(withEmail("user3WithEmail"));
db.users().insertMember(qualityProfileAdministratorGroup2, user3WithEmail);
UserDto user4NoEmail = db.users().insertUser(withoutEmail("user4NoEmail"));
db.users().insertPermissionOnUser(user4NoEmail, ADMINISTER_QUALITY_PROFILES);
UserDto user4WithEmail = db.users().insertUser(withEmail("user4WithEmail"));
db.users().insertPermissionOnUser(user4WithEmail, ADMINISTER_QUALITY_PROFILES);
UserDto user5NoEmail = db.users().insertUser(withoutEmail("user5NoEmail"));
db.users().insertPermissionOnUser(user5NoEmail, ADMINISTER_QUALITY_PROFILES);
UserDto user5WithEmail = db.users().insertUser(withEmail("user5WithEmail"));
db.users().insertPermissionOnUser(user5WithEmail, ADMINISTER_QUALITY_PROFILES);
db.users().insertUser(withoutEmail("user6NoEmail"));
db.users().insertUser(withEmail("user6WithEmail"));
Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1WithEmail), globalEmailSubscriberOf(user2WithEmail), globalEmailSubscriberOf(user3WithEmail), globalEmailSubscriberOf(user4WithEmail), globalEmailSubscriberOf(user5WithEmail));
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectUserUuidsWithGlobalPermission.
@Test
public void selectUserUuidsWithGlobalPermission() {
// 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();
db.users().insertPermissionOnGroup(group1, ADMINISTER);
db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
db.users().insertMember(group1, user1);
db.users().insertMember(group1, user2);
db.users().insertPermissionOnUser(user3, ADMINISTER);
db.users().insertPermissionOnAnyone(ADMINISTER);
assertThat(underTest.selectUserUuidsWithGlobalPermission(db.getSession(), ADMINISTER.getKey())).containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid(), user3.getUuid());
assertThat(underTest.selectUserUuidsWithGlobalPermission(db.getSession(), PROVISION_PROJECTS.getKey())).containsExactlyInAnyOrder(user1.getUuid(), user2.getUuid());
}
Aggregations