use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class IssueIndexTest method search_issues_for_batch_return_only_authorized_issues.
@Test
public void search_issues_for_batch_return_only_authorized_issues() {
OrganizationDto org = newOrganizationDto();
ComponentDto project1 = newProjectDto(org);
ComponentDto project2 = newProjectDto(org);
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
GroupDto allowedGroup = newGroupDto();
GroupDto otherGroup = newGroupDto();
// project1 can be seen by allowedGroup
indexIssue(IssueDocTesting.newDoc("ISSUE1", file1));
authorizationIndexerTester.allowOnlyGroup(project1, allowedGroup);
// project3 can be seen by nobody
indexIssue(IssueDocTesting.newDoc("ISSUE3", file2));
userSessionRule.logIn().setGroups(allowedGroup);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project1))).hasSize(1);
userSessionRule.logIn().setGroups(otherGroup);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project2))).isEmpty();
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class OrganizationCreationImplTest method create_creates_default_template_for_new_organization.
@Test
public void create_creates_default_template_for_new_organization() throws OrganizationCreation.KeyConflictException {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
underTest.create(dbSession, SOME_USER_ID, FULL_POPULATED_NEW_ORGANIZATION);
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, FULL_POPULATED_NEW_ORGANIZATION.getKey()).get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization " + FULL_POPULATED_NEW_ORGANIZATION.getName());
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getViewUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(ANYONE_GROUP_ID, UserRole.USER), tuple(ANYONE_GROUP_ID, UserRole.CODEVIEWER));
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class CreateActionTest method request_creates_default_template_for_owner_group_and_anyone.
@Test
public void request_creates_default_template_for_owner_group_and_anyone() {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
UserDto user = dbTester.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
executeRequest("orgFoo");
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "orgfoo").get();
GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
assertThat(defaultTemplate.getName()).isEqualTo("Default template");
assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization orgFoo");
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
assertThat(defaultTemplates.getViewUuid()).isNull();
assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(0, UserRole.USER), tuple(0, UserRole.CODEVIEWER));
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class PermissionIndexerTest method initializeOnStartup_does_not_grant_access_to_anybody.
@Test
public void initializeOnStartup_does_not_grant_access_to_anybody() {
ComponentDto project = createAndIndexProject();
UserDto user = userDbTester.insertUser();
GroupDto group = userDbTester.insertGroup();
indexOnStartup();
verifyAnyoneNotAuthorized(project);
verifyNotAuthorized(project, user);
verifyNotAuthorized(project, user, group);
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class PermissionIndexerTest method initializeOnStartup_grants_access_to_group.
@Test
public void initializeOnStartup_grants_access_to_group() {
ComponentDto project = createAndIndexProject();
UserDto user1 = userDbTester.insertUser();
UserDto user2 = userDbTester.insertUser();
UserDto user3 = userDbTester.insertUser();
GroupDto group1 = userDbTester.insertGroup();
GroupDto group2 = userDbTester.insertGroup();
userDbTester.insertProjectPermissionOnGroup(group1, USER, project);
userDbTester.insertProjectPermissionOnGroup(group2, ADMIN, project);
indexOnStartup();
// anonymous
verifyAnyoneNotAuthorized(project);
// group1 has access
verifyAuthorized(project, user1, group1);
// group2 has not access (only USER permission is accepted)
verifyNotAuthorized(project, user2, group2);
// user3 is not in any group
verifyNotAuthorized(project, user3);
}
Aggregations