Search in sources :

Example 1 with CheckmarxSastScanSettings

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings in project sechub by mercedes-benz.

the class CheckmarxProjectSupportTest method updatePresetIdWhenSetInAdapterConfig_preset_id_set_in_sechub.

@Test
public void updatePresetIdWhenSetInAdapterConfig_preset_id_set_in_sechub() {
    /* prepare */
    long secHubPresetId = 39203;
    long checkmarxPresetId = 1;
    CheckmarxConfigBuilder builder = createBuilderWithMandatoryParamatersSet();
    builder.setPresetIdForNewProjects(secHubPresetId);
    CheckmarxConfig config = builder.build();
    CheckmarxSastScanSettings checkmarxScanSettings = new CheckmarxSastScanSettings();
    checkmarxScanSettings.setPresetId(checkmarxPresetId);
    InternalUpdateContext updateContext = supportToTest.new InternalUpdateContext();
    /* execute */
    supportToTest.updatePresetIdWhenSetInAdapterConfig(config, checkmarxScanSettings, updateContext);
    /* test */
    assertThat(updateContext.isUpdateOfPresetIdNecessary(), is(true));
    assertThat(updateContext.getPresetId(), is(secHubPresetId));
    assertThat(updateContext.isUpdateNecessary(), is(true));
}
Also used : InternalUpdateContext(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport.InternalUpdateContext) CheckmarxConfigBuilder(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig.CheckmarxConfigBuilder) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings) CheckmarxConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig) Test(org.junit.Test)

Example 2 with CheckmarxSastScanSettings

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings in project sechub by mercedes-benz.

the class CheckmarxProjectSupportTest method updatePresetIdWhenSetInAdapterConfig_presetId_sechub_not_set__no_update_necessary.

@Test
public void updatePresetIdWhenSetInAdapterConfig_presetId_sechub_not_set__no_update_necessary() {
    /* prepare */
    long presetId = 443940;
    CheckmarxConfigBuilder builder = createBuilderWithMandatoryParamatersSet();
    builder.setPresetIdForNewProjects(null);
    CheckmarxConfig config = builder.build();
    CheckmarxSastScanSettings checkmarxScanSettings = new CheckmarxSastScanSettings();
    checkmarxScanSettings.setPresetId(presetId);
    InternalUpdateContext updateContext = supportToTest.new InternalUpdateContext();
    /* execute */
    supportToTest.updatePresetIdWhenSetInAdapterConfig(config, checkmarxScanSettings, updateContext);
    /* test */
    assertThat(updateContext.isUpdateOfPresetIdNecessary(), is(false));
    assertThat(updateContext.getPresetId(), is(presetId));
    assertThat(updateContext.isUpdateNecessary(), is(false));
}
Also used : InternalUpdateContext(com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport.InternalUpdateContext) CheckmarxConfigBuilder(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig.CheckmarxConfigBuilder) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings) CheckmarxConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig) Test(org.junit.Test)

Example 3 with CheckmarxSastScanSettings

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method updatePresetIdAndEngineConfigurationIfNecessary.

protected boolean updatePresetIdAndEngineConfigurationIfNecessary(CheckmarxContext context, CheckmarxSessionData sessionData) throws AdapterException {
    boolean updated = false;
    InternalUpdateContext updateContext = new InternalUpdateContext();
    CheckmarxAdapterConfig config = context.getConfig();
    CheckmarxSastScanSettings checkmarxSastScanSettings = fetchCurrentSastScanSettings(context, sessionData);
    List<CheckmarxEngineConfiguration> engineConfigurations = fetchEngineConfigurations(context, sessionData);
    updatePresetIdWhenSetInAdapterConfig(config, checkmarxSastScanSettings, updateContext);
    updateEngineCondfigurationIdWhenSecHubAndCheckmarxDiffer(config, engineConfigurations, checkmarxSastScanSettings, updateContext);
    /* check if the engine configuration needs to be updated */
    if (updateContext.isUpdateNecessary()) {
        LOG.debug("Update scan settings.");
        updateSastScanSettings(context, updateContext.getPresetId(), updateContext.getEngineConfigurationId(), checkmarxSastScanSettings);
        if (updateContext.isUpdateOfPresetIdNecessary()) {
            LOG.debug("Updated preset id {}", updateContext.getPresetId());
        }
        if (updateContext.isUpdateOfEngineConfigurationNecessary()) {
            LOG.debug("Updated engine configuration id {}", updateContext.getEngineConfigurationId());
        }
        updated = true;
    } else {
        LOG.debug("No update necessary.");
    }
    return updated;
}
Also used : CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings) CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)

Example 4 with CheckmarxSastScanSettings

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method extractSastScanSettingsFromGet.

// https://swagger-open-api.herokuapp.com/v1/swagger#/SAST/ScanSettingsV1_1__GetByprojectId
CheckmarxSastScanSettings extractSastScanSettingsFromGet(String json, JSONAdapterSupport support) throws AdapterException {
    Access rootNode = support.fetchRootNode(json);
    CheckmarxSastScanSettings settings = new CheckmarxSastScanSettings();
    settings.setProjectId(rootNode.fetch("project").fetch("id").asLong());
    settings.setPresetId(rootNode.fetch("preset").fetch("id").asLong());
    settings.setEngineConfigurationId(rootNode.fetch("engineConfiguration").fetch("id").asLong());
    return settings;
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)

Example 5 with CheckmarxSastScanSettings

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method fetchCurrentSastScanSettings.

private CheckmarxSastScanSettings fetchCurrentSastScanSettings(CheckmarxContext context, CheckmarxSessionData sessionData) throws AdapterException {
    CheckmarxSastScanSettings settings;
    // project scan settings cannot be defined at creation time.
    // see
    // https://checkmarx.atlassian.net/wiki/spaces/KC/pages/1140555950/CxSAST+REST+API+-+Swagger+Examples+v8.9.0+-+v1.1
    // https://checkmarx.atlassian.net/wiki/spaces/KC/pages/334299447/Get+Scan+Settings+by+Project+Id+-+GET+sast+scanSettings+projectId+v8.7.0+and+up
    MultiValueMap<String, String> headers2 = new LinkedMultiValueMap<>();
    headers2.set("Content-Type", "application/json;v=1.1");
    RestOperations restTemplate2 = context.getRestOperations();
    /* read current setup */
    String fetchScanSettingsURL = context.getAPIURL("sast/scanSettings/" + sessionData.getProjectId());
    ResponseEntity<String> scanSettingsResponse = restTemplate2.getForEntity(fetchScanSettingsURL, String.class);
    settings = extractSastScanSettingsFromGet(scanSettingsResponse.getBody(), context.json());
    return settings;
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RestOperations(org.springframework.web.client.RestOperations) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)

Aggregations

CheckmarxSastScanSettings (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)7 CheckmarxConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig)4 CheckmarxConfigBuilder (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig.CheckmarxConfigBuilder)4 InternalUpdateContext (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport.InternalUpdateContext)4 Test (org.junit.Test)4 CheckmarxEngineConfiguration (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)3 LinkedList (java.util.LinkedList)2 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)1 Access (com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 RestOperations (org.springframework.web.client.RestOperations)1