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_private_project.
@Test
public void keepAuthorizedUsersForRoleAndProject_returns_user_if_granted_project_permission_by_group_on_private_project() {
ComponentDto project = db.components().insertPrivateProject();
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();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectGlobalAdministerEmailSubscribers_returns_only_global_administers.
@Test
public void selectGlobalAdministerEmailSubscribers_returns_only_global_administers() {
UserDto user1 = db.users().insertUser(withEmail("user1"));
db.users().insertPermissionOnUser(user1, ADMINISTER);
UserDto user2 = db.users().insertUser(withEmail("user2"));
db.users().insertPermissionOnUser(user2, ADMINISTER);
// user3 is global administer via a group
GroupDto administratorGroup2 = db.users().insertGroup();
db.users().insertPermissionOnGroup(administratorGroup2, ADMINISTER);
UserDto user3 = db.users().insertUser(withEmail("user3"));
db.users().insertMember(administratorGroup2, user3);
// user4 has another global permission via a group
GroupDto administratorGroup3 = db.users().insertGroup();
db.users().insertPermissionOnGroup(administratorGroup3, QUALITY_PROFILE_ADMIN);
UserDto user4 = db.users().insertUser(withEmail("user4"));
db.users().insertMember(administratorGroup3, user4);
ComponentDto project = db.components().insertPrivateProject();
// user5 is only project level administer
UserDto user5 = db.users().insertUser(withEmail("user5"));
// db.users().insertPermissionOnUser(user5, ADMINISTER);
db.users().insertProjectPermissionOnUser(user5, "admin", project);
// user6 has other global permission
UserDto user6 = db.users().insertUser(withEmail("user6"));
db.users().insertPermissionOnUser(user6, ADMINISTER_QUALITY_PROFILES);
// user7 has no permission
db.users().insertUser(withEmail("user7"));
Set<EmailSubscriberDto> subscribers = underTest.selectGlobalAdministerEmailSubscribers(dbSession);
assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1), globalEmailSubscriberOf(user2), globalEmailSubscriberOf(user3));
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method anonymous_should_be_authorized.
@Test
public void anonymous_should_be_authorized() {
ComponentDto project1 = db.components().insertPublicProject();
ComponentDto project2 = db.components().insertPublicProject();
UserDto user1 = db.users().insertUser("u1");
GroupDto group = db.users().insertGroup();
db.users().insertMembers(group, user1);
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project1.uuid(), project2.uuid()), null, UserRole.USER)).containsOnly(project1.uuid(), project2.uuid());
// group does not have the role "admin"
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet(project1.uuid()), null, "admin")).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedProjectUuids_returns_empty_list_if_input_does_not_reference_existing_projects.
@Test
public void keepAuthorizedProjectUuids_returns_empty_list_if_input_does_not_reference_existing_projects() {
ComponentDto publicProject = db.components().insertPublicProject();
UserDto user = db.users().insertUser();
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, newHashSet("does_not_exist"), user.getUuid(), UserRole.USER)).isEmpty();
}
use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method keepAuthorizedUsersForRoleAndProject_does_not_return_user_if_granted_project_permission_by_AnyOne_on_public_project.
@Test
public void keepAuthorizedUsersForRoleAndProject_does_not_return_user_if_granted_project_permission_by_AnyOne_on_public_project() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto otherProject = db.components().insertPublicProject();
UserDto otherUser = db.users().insertUser();
db.users().insertProjectPermissionOnAnyone(randomPermission, project);
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession, singleton(user.getUuid()), randomPermission, project.uuid())).isEmpty();
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