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