Search in sources :

Example 71 with UserDto

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 72 with UserDto

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));
}
Also used : EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 73 with UserDto

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 74 with UserDto

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 75 with UserDto

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41