Search in sources :

Example 16 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class CreateTemplateActionTest method create_minimalist_permission_template.

@Test
public void create_minimalist_permission_template() throws Exception {
    loginAsAdmin(db.getDefaultOrganization());
    newRequest("Finance", null, null);
    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
    assertThat(finance.getName()).isEqualTo("Finance");
    assertThat(finance.getDescription()).isNullOrEmpty();
    assertThat(finance.getKeyPattern()).isNullOrEmpty();
    assertThat(finance.getUuid()).isNotEmpty();
    assertThat(finance.getCreatedAt().getTime()).isEqualTo(NOW);
    assertThat(finance.getUpdatedAt().getTime()).isEqualTo(NOW);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 17 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class CreateTemplateActionTest method create_full_permission_template.

@Test
public void create_full_permission_template() throws Exception {
    loginAsAdmin(db.getDefaultOrganization());
    TestResponse result = newRequest("Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
    assertJson(result.getInput()).ignoreFields("id").isSimilarTo(getClass().getResource("create_template-example.json"));
    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
    assertThat(finance.getName()).isEqualTo("Finance");
    assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
    assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
    assertThat(finance.getUuid()).isNotEmpty();
    assertThat(finance.getCreatedAt().getTime()).isEqualTo(NOW);
    assertThat(finance.getUpdatedAt().getTime()).isEqualTo(NOW);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) TestResponse(org.sonar.server.ws.TestResponse) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 18 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class DeleteTemplateActionTest method fail_to_delete_by_uuid_if_template_is_default_template_for_view_with_views.

@Test
public void fail_to_delete_by_uuid_if_template_is_default_template_for_view_with_views() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
    db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), template);
    loginAsAdmin(organization);
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("It is not possible to delete the default permission template for views");
    newRequestByUuid(this.underTestWithViews, template.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 19 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.

the class DeleteTemplateActionTest method fail_to_delete_by_name_if_not_admin_without_views.

@Test
public void fail_to_delete_by_name_if_not_admin_without_views() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = db.permissionTemplates().insertTemplate(organization);
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequestByName(underTestWithoutViews, organization.getKey(), template.getName());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 20 with PermissionTemplateDto

use of org.sonar.db.permission.template.PermissionTemplateDto 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

PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)97 Test (org.junit.Test)63 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)42 OrganizationDto (org.sonar.db.organization.OrganizationDto)33 GroupDto (org.sonar.db.user.GroupDto)17 DbSession (org.sonar.db.DbSession)16 UserDto (org.sonar.db.user.UserDto)15 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 InputStream (java.io.InputStream)13 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)12 DefaultTemplates (org.sonar.db.organization.DefaultTemplates)10 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)9 WsPermissions (org.sonarqube.ws.WsPermissions)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)8 PermissionTemplateTesting.newPermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto)7 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)7 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 ComponentDto (org.sonar.db.component.ComponentDto)6 Date (java.util.Date)5