Search in sources :

Example 11 with ProjectAccessLevel

use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.

the class ProjectAdministrationRestControllerRestDocTest method restdoc_change_project_access_level.

@Test
@UseCaseRestDoc(useCase = UseCaseAdministratorChangesProjectAccessLevel.class)
public void restdoc_change_project_access_level() throws Exception {
    Class<UseCaseAdministratorChangesProjectAccessLevel> useCase = UseCaseAdministratorChangesProjectAccessLevel.class;
    String apiEndpoint = https(PORT_USED).buildAdminChangesProjectAccessLevelUrl(PROJECT_ID.pathElement(), PROJECT_ACCESS_LEVEL.pathElement());
    /* prepare */
    StringBuilder acceptedValues = new StringBuilder();
    acceptedValues.append("Accepted values: ");
    for (Iterator<ProjectAccessLevel> it = Arrays.asList(ProjectAccessLevel.values()).iterator(); it.hasNext(); ) {
        ProjectAccessLevel level = it.next();
        acceptedValues.append(level.getId());
        String description = level.getDescription();
        if (description != null) {
            acceptedValues.append("(");
            acceptedValues.append(description);
            acceptedValues.append(")");
        }
        if (it.hasNext()) {
            acceptedValues.append(", ");
        }
    }
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint, "projectId1", ProjectAccessLevel.READ_ONLY.getId()).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The id for project"), parameterWithName(PROJECT_ACCESS_LEVEL.paramName()).description("The new project access level. " + acceptedValues.toString()))));
/* @formatter:on */
}
Also used : UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 12 with ProjectAccessLevel

use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.

the class ScanProjectConfigAccessLevelService method changeProjectAccessLevel.

public void changeProjectAccessLevel(String projectId, ProjectAccessLevel newAccessLevel, ProjectAccessLevel formerAccessLevel) {
    /* validate */
    notNull(newAccessLevel, "New access level may not be null!");
    projectIdValidation.validate(projectId);
    /* change configuration */
    ProjectAccessLevel configuredAccessLevel = getProjectAccessLevelOrFallback(projectId, formerAccessLevel);
    if (!Objects.equals(formerAccessLevel, configuredAccessLevel)) {
        /*
             * In this case this could be a race condition (two events on nearly same time
             * happening). So we add a warn log entry.
             */
        LOG.warn("Configured access level was in scan domain:'{}' - but given fallback was: '{}'. This should not happen.", configuredAccessLevel, formerAccessLevel);
    }
    scanProjectConfigService.set(projectId, CONFIG_ID_PROJECT_ACCESS_LEVEL, newAccessLevel.getId());
    LOG.info("Changed access level for project:{} to level:{}", projectId, newAccessLevel.getId());
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)

Example 13 with ProjectAccessLevel

use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.

the class ScanMessageHandlerTest method when_sending_message_id_PROJECT_ACCESS_LEVEL_CHANGED_changeProjectAccessLevel_is_called.

@Test
void when_sending_message_id_PROJECT_ACCESS_LEVEL_CHANGED_changeProjectAccessLevel_is_called() {
    /* prepare */
    ProjectAccessLevel newAccessLevel = ProjectAccessLevel.NONE;
    ProjectAccessLevel formerAccessLevel = ProjectAccessLevel.READ_ONLY;
    DomainMessage request = new DomainMessage(MessageID.PROJECT_ACCESS_LEVEL_CHANGED);
    ProjectMessage content = new ProjectMessage();
    content.setProjectId("projectId1");
    content.setFormerAccessLevel(formerAccessLevel);
    content.setNewAccessLevel(newAccessLevel);
    request.set(MessageDataKeys.PROJECT_ACCESS_LEVEL_CHANGE_DATA, content);
    /* execute */
    simulateEventSend(request, messageHandlerToTest);
    /* test */
    verify(messageHandlerToTest.projectAccessLevelService).changeProjectAccessLevel("projectId1", newAccessLevel, formerAccessLevel);
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test)

Example 14 with ProjectAccessLevel

use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.

the class ScanProjectConfigAccessLevelServiceTest method fetchProjectAccessLevel_returns_result_from_scanProjectConfigService_by_getOrCreate.

@Test
void fetchProjectAccessLevel_returns_result_from_scanProjectConfigService_by_getOrCreate() {
    /* prepare */
    ScanProjectConfig config = new ScanProjectConfig(ScanProjectConfigID.PROJECT_ACCESS_LEVEL, PROJECT1);
    config.setData(null);
    when(scanProjectConfigService.getOrCreate(eq(PROJECT1), eq(ScanProjectConfigID.PROJECT_ACCESS_LEVEL), eq(false), any())).thenReturn(config);
    /* part 1: test */
    ProjectAccessLevel result = serviceToTest.fetchProjectAccessLevel(PROJECT1);
    /* test */
    assertNull(result);
    /* part 2: for each level we try out as well */
    for (ProjectAccessLevel level : ProjectAccessLevel.values()) {
        /* execute */
        config.setData(level.getId());
        result = serviceToTest.fetchProjectAccessLevel(PROJECT1);
        /* test */
        assertEquals(level, result);
    }
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) Test(org.junit.jupiter.api.Test)

Example 15 with ProjectAccessLevel

use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.

the class ProjectChangeAccessLevelService method changeProjectAccessLevel.

/* @formatter:off */
@UseCaseAdministratorChangesProjectAccessLevel(@Step(number = 2, name = "Change access level", description = "The service will change the project access level inside administration domain and trigger a change event to inform recipients about the new situation."))
public /* @formatter:on */
void changeProjectAccessLevel(String projectId, ProjectAccessLevel wantedLevel) {
    /* audit */
    auditLogService.log("triggers for project:{} an access level change to '{}'", logSanitizer.sanitize(projectId, 30), wantedLevel);
    /* validate */
    notNull(wantedLevel, "project access level may not be null!");
    assertion.assertIsValidProjectId(projectId);
    Project project = projectRepository.findOrFailProject(projectId);
    ProjectAccessLevel formerAccessLevel = project.getAccessLevel();
    if (wantedLevel.equals(formerAccessLevel)) {
        LOG.info("Access level is already '{}' for project:{}, so cancel operation", formerAccessLevel, project.getId());
        return;
    }
    /* change */
    project.accessLevel = wantedLevel;
    transactionService.saveInOwnTransaction(project);
    /* trigger event */
    sendProjectAccessLevelChangedEvent(project, formerAccessLevel);
}
Also used : UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel)

Aggregations

ProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)15 UseCaseAdministratorChangesProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel)4 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)3 Test (org.junit.jupiter.api.Test)3 IsReceivingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)2 DeveloperAdministration (com.mercedesbenz.sechub.developertools.admin.DeveloperAdministration)1 DeveloperProjectDetailInformation (com.mercedesbenz.sechub.developertools.admin.DeveloperProjectDetailInformation)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)1 Test (org.junit.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1