Search in sources :

Example 66 with GroupDto

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));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Test(org.junit.Test)

Example 67 with GroupDto

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);
}
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 68 with GroupDto

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);
}
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 69 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class PermissionIndexerTest method initializeOnStartup_grants_access_to_user_and_group.

@Test
public void initializeOnStartup_grants_access_to_user_and_group() {
    ComponentDto project = createAndIndexProject();
    UserDto user1 = userDbTester.insertUser();
    UserDto user2 = userDbTester.insertUser();
    GroupDto group = userDbTester.insertGroup();
    userDbTester.insertMember(group, user2);
    userDbTester.insertProjectPermissionOnUser(user1, USER, project);
    userDbTester.insertProjectPermissionOnGroup(group, USER, project);
    indexOnStartup();
    // anonymous
    verifyAnyoneNotAuthorized(project);
    // has direct access
    verifyAuthorized(project, user1);
    // has access through group
    verifyAuthorized(project, user1, group);
    // no access
    verifyNotAuthorized(project, user2);
}
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 70 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class PermissionTemplateServiceTest method would_user_have_scan_permission_with_default_permission_template.

@Test
public void would_user_have_scan_permission_with_default_permission_template() {
    OrganizationDto organization = dbTester.organizations().insert();
    UserDto user = dbTester.users().insertUser();
    GroupDto group = dbTester.users().insertGroup(organization);
    dbTester.users().insertMember(group, user);
    PermissionTemplateDto template = templateDb.insertTemplate(organization);
    dbTester.organizations().setDefaultTemplates(template, null);
    templateDb.addProjectCreatorToTemplate(template.getId(), SCAN_EXECUTION);
    templateDb.addUserToTemplate(template.getId(), user.getId(), UserRole.USER);
    templateDb.addGroupToTemplate(template.getId(), group.getId(), UserRole.CODEVIEWER);
    templateDb.addGroupToTemplate(template.getId(), null, UserRole.ISSUE_ADMIN);
    // authenticated user
    checkWouldUserHaveScanPermission(organization, user.getId(), true);
    // anonymous user
    checkWouldUserHaveScanPermission(organization, null, false);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2