Search in sources :

Example 11 with AdapterMetaData

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

the class AbstractMockedAdapter method assertMetaDataHandledAsExpected.

protected void assertMetaDataHandledAsExpected(C config, AdapterRuntimeContext runtimeContext) {
    AdapterMetaData metaData = assertMetaData(runtimeContext);
    metaData.setValue(KEY_METADATA_BEFORE_WAIT, DEFAULT_METADATA_MOCK_BEFORE_WAIT);
    String combined = metaData.getValue(KEY_METADATA_COMBINED);
    String initial = metaData.getValue(KEY_METADATA_INITIAL);
    String before = metaData.getValue(KEY_METADATA_BEFORE_WAIT);
    if (!"1+2".equals(combined)) {
        throw new IllegalStateException("meta data for combined value was not as expected ,but:" + combined);
    }
    if (!DEFAULT_METADATA_MOCK_INITIAL_VALUE.equals(initial)) {
        throw new IllegalStateException("meta data for initial value was not as expected ,but:" + initial);
    }
    if (!DEFAULT_METADATA_MOCK_BEFORE_WAIT.equals(before)) {
        throw new IllegalStateException("meta data for before value was not as expected ,but:" + before);
    }
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Example 12 with AdapterMetaData

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

the class AdapterMetaDataConverterTest method values_transformed_to_string_are_transformed_back_correctly.

@Test
public void values_transformed_to_string_are_transformed_back_correctly() {
    /* prepare */
    AdapterMetaData metaData = new AdapterMetaData();
    metaData.setValue("key1", "value1");
    metaData.setValue("sub1.key2", "value1.2");
    /* execute */
    String text = converterToTest.convertToJSONOrNull(metaData);
    AdapterMetaData metaDataback = converterToTest.convertToMetaDataOrNull(text);
    /* test */
    assertEquals("value1", metaDataback.getValue("key1"));
    assertEquals("value1.2", metaDataback.getValue("sub1.key2"));
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) Test(org.junit.Test)

Example 13 with AdapterMetaData

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

the class ProductExecutorContextTest method formerResults_1_result_with_metadata__results_in_metadata_from_callback_getMetaDataOrNull.

@Test
public void formerResults_1_result_with_metadata__results_in_metadata_from_callback_getMetaDataOrNull() {
    /* prepare */
    AdapterMetaData metaData = new AdapterMetaData();
    when(callback.getMetaDataOrNull()).thenReturn(metaData);
    /* execute */
    AdapterMetaData result = contextToTest.getCurrentMetaDataOrNull();
    /* test */
    verify(callback).getMetaDataOrNull();
    assertEquals(result, metaData);
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) Test(org.junit.Test)

Example 14 with AdapterMetaData

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

the class ProductExecutorContext method useFirstFormerResultHavingMetaData.

public void useFirstFormerResultHavingMetaData(String key, String value) {
    LOG.debug("use first former result with key:{},value:{}", key, value);
    AdapterMetaDataConverter metaDataConverter = callback.getMetaDataConverter();
    for (ProductResult result : formerResults) {
        if (result == null) {
            continue;
        }
        String metaDataString = result.getMetaData();
        AdapterMetaData metaDataOrNull = metaDataConverter.convertToMetaDataOrNull(metaDataString);
        if (metaDataOrNull != null && metaDataOrNull.hasValue(key, value)) {
            callback.setCurrentProductResult(result);
            return;
        }
    }
    /* not found - ensure null */
    callback.setCurrentProductResult(null);
}
Also used : AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Example 15 with AdapterMetaData

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

the class NetsparkerAdapterTestApplication method main.

public static void main(String[] args) throws Exception {
    SecHubTimeUnitData maxScanDuration = null;
    String maxScanDurationDurationProperty = getSystemProperty("sechub.adapter.netsparker.maxscanduration.duration");
    String maxScanDurationUnitProperty = getSystemProperty("sechub.adapter.netsparker.maxscanduration.unit");
    if (maxScanDurationDurationProperty != null && maxScanDurationUnitProperty != null) {
        int duration = Integer.valueOf(maxScanDurationDurationProperty);
        SecHubTimeUnit unit = SecHubTimeUnit.valueOf(maxScanDurationUnitProperty);
        maxScanDuration = SecHubTimeUnitData.of(duration, unit);
    }
    /* @formatter:off */
    NetsparkerConfigBuilder builder = NetsparkerConfig.builder().setUser(getSystemProperty("sechub.adapter.netsparker.user")).setTrustAllCertificates(getSystemPropertyBooleanOrFalse("sechub.adapter.netsparker.trustall")).setAgentGroupName(getSystemProperty("sechub.adapter.netsparker.user.agent.groupname")).setPasswordOrAPIToken(getSystemProperty("sechub.adapter.netsparker.apitoken")).setPolicyID(getSystemProperty("sechub.adapter.netsparker.policyid")).setProductBaseUrl(getSystemProperty("sechub.adapter.netsparker.baseurl")).setLicenseID(getSystemProperty("sechub.adapter.netsparker.licenseid", "none")).setTargetURI(new URI(getSystemProperty("sechub.adapter.netsparker.targeturi"))).setMaxScanDuration(maxScanDuration);
    /* @formatter:on */
    String loginType = getSystemProperty("sechub.adapter.netsparker.login.type", "<none>");
    if ("basic".equalsIgnoreCase(loginType)) {
        handleBasicLogin(builder);
    } else if ("formAutodetect".equalsIgnoreCase(loginType)) {
        handleFormAutodetect(builder);
    } else if ("formScript".equalsIgnoreCase(loginType)) {
        handleFormScript(builder);
    } else if ("<none>".equalsIgnoreCase(loginType)) {
    /* ignore */
    } else {
        throw new IllegalArgumentException("login type:" + loginType + " not supported!");
    }
    NetsparkerAdapterConfig config = builder.build();
    NetsparkerAdapter netsparker = new NetsparkerAdapterV1();
    String result = netsparker.start(config, new AdapterMetaDataCallback() {

        AdapterMetaData metaData;

        @Override
        public void persist(AdapterMetaData metaData) {
            System.out.println("persist:" + metaData);
            this.metaData = metaData;
        }

        @Override
        public AdapterMetaData getMetaDataOrNull() {
            return metaData;
        }
    });
    System.out.println("result:");
    System.out.println(result);
}
Also used : NetsparkerConfigBuilder(com.mercedesbenz.sechub.adapter.netsparker.NetsparkerConfig.NetsparkerConfigBuilder) SecHubTimeUnitData(com.mercedesbenz.sechub.adapter.SecHubTimeUnitData) URI(java.net.URI) AdapterMetaDataCallback(com.mercedesbenz.sechub.adapter.AdapterMetaDataCallback) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData) SecHubTimeUnit(com.mercedesbenz.sechub.commons.model.SecHubTimeUnit)

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