use of com.mercedesbenz.sechub.adapter.AdapterMetaData in project sechub by mercedes-benz.
the class CheckmarxAdapterTestApplication method main.
public static void main(String[] args) throws Exception {
System.setProperty("log4j.logger.org.apache.http", "ERROR");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "OFF");
dump("https.proxyHost");
dump("https.proxyPort");
dump("https.nonProxyHosts");
dump("http.proxyHost");
dump("http.proxyPort");
dump("http.nonProxyHosts");
dump("javax.net.ssl.keyStore");
dump("javax.net.ssl.trustStore");
String user = ensureProperty("test.sechub.adapter.checkmarx.user");
String password = ensureProperty("test.sechub.adapter.checkmarx.password");
String baseUrl = ensureProperty("test.sechub.adapter.checkmarx.baseurl");
String projectname = ensureProperty("test.sechub.adapter.checkmarx.projectName");
String teamId = ensureProperty("test.sechub.adapter.checkmarx.teamid");
Long presetId = Long.valueOf(ensureProperty("test.sechub.adapter.checkmarx.presetid"));
String pathInOtherProject = ensurePropertyOrDefault("test.sechub.adapter..checkmarx.zipfilename", "zipfile_contains_only_one_simple_java_file.zip");
// "zipfile_contains_only_test1.txt.zip"; // leads to FAILED in queue
// "zipfile_contains_sechub_doc_java.zip"; // should work
File zipFile = CheckmarxTestFileSupport.getTestfileSupport().createFileFromRoot("sechub-other/testsourcecode/" + pathInOtherProject);
/* @formatter:off */
CheckmarxAdapterConfig config = CheckmarxConfig.builder().setUser(user).setProjectId(projectname).setTeamIdForNewProjects(teamId).setPresetIdForNewProjects(presetId).setPasswordOrAPIToken(password).setSourceCodeZipFileInputStream(new FileInputStream(zipFile)).setTrustAllCertificates(true).setProductBaseUrl(baseUrl).build();
/* @formatter:on */
CheckmarxAdapterV1 adapter = new CheckmarxAdapterV1();
String data = adapter.start(config, new AdapterMetaDataCallback() {
@Override
public void persist(AdapterMetaData metaData) {
System.out.println("update metadata:" + metaData);
}
@Override
public AdapterMetaData getMetaDataOrNull() {
return null;
}
});
File file = TestUtil.createTempFileInBuildFolder("checkmarx-adaptertest-result", "xml").toFile();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(data);
fileWriter.close();
System.out.println("-----------------------------------------------------------------------------------------------------------------");
System.out.println("- RESULT:");
System.out.println("-----------------------------------------------------------------------------------------------------------------");
System.out.println(file.getAbsolutePath());
}
use of com.mercedesbenz.sechub.adapter.AdapterMetaData in project sechub by mercedes-benz.
the class CheckmarxAdapterV1WireMockTest method simulate_restart_upload_done_but_no_scan.
@Test
public void simulate_restart_upload_done_but_no_scan() throws Exception {
/* prepare */
AdapterMetaData metadata = new AdapterMetaData();
metadata.setValue(CheckmarxMetaDataID.KEY_FILEUPLOAD_DONE, true);
when(callback.getMetaDataOrNull()).thenReturn(metadata);
LinkedHashMap<String, String> loginResponse = login(3600);
simulateCheckProjectExistsReturnsTrue(loginResponse);
/* no project creation */
/* no upload */
/* scan start */
simulateStartScanAccepted();
simulateWaitForQueingDoneReturns("New");
simulateWaitForQueingDoneReturns("Finished");
simulateCheckScanAvailableReturns("Running");
simulateCheckScanAvailableReturns("Finished");
/* report start */
simulateStartReportCreationWasSuccesful();
simulateWaitForReportResultsReturns("Something");
simulateWaitForReportResultsReturns("Something");
simulateWaitForReportResultsReturns("Created");
/* download report */
simulateDownloadReportSuccesful();
}
use of com.mercedesbenz.sechub.adapter.AdapterMetaData in project sechub by mercedes-benz.
the class CheckmarxAdapterV1WireMockTest method simulate_restart_and_scan_already_exists_and_also_report_exists_and_both_have_finished.
@Test
public void simulate_restart_and_scan_already_exists_and_also_report_exists_and_both_have_finished() throws Exception {
/* prepare */
AdapterMetaData metadata = new AdapterMetaData();
metadata.setValue(CheckmarxMetaDataID.KEY_FILEUPLOAD_DONE, true);
metadata.setValue(CheckmarxMetaDataID.KEY_SCAN_ID, CHECKMARX_SCAN_ID);
metadata.setValue(CheckmarxMetaDataID.KEY_REPORT_ID, CHECKMARX_REPORT_ID);
when(callback.getMetaDataOrNull()).thenReturn(metadata);
LinkedHashMap<String, String> loginResponse = login(3600);
simulateCheckProjectExistsReturnsTrue(loginResponse);
/* no project creation */
/* no upload */
/* no scan start */
simulateWaitForQueingDoneReturns("Finished");
simulateCheckScanAvailableReturns("Finished");
/* no report start */
simulateWaitForReportResultsReturns("Created");
/* download report */
simulateDownloadReportSuccesful();
/* execute */
String result = adapterToTest.start(config, callback);
/* @formatter:on */
/* test */
assertEquals(CONTENT_FROM_CHECKMARX, result);
history.assertAllRememberedUrlsWereRequested();
}
use of com.mercedesbenz.sechub.adapter.AdapterMetaData in project sechub by mercedes-benz.
the class CheckmarxAdapterV1WireMockTest method simulate_restart_scan_already_exists_and_has_finished_but_no_report.
@Test
public void simulate_restart_scan_already_exists_and_has_finished_but_no_report() throws Exception {
/* prepare */
AdapterMetaData metadata = new AdapterMetaData();
metadata.setValue(CheckmarxMetaDataID.KEY_FILEUPLOAD_DONE, true);
metadata.setValue(CheckmarxMetaDataID.KEY_SCAN_ID, CHECKMARX_SCAN_ID);
when(callback.getMetaDataOrNull()).thenReturn(metadata);
LinkedHashMap<String, String> loginResponse = login(3600);
simulateCheckProjectExistsReturnsTrue(loginResponse);
/* no project creation */
/* no upload */
/* no scan start - because reused */
simulateWaitForQueingDoneReturns("Finished");
simulateCheckScanAvailableReturns("Finished");
/* report start */
/* report start */
simulateStartReportCreationWasSuccesful();
simulateWaitForReportResultsReturns("Something");
simulateWaitForReportResultsReturns("Created");
/* download report */
simulateDownloadReportSuccesful();
/* execute */
String result = adapterToTest.start(config, callback);
/* @formatter:on */
/* test */
assertEquals(CONTENT_FROM_CHECKMARX, result);
history.assertAllRememberedUrlsWereRequested();
}
use of com.mercedesbenz.sechub.adapter.AdapterMetaData in project sechub by mercedes-benz.
the class PDSAdapterV1 method handleUploadWhenRequired.
private void handleUploadWhenRequired(PDSContext context, SecHubDataConfigurationType type) throws AdapterException {
PDSAdapterConfig config = context.getConfig();
PDSAdapterConfigData data = config.getPDSAdapterConfigData();
UUID pdsJobUUID = context.getPdsJobUUID();
String secHubTraceId = context.getTraceID();
AdapterMetaData metaData = context.getRuntimeContext().getMetaData();
boolean required = checkRequired(data, type);
if (!required) {
LOG.debug("Skipped {} file upload for pds job:{}, because not required", type, pdsJobUUID);
return;
}
String sourceUploadMetaDataKey = createUploadMetaDataKey(pdsJobUUID, type);
if (metaData.hasValue(sourceUploadMetaDataKey, true)) {
LOG.info("Reuse existing {} upload for pds job: {} - sechub: {}", type, pdsJobUUID, secHubTraceId);
return;
}
LOG.info("Start {} uploading for pds job: {} - sechub: {}", type, pdsJobUUID, secHubTraceId);
String checksum = fetchChecksumOrNull(data, type);
uploadSupport.upload(type, context, data, checksum);
/* after this - mark file upload done - at least for debugging */
metaData.setValue(sourceUploadMetaDataKey, true);
context.getRuntimeContext().getCallback().persist(metaData);
}
Aggregations