Search in sources :

Example 1 with SecHubTimeUnitData

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

the class NetsparkerAdapterV1Test method build_json_for_new_scan_with_max_scan_duration_5_minutes.

/*
     * In Netsparker the max scan duration has to be in hours not minutes. As a
     * result, 5 minutes need to be converter to hours. 5 minutes will be rounded up
     * to one hour (60 minutes), because 1 hour is the minimum possible value for
     * max scan duration in Netsparker.
     */
@Test
public void build_json_for_new_scan_with_max_scan_duration_5_minutes() throws Exception {
    /* prepare */
    SecHubTimeUnitData maxScanDuration = SecHubTimeUnitData.of(5, SecHubTimeUnit.MINUTE);
    when(config.getMaxScanDuration()).thenReturn(maxScanDuration);
    when(config.hasMaxScanDuration()).thenReturn(true);
    /* execute */
    String json = adapterToTest.buildJsonForCreateNewScan(jsonAdapterSupport, config);
    /* test */
    // the minimum scan duration for Netsparker is 1 hour
    String expected = NetsparkerAdapterTestFileSupport.getTestfileSupport().loadTestFile("json/max_duration_one_hour_expected.json");
    assertEquals(expected, json);
}
Also used : SecHubTimeUnitData(com.mercedesbenz.sechub.adapter.SecHubTimeUnitData) Test(org.junit.Test)

Example 2 with SecHubTimeUnitData

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

the class NetsparkerConfigBuilderTest method getMaxScanDuration_returns_builder_value.

@Test
public void getMaxScanDuration_returns_builder_value() {
    /* prepare */
    SecHubTimeUnitData maxScanDuration = SecHubTimeUnitData.of(98, SecHubTimeUnit.MINUTE);
    /* execute */
    NetsparkerAdapterConfig adapterConfig = validConfigAnd().setMaxScanDuration(maxScanDuration).build();
    /* test */
    assertEquals(maxScanDuration, adapterConfig.getMaxScanDuration());
}
Also used : SecHubTimeUnitData(com.mercedesbenz.sechub.adapter.SecHubTimeUnitData) Test(org.junit.Test)

Example 3 with SecHubTimeUnitData

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

the class WebConfigBuilderStrategyTest method webscan_max_scan_duration.

@Test
public void webscan_max_scan_duration() {
    /* prepare */
    WebConfigBuilderStrategy strategyToTest = createStrategy("sechub_config/webscan_max_scan_duration.json");
    TestAbstractWebScanAdapterConfigBuilder configBuilder = new TestAbstractWebScanAdapterConfigBuilder();
    SecHubTimeUnitData expectedMaxScanDuration = SecHubTimeUnitData.of(1, SecHubTimeUnit.HOUR);
    /* execute */
    strategyToTest.configure(configBuilder);
    /* test */
    TestWebScanAdapterConfig result = configBuilder.build();
    SecHubTimeUnitData maxScanDuration = result.getMaxScanDuration();
    assertNotNull(maxScanDuration);
    assertEquals(expectedMaxScanDuration, maxScanDuration);
}
Also used : SecHubTimeUnitData(com.mercedesbenz.sechub.adapter.SecHubTimeUnitData) Test(org.junit.jupiter.api.Test)

Example 4 with SecHubTimeUnitData

use of com.mercedesbenz.sechub.adapter.SecHubTimeUnitData 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 5 with SecHubTimeUnitData

use of com.mercedesbenz.sechub.adapter.SecHubTimeUnitData 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

SecHubTimeUnitData (com.mercedesbenz.sechub.adapter.SecHubTimeUnitData)9 Test (org.junit.Test)6 SecHubTimeUnit (com.mercedesbenz.sechub.commons.model.SecHubTimeUnit)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 Test (org.junit.jupiter.api.Test)1