use of com.mercedesbenz.sechub.owaspzapwrapper.scan.OwaspZapScan in project sechub by mercedes-benz.
the class OwaspZapScanExecutorTest method the_result_from_resolver_returned_is_executed.
@Test
void the_result_from_resolver_returned_is_executed() throws Exception {
/* prepare */
OwaspZapScanConfiguration scanConfig = mock(OwaspZapScanConfiguration.class);
ClientApi clientApi = mock(ClientApi.class);
URI targetUri = new URI("http://www.example.com");
when(scanConfig.getTargetUri()).thenReturn(targetUri);
OwaspZapScan scan = mock(OwaspZapScan.class);
when(resolver.resolveScanImplementation(eq(scanConfig), any())).thenReturn(scan);
when(clientApiFactory.create(scanConfig.getServerConfig())).thenReturn(clientApi);
when(connectionChecker.isTargetReachable(targetUri, null)).thenReturn(true);
/* execute */
executorToTest.execute(scanConfig);
/* test */
verify(connectionChecker).isTargetReachable(targetUri, null);
verify(clientApiFactory).create(scanConfig.getServerConfig());
verify(resolver).resolveScanImplementation(scanConfig, clientApi);
verify(scan).scan();
}
use of com.mercedesbenz.sechub.owaspzapwrapper.scan.OwaspZapScan in project sechub by mercedes-benz.
the class OwaspZapScanResolverTest method http_basic_authentication_scan_is_resolved_correctly.
@Test
void http_basic_authentication_scan_is_resolved_correctly() {
/* prepare */
OwaspZapScanConfiguration scanConfig = mock(OwaspZapScanConfiguration.class);
when(scanConfig.getAuthenticationType()).thenReturn(AuthenticationType.HTTP_BASIC_AUTHENTICATION);
ClientApi clientApi = mock(ClientApi.class);
/* execute */
OwaspZapScan scan = resolverToTest.resolveScanImplementation(scanConfig, clientApi);
/* test */
assertTrue(scan instanceof HTTPBasicAuthScan);
}
use of com.mercedesbenz.sechub.owaspzapwrapper.scan.OwaspZapScan in project sechub by mercedes-benz.
the class OwaspZapScanResolver method resolveScanImplementation.
public OwaspZapScan resolveScanImplementation(OwaspZapScanConfiguration scanConfig, ClientApi clientApi) {
LOG.info("Resolve scan implementation.");
OwaspZapScan scan;
AuthenticationType authenticationType = scanConfig.getAuthenticationType();
if (authenticationType == null) {
throw new MustExitRuntimeException("No matching scan type could be found.", MustExitCode.AUTHENTICATIONTYPE_CONFIGURATION_INVALID);
}
switch(authenticationType) {
case UNAUTHENTICATED:
scan = new UnauthenticatedScan(clientApi, scanConfig);
LOG.info("Using unauthenticated scan");
break;
case HTTP_BASIC_AUTHENTICATION:
scan = new HTTPBasicAuthScan(clientApi, scanConfig);
LOG.info("Using http basic authentication scan");
break;
default:
throw new MustExitRuntimeException("No matching scan type could be found.", MustExitCode.AUTHENTICATIONTYPE_CONFIGURATION_INVALID);
}
return scan;
}
use of com.mercedesbenz.sechub.owaspzapwrapper.scan.OwaspZapScan in project sechub by mercedes-benz.
the class OwaspZapScanExecutorTest method target_is_not_reachable_throws_mustexitruntimeexception.
@Test
void target_is_not_reachable_throws_mustexitruntimeexception() throws Exception {
/* prepare */
OwaspZapScanConfiguration scanConfig = mock(OwaspZapScanConfiguration.class);
ClientApi clientApi = mock(ClientApi.class);
URI targetUri = new URI("http://www.my-url.com");
when(scanConfig.getTargetUri()).thenReturn(targetUri);
OwaspZapScan scan = mock(OwaspZapScan.class);
when(resolver.resolveScanImplementation(eq(scanConfig), any())).thenReturn(scan);
when(clientApiFactory.create(scanConfig.getServerConfig())).thenReturn(clientApi);
when(connectionChecker.isTargetReachable(targetUri, null)).thenReturn(false);
/* execute + test */
assertThrows(MustExitRuntimeException.class, () -> executorToTest.execute(scanConfig));
verify(connectionChecker).isTargetReachable(targetUri, null);
verify(scan, never()).scan();
verify(clientApiFactory, never()).create(scanConfig.getServerConfig());
verify(resolver, never()).resolveScanImplementation(scanConfig, clientApi);
}
use of com.mercedesbenz.sechub.owaspzapwrapper.scan.OwaspZapScan in project sechub by mercedes-benz.
the class OwaspZapScanResolverTest method unauthenticated_scan_is_resolved_correctly.
@Test
void unauthenticated_scan_is_resolved_correctly() {
/* prepare */
OwaspZapScanConfiguration scanConfig = mock(OwaspZapScanConfiguration.class);
when(scanConfig.getAuthenticationType()).thenReturn(AuthenticationType.UNAUTHENTICATED);
ClientApi clientApi = mock(ClientApi.class);
/* execute */
OwaspZapScan scan = resolverToTest.resolveScanImplementation(scanConfig, clientApi);
/* test */
assertTrue(scan instanceof UnauthenticatedScan);
}
Aggregations