Search in sources :

Example 6 with SecHubTimeUnit

use of com.mercedesbenz.sechub.commons.model.SecHubTimeUnit in project sechub by mercedes-benz.

the class WebConfigBuilderStrategy method handleMaxScanDuration.

private <B extends AbstractWebScanAdapterConfigBuilder<B, ?>> void handleMaxScanDuration(B configBuilder, SecHubWebScanConfiguration webscanConfig) {
    Optional<WebScanDurationConfiguration> optMaxScanDuration = webscanConfig.getMaxScanDuration();
    if (!optMaxScanDuration.isPresent()) {
        return;
    }
    int duration = optMaxScanDuration.get().getDuration();
    SecHubTimeUnit unit = optMaxScanDuration.get().getUnit();
    SecHubTimeUnitData maxScanDuration = SecHubTimeUnitData.of(duration, unit);
    configBuilder.setMaxScanDuration(maxScanDuration);
}
Also used : WebScanDurationConfiguration(com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration) SecHubTimeUnitData(com.mercedesbenz.sechub.adapter.SecHubTimeUnitData) SecHubTimeUnit(com.mercedesbenz.sechub.commons.model.SecHubTimeUnit)

Example 7 with SecHubTimeUnit

use of com.mercedesbenz.sechub.commons.model.SecHubTimeUnit 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)

Example 8 with SecHubTimeUnit

use of com.mercedesbenz.sechub.commons.model.SecHubTimeUnit in project sechub by mercedes-benz.

the class SecHubWebScanConfigurationHelper method fetchMaxScanDurationInMillis.

public long fetchMaxScanDurationInMillis(SecHubWebScanConfiguration sechubWebConfig) {
    if (!sechubWebConfig.getMaxScanDuration().isPresent()) {
        return DEFAULT_MAX_SCAN_DURATION;
    }
    SecHubTimeUnit sechubTimeUnit = sechubWebConfig.getMaxScanDuration().get().getUnit();
    int maxScanDuration = sechubWebConfig.getMaxScanDuration().get().getDuration();
    switch(sechubTimeUnit) {
        case DAY:
            return maxScanDuration * DAYS_IN_MS;
        case HOUR:
            return maxScanDuration * HOURS_IN_MS;
        case MINUTE:
            return maxScanDuration * MINUTES_IN_MS;
        case SECOND:
            return maxScanDuration * SECONDS_IN_MS;
        case MILLISECOND:
            return maxScanDuration;
        default:
            return DEFAULT_MAX_SCAN_DURATION;
    }
}
Also used : SecHubTimeUnit(com.mercedesbenz.sechub.commons.model.SecHubTimeUnit)

Example 9 with SecHubTimeUnit

use of com.mercedesbenz.sechub.commons.model.SecHubTimeUnit in project sechub by mercedes-benz.

the class SecHubTimeUnitTest method from_json_second.

@ParameterizedTest
@ValueSource(strings = { "\"SECOND\"", "\"second\"", "\"seconds\"", "\"SECONDS\"" })
public void from_json_second(String json) throws JsonMappingException, JsonProcessingException {
    /* prepare */
    ObjectMapper objectMapper = new ObjectMapper();
    /* execute */
    SecHubTimeUnit unit = objectMapper.readValue(json, SecHubTimeUnit.class);
    /* test */
    assertEquals(SecHubTimeUnit.SECOND, unit);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SecHubTimeUnit(com.mercedesbenz.sechub.commons.model.SecHubTimeUnit) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with SecHubTimeUnit

use of com.mercedesbenz.sechub.commons.model.SecHubTimeUnit in project sechub by mercedes-benz.

the class SecHubTimeUnitTest method get_multiplicator_milliseconds__get_millisecond.

@Test
public void get_multiplicator_milliseconds__get_millisecond() {
    /* execute */
    SecHubTimeUnit unit = SecHubTimeUnit.MILLISECOND;
    /* test */
    assertNotNull(unit);
    assertEquals(1, unit.getMultiplicatorMilliseconds());
}
Also used : SecHubTimeUnit(com.mercedesbenz.sechub.commons.model.SecHubTimeUnit) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SecHubTimeUnit (com.mercedesbenz.sechub.commons.model.SecHubTimeUnit)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 SecHubTimeUnitData (com.mercedesbenz.sechub.adapter.SecHubTimeUnitData)2 Test (org.junit.jupiter.api.Test)2 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)1 AdapterMetaDataCallback (com.mercedesbenz.sechub.adapter.AdapterMetaDataCallback)1 NetsparkerConfigBuilder (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerConfig.NetsparkerConfigBuilder)1 WebScanDurationConfiguration (com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration)1 URI (java.net.URI)1