Search in sources :

Example 6 with AdapterMetaData

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());
}
Also used : AdapterMetaDataCallback(com.mercedesbenz.sechub.adapter.AdapterMetaDataCallback) FileWriter(java.io.FileWriter) File(java.io.File) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) FileInputStream(java.io.FileInputStream)

Example 7 with AdapterMetaData

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();
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) Test(org.junit.Test)

Example 8 with AdapterMetaData

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();
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) Test(org.junit.Test)

Example 9 with AdapterMetaData

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();
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) Test(org.junit.Test)

Example 10 with AdapterMetaData

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);
}
Also used : UUID(java.util.UUID) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Aggregations

AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)26 Test (org.junit.Test)10 UUID (java.util.UUID)8 File (java.io.File)5 AssertFullScanData (com.mercedesbenz.sechub.integrationtest.api.AssertFullScanData)4 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)3 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)3 ExecutionResult (com.mercedesbenz.sechub.integrationtest.internal.SecHubClientExecutor.ExecutionResult)3 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 InputStream (java.io.InputStream)3 HttpEntity (org.springframework.http.HttpEntity)3 AdapterMetaDataCallback (com.mercedesbenz.sechub.adapter.AdapterMetaDataCallback)2 TreeMap (java.util.TreeMap)2 HttpHeaders (org.springframework.http.HttpHeaders)2 RestOperations (org.springframework.web.client.RestOperations)2 SecHubTimeUnitData (com.mercedesbenz.sechub.adapter.SecHubTimeUnitData)1 CheckmarxScanSupport (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxScanSupport)1 CheckmarxUploadSupport (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxUploadSupport)1 NetsparkerConfigBuilder (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerConfig.NetsparkerConfigBuilder)1