Repository: mercedes-benz/sechub
Issue: OWASP ZAP Wrapper OpenApi Scanning exits because missing condition

### Situation
During the implementation of the open api scanning there was a misunterstanding regarding the data section part on my side. I thought the ENV variable:
`PDS_JOB_EXTRACTED_SOURCES_FOLDER` on PDS side will only be set if there are sources extracted to the PDS. I relied on this condition, but this is not enough.

### Solution
Check if the data section was found, otherwise assume no API definition was uploaded.

Changed files:
sechub-wrapper-owasp-zap/src/test/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProviderTest.java
sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/OwaspZapScanConfigurationFactory.java
sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProvider.java

diff --git a/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProvider.java b/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProvider.java
index 15ef0fde2..d77d6184b 100644
--- a/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProvider.java
+++ b/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProvider.java
@@ -5,12 +5,16 @@ import java.io.File;
 import java.nio.file.Path;
 import java.util.List;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.mercedesbenz.sechub.commons.model.SecHubScanConfiguration;
 import com.mercedesbenz.sechub.commons.model.SecHubSourceDataConfiguration;
 import com.mercedesbenz.sechub.owaspzapwrapper.cli.ZapWrapperExitCode;
 import com.mercedesbenz.sechub.owaspzapwrapper.cli.ZapWrapperRuntimeException;
 
 public class ApiDefinitionFileProvider {
+    private static final Logger LOG = LoggerFactory.getLogger(ApiDefinitionFileProvider.class);
 
     /**
      *
@@ -21,19 +25,22 @@ public class ApiDefinitionFileProvider {
      *
      * @param extractedSourcesFolderPath
      * @param sechubConfig
-     * @return Path to API definition file
+     * @return Path to API definition file or <code>null</code> if parameters are
+     *         null or no data section is found
      */
     public Path fetchApiDefinitionFile(String extractedSourcesFolderPath, SecHubScanConfiguration sechubConfig) {
         if (extractedSourcesFolderPath == null) {
-            throw new ZapWrapperRuntimeException("Sources folder must not be null!", ZapWrapperExitCode.EXECUTION_FAILED);
+            LOG.info("Extracted sources folder path env variable was not set.");
+            return null;
         }
         if (sechubConfig == null) {
-            throw new ZapWrapperRuntimeException("SecHub scan config must not be null!", ZapWrapperExitCode.EXECUTION_FAILED);
+            LOG.info("SecHub scan configuration was not set.");
+            return null;
         }
 
         if (!sechubConfig.getData().isPresent()) {
-            throw new ZapWrapperRuntimeException("Data section should not be empty since a sources folder was found.",
-                    ZapWrapperExitCode.SECHUB_CONFIGURATION_INVALID);
+            LOG.info("No data section was found. Continuing without searching for API definition.");
+            return null;
         }
 
         List<SecHubSourceDataConfiguration> sourceData = sechubConfig.getData().get().getSources();
diff --git a/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/OwaspZapScanConfigurationFactory.java b/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/OwaspZapScanConfigurationFactory.java
index c28b4180d..902a967fc 100644
--- a/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/OwaspZapScanConfigurationFactory.java
+++ b/sechub-wrapper-owasp-zap/src/main/java/com/mercedesbenz/sechub/owaspzapwrapper/config/OwaspZapScanConfigurationFactory.java
@@ -184,12 +184,9 @@ public class OwaspZapScanConfigurationFactory {
     }
 
     private Path createPathToApiDefinitionFileOrNull(SecHubScanConfiguration sechubScanConfig) {
-        // use the extracted sources folder path if sources where uploaded and extracted
-        // on the PDS
+        // use the extracted sources folder path, where all text files are uploaded and
+        // extracted
         String extractedSourcesFolderPath = environmentVariableReader.readAsString(EnvironmentVariableConstants.PDS_JOB_EXTRACTED_SOURCES_FOLDER);
-        if (extractedSourcesFolderPath == null) {
-            return null;
-        }
         return apiDefinitionFileProvider.fetchApiDefinitionFile(extractedSourcesFolderPath, sechubScanConfig);
     }
 }
diff --git a/sechub-wrapper-owasp-zap/src/test/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProviderTest.java b/sechub-wrapper-owasp-zap/src/test/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProviderTest.java
index 8e1a880a9..b47a42595 100644
--- a/sechub-wrapper-owasp-zap/src/test/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProviderTest.java
+++ b/sechub-wrapper-owasp-zap/src/test/java/com/mercedesbenz/sechub/owaspzapwrapper/config/ApiDefinitionFileProviderTest.java
@@ -22,38 +22,35 @@ class ApiDefinitionFileProviderTest {
     private ApiDefinitionFileProvider providerToTest = new ApiDefinitionFileProvider();;
 
     @Test
-    void sources_folder_is_null_results_in_must_exit_exception() {
-        /* execute + test */
-        ZapWrapperRuntimeException exception = assertThrows(ZapWrapperRuntimeException.class,
-                () -> providerToTest.fetchApiDefinitionFile(null, new SecHubScanConfiguration()));
+    void sources_folder_is_null_results_in_null_as_api_file_path() {
+        /* execute */
+        Path result = providerToTest.fetchApiDefinitionFile(null, new SecHubScanConfiguration());
 
-        assertEquals("Sources folder must not be null!", exception.getMessage());
-        assertEquals(ZapWrapperExitCode.EXECUTION_FAILED, exception.getExitCode());
+        /* test */
+        assertEquals(null, result);
     }
 
     @Test
-    void sechub_scan_config_is_null_results_in_must_exit_exception() {
-        /* execute + test */
-        ZapWrapperRuntimeException exception = assertThrows(ZapWrapperRuntimeException.class,
-                () -> providerToTest.fetchApiDefinitionFile("/example/path/to/extracted/sources", null));
+    void sechub_scan_config_is_null_results_in_null_as_api_file_path() {
+        /* execute */
+        Path result = providerToTest.fetchApiDefinitionFile("/example/path/to/extracted/sources", null);
 
-        assertEquals("SecHub scan config must not be null!", exception.getMessage());
-        assertEquals(ZapWrapperExitCode.EXECUTION_FAILED, exception.getExitCode());
+        /* test */
+        assertEquals(null, result);
     }
 
     @Test
-    void missing_data_section_part_results_in_zap_wrapper_runtime_exception() {
+    void missing_data_section_part_results_in_null_as_api_file_path() {
         /* prepare */
         String sechubScanConfigJSON = "{\\"apiVersion\\":\\"1.0\\","
                 + "\\"webScan\\":{\\"uri\\":\\"https://localhost:8443\\",\\"api\\":{\\"type\\":\\"openApi\\",\\"use\\":[\\"open-api-file-reference\\"]}}}";
         SecHubScanConfiguration sechubScanConfiguration = SecHubScanConfiguration.createFromJSON(sechubScanConfigJSON);
 
-        /* execute + test */
-        ZapWrapperRuntimeException exception = assertThrows(ZapWrapperRuntimeException.class,
-                () -> providerToTest.fetchApiDefinitionFile("/example/path/to/extracted/sources", sechubScanConfiguration));
+        /* execute */
+        Path result = providerToTest.fetchApiDefinitionFile("/example/path/to/extracted/sources", sechubScanConfiguration);
 
-        assertEquals("Data section should not be empty since a sources folder was found.", exception.getMessage());
-        assertEquals(ZapWrapperExitCode.SECHUB_CONFIGURATION_INVALID, exception.getExitCode());
+        /* test */
+        assertEquals(null, result);
     }
 
     @ParameterizedTest