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