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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations