Search in sources :

Example 11 with CommandLineSettings

use of com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings in project sechub by mercedes-benz.

the class OwaspZapScanConfigurationFactoryTest method context_name_is_created_as_UUID_when_not_defined.

@Test
void context_name_is_created_as_UUID_when_not_defined() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    when(settings.getJobUUID()).thenReturn(null);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    String contextName = result.getContextName();
    assertNotNull(contextName);
    // just check it us a uuid... (otherwise exception)
    UUID.fromString(contextName);
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with CommandLineSettings

use of com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings in project sechub by mercedes-benz.

the class OwaspZapScanConfigurationFactoryTest method created_configuration_has_max_scan_duration_from_sechub_webconfig.

@Test
void created_configuration_has_max_scan_duration_from_sechub_webconfig() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    SecHubWebScanConfiguration config = simulateProvidedSecHubConfiguration(settings);
    long maxScanDueration = 4711L;
    when(sechubWebConfigHelper.fetchMaxScanDurationInMillis(config)).thenReturn(maxScanDueration);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertEquals(result.getMaxScanDurationInMillis(), maxScanDueration);
}
Also used : SecHubWebScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration) CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with CommandLineSettings

use of com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings in project sechub by mercedes-benz.

the class OwaspZapScanConfigurationFactoryTest method fails_when_host_port_or_apikey_not_in_commandline_and_also_not_in_env.

/* @formatter:off*/
@ParameterizedTest
@CsvSource({ "host,4711,", "host,,secret", ",4711,secret" })
/* @formatter:on*/
void fails_when_host_port_or_apikey_not_in_commandline_and_also_not_in_env(String host, Integer port, String apiKey) {
    /* prepare */
    CommandLineSettings settings = mock(CommandLineSettings.class);
    when(settings.getZapHost()).thenReturn(host);
    if (port != null) {
        // when not defined in CSV, null is used. The mock does use int primitive,
        // so we just do not set it.
        when(settings.getZapPort()).thenReturn(port);
    }
    when(settings.getZapApiKey()).thenReturn(apiKey);
    /* execute + test */
    assertThrows(MustExitRuntimeException.class, () -> factoryToTest.create(settings));
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with CommandLineSettings

use of com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings in project sechub by mercedes-benz.

the class OwaspZapScanConfigurationFactoryTest method proxy_set_or_not_is_valid_result_returned_contains_null_as_proxyinformation.

@Test
void proxy_set_or_not_is_valid_result_returned_contains_null_as_proxyinformation() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    when(settings.getProxyHost()).thenReturn(null);
    when(settings.getProxyPort()).thenReturn(0);
    when(environmentVariableReader.readAsString(PROXY_HOST_ENV_VARIABLE_NAME)).thenReturn(null);
    when(environmentVariableReader.readAsInt(PROXY_PORT_ENV_VARIABLE_NAME)).thenReturn(0);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertNotNull(result);
    assertNull(result.getProxyInformation());
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with CommandLineSettings

use of com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings in project sechub by mercedes-benz.

the class OwaspZapScanConfigurationFactoryTest method context_name_is_used_from_settings_when_defined.

@Test
void context_name_is_used_from_settings_when_defined() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    String jobUUID = "12345";
    when(settings.getJobUUID()).thenReturn(jobUUID);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertEquals(result.getContextName(), jobUUID);
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CommandLineSettings (com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Test (org.junit.jupiter.api.Test)8 CsvSource (org.junit.jupiter.params.provider.CsvSource)6 SecHubWebScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration)3 AuthenticationType (com.mercedesbenz.sechub.owaspzapwrapper.config.auth.AuthenticationType)1 File (java.io.File)1 URI (java.net.URI)1 Path (java.nio.file.Path)1