Search in sources :

Example 6 with CommandLineSettings

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

the class OwaspZapScanConfigurationFactoryTest method targetURI_calculated_by_factory_is_in_result.

@Test
void targetURI_calculated_by_factory_is_in_result() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    String targetUri = "https://www.example.com";
    when(settings.getTargetURL()).thenReturn(targetUri);
    URI createdUri = URI.create("https://fromfactory.example.com");
    when(targetUriFactory.create(targetUri)).thenReturn(createdUri);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertEquals(result.getTargetUri(), createdUri);
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) URI(java.net.URI) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with CommandLineSettings

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

the class OwaspZapScanConfigurationFactoryTest method createSettingsMockWithNecessaryParts.

private CommandLineSettings createSettingsMockWithNecessaryParts() {
    CommandLineSettings settings = mock(CommandLineSettings.class);
    when(settings.getZapHost()).thenReturn("https://zaphot.example.com");
    when(settings.getZapPort()).thenReturn(815);
    when(settings.getZapApiKey()).thenReturn("secret-key");
    return settings;
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings)

Example 8 with CommandLineSettings

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

the class OwaspZapScanConfigurationFactoryTest method report_file_from_setting_is_used_in_result.

@Test
void report_file_from_setting_is_used_in_result() {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    Path path = new File("not-existing").toPath();
    when(settings.getReportFile()).thenReturn(path);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertEquals(result.getReportFile(), path);
}
Also used : Path(java.nio.file.Path) CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with CommandLineSettings

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

the class OwaspZapScanConfigurationFactoryTest method result_contains_server_config_with_arguments_from_command_line_settings_no_env_variables.

@ParameterizedTest
@CsvSource({ "https://zaproxy.example.com,8080,api-key,https://proxy.example.com,3333", "host,4711,secret,proxy,5312" })
void result_contains_server_config_with_arguments_from_command_line_settings_no_env_variables(String host, int port, String apiKey, String proxy, int proxyPort) {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    when(settings.getZapHost()).thenReturn(host);
    when(settings.getZapPort()).thenReturn(port);
    when(settings.getZapApiKey()).thenReturn(apiKey);
    when(settings.getProxyHost()).thenReturn(proxy);
    when(settings.getProxyPort()).thenReturn(proxyPort);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    OwaspZapServerConfiguration serverConfig = result.getServerConfig();
    assertNotNull(serverConfig);
    assertEquals(host, serverConfig.getZaproxyHost());
    assertEquals(port, serverConfig.getZaproxyPort());
    assertEquals(apiKey, serverConfig.getZaproxyApiKey());
    assertEquals(proxy, result.getProxyInformation().getHost());
    assertEquals(proxyPort, result.getProxyInformation().getPort());
    verify(environmentVariableReader, never()).readAsInt(any());
    verify(environmentVariableReader, never()).readAsString(any());
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with CommandLineSettings

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

the class OwaspZapScanConfigurationFactoryTest method verbose_from_settings_is_in_result.

@ParameterizedTest
@CsvSource({ "true", "false" })
void verbose_from_settings_is_in_result(boolean verboseEnabled) {
    /* prepare */
    CommandLineSettings settings = createSettingsMockWithNecessaryParts();
    when(settings.isVerboseEnabled()).thenReturn(verboseEnabled);
    /* execute */
    OwaspZapScanConfiguration result = factoryToTest.create(settings);
    /* test */
    assertEquals(result.isVerboseOutput(), verboseEnabled);
}
Also used : CommandLineSettings(com.mercedesbenz.sechub.owaspzapwrapper.cli.CommandLineSettings) CsvSource(org.junit.jupiter.params.provider.CsvSource) 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