From a78848d0f209d73d471c677f2c11515738956b0b Mon Sep 17 00:00:00 2001 From: Albert Tregnaghi Date: Thu, 5 Dec 2024 08:29:18 +0100 Subject: [PATCH] Separated examples to 2 different enums to fix failing unit test #3521 --- .../sechub/ExampleFilesValidTest.java | 52 +++++++++++++------ .../sechub/PDSDataExampleFile.java | 18 +++++++ ...File.java => SecHubConfigExampleFile.java} | 5 +- 3 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 sechub-doc/src/test/java/com/mercedesbenz/sechub/PDSDataExampleFile.java rename sechub-doc/src/test/java/com/mercedesbenz/sechub/{ExampleFile.java => SecHubConfigExampleFile.java} (93%) diff --git a/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFilesValidTest.java b/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFilesValidTest.java index 16efbcbd7..eff696a54 100644 --- a/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFilesValidTest.java +++ b/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFilesValidTest.java @@ -11,8 +11,28 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import com.mercedesbenz.sechub.commons.model.*; -import com.mercedesbenz.sechub.commons.model.login.*; +import com.mercedesbenz.sechub.commons.model.ClientCertificateConfiguration; +import com.mercedesbenz.sechub.commons.model.HTTPHeaderConfiguration; +import com.mercedesbenz.sechub.commons.model.JSONConverter; +import com.mercedesbenz.sechub.commons.model.JSONConverterException; +import com.mercedesbenz.sechub.commons.model.SecHubDataConfiguration; +import com.mercedesbenz.sechub.commons.model.SecHubScanConfiguration; +import com.mercedesbenz.sechub.commons.model.SecHubSourceDataConfiguration; +import com.mercedesbenz.sechub.commons.model.SecHubTimeUnit; +import com.mercedesbenz.sechub.commons.model.SecHubWebScanApiConfiguration; +import com.mercedesbenz.sechub.commons.model.SecHubWebScanApiType; +import com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration; +import com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration; +import com.mercedesbenz.sechub.commons.model.login.Action; +import com.mercedesbenz.sechub.commons.model.login.ActionType; +import com.mercedesbenz.sechub.commons.model.login.BasicLoginConfiguration; +import com.mercedesbenz.sechub.commons.model.login.EncodingType; +import com.mercedesbenz.sechub.commons.model.login.FormLoginConfiguration; +import com.mercedesbenz.sechub.commons.model.login.Page; +import com.mercedesbenz.sechub.commons.model.login.Script; +import com.mercedesbenz.sechub.commons.model.login.TOTPHashAlgorithm; +import com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration; +import com.mercedesbenz.sechub.commons.model.login.WebLoginTOTPConfiguration; import com.mercedesbenz.sechub.commons.model.template.TemplateType; import com.mercedesbenz.sechub.commons.pds.PDSDefaultParameterKeyConstants; import com.mercedesbenz.sechub.commons.pds.data.PDSTemplateMetaData; @@ -66,8 +86,8 @@ void check_pds_config_example1_can_be_loaded_and_is_valid() throws Exception { } @ParameterizedTest - @EnumSource(ExampleFile.class) - void every_sechub_config_file_is_valid(ExampleFile file) { + @EnumSource(SecHubConfigExampleFile.class) + void every_sechub_config_file_is_valid(SecHubConfigExampleFile file) { /* prepare */ String json = TestFileReader.readTextFromFile(file.getPath()); SecHubScanConfiguration config = null; @@ -84,10 +104,10 @@ void every_sechub_config_file_is_valid(ExampleFile file) { } @ParameterizedTest - @EnumSource(value = ExampleFile.class, names = { "WEBSCAN_ANONYMOUS", "WEBSCAN_BASIC_AUTH", "WEBSCAN_FORM_BASED_SCRIPT_AUTH", + @EnumSource(value = SecHubConfigExampleFile.class, names = { "WEBSCAN_ANONYMOUS", "WEBSCAN_BASIC_AUTH", "WEBSCAN_FORM_BASED_SCRIPT_AUTH", "WEBSCAN_OPENAPI_WITH_DATA_REFERENCE", "WEBSCAN_HEADER_SCAN", "WEBSCAN_CLIENT_CERTIFICATE", "WEBSCAN_FORM_BASED_SCRIPT_AUTH_WITH_TOTP" }, mode = EnumSource.Mode.INCLUDE) - void every_sechub_config_webscan_file_is_valid_and_has_a_target_uri(ExampleFile file) { + void every_sechub_config_webscan_file_is_valid_and_has_a_target_uri(SecHubConfigExampleFile file) { /* prepare */ String json = TestFileReader.readTextFromFile(file.getPath()); @@ -105,7 +125,7 @@ void every_sechub_config_webscan_file_is_valid_and_has_a_target_uri(ExampleFile @Test void webscan_anonymous_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_ANONYMOUS.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_ANONYMOUS.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -124,7 +144,7 @@ void webscan_anonymous_can_be_read_and_contains_expected_config() { @Test void webscan_basic_auth_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_BASIC_AUTH.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_BASIC_AUTH.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -147,7 +167,7 @@ void webscan_basic_auth_can_be_read_and_contains_expected_config() { @Test void webscan_form_based_script_auth_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_FORM_BASED_SCRIPT_AUTH.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_FORM_BASED_SCRIPT_AUTH.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -171,7 +191,7 @@ void webscan_form_based_script_auth_can_be_read_and_contains_expected_config() { @Test void webscan_openapi_with_data_reference_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_OPENAPI_WITH_DATA_REFERENCE.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_OPENAPI_WITH_DATA_REFERENCE.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -188,7 +208,7 @@ void webscan_openapi_with_data_reference_can_be_read_and_contains_expected_confi @Test void webscan_client_certificate_with_data_reference_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_CLIENT_CERTIFICATE_WITH_OPENAPI.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_CLIENT_CERTIFICATE_WITH_OPENAPI.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -208,7 +228,7 @@ void webscan_client_certificate_with_data_reference_can_be_read_and_contains_exp @Test void webscan_client_certificate_with_openapi_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_CLIENT_CERTIFICATE.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_CLIENT_CERTIFICATE.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -225,7 +245,7 @@ void webscan_client_certificate_with_openapi_can_be_read_and_contains_expected_c @Test void webscan_header_scan_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_HEADER_SCAN.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_HEADER_SCAN.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -253,7 +273,7 @@ void webscan_header_scan_can_be_read_and_contains_expected_config() { @Test void webscan_header_from_data_reference_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_HEADER_FROM_DATA_REFERENCE.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_HEADER_FROM_DATA_REFERENCE.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -286,7 +306,7 @@ void webscan_header_from_data_reference_can_be_read_and_contains_expected_config @Test void webscan_form_based_script_auth_with_totp_can_be_read_and_contains_expected_config() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.WEBSCAN_FORM_BASED_SCRIPT_AUTH_WITH_TOTP.getPath()); + String json = TestFileReader.readTextFromFile(SecHubConfigExampleFile.WEBSCAN_FORM_BASED_SCRIPT_AUTH_WITH_TOTP.getPath()); /* execute */ SecHubScanConfiguration config = SecHubScanConfiguration.createFromJSON(json); @@ -316,7 +336,7 @@ void webscan_form_based_script_auth_with_totp_can_be_read_and_contains_expected_ @Test void pds_param_template_metadata_array_syntax_example_is_valid() { /* prepare */ - String json = TestFileReader.readTextFromFile(ExampleFile.PDS_PARAM_TEMPLATE_META_DATA_SYNTAX.getPath()); + String json = TestFileReader.readTextFromFile(PDSDataExampleFile.PDS_PARAM_TEMPLATE_META_DATA_SYNTAX.getPath()); /* execute */ List result = JSONConverter.get().fromJSONtoListOf(PDSTemplateMetaData.class, json); diff --git a/sechub-doc/src/test/java/com/mercedesbenz/sechub/PDSDataExampleFile.java b/sechub-doc/src/test/java/com/mercedesbenz/sechub/PDSDataExampleFile.java new file mode 100644 index 000000000..b4dc4be87 --- /dev/null +++ b/sechub-doc/src/test/java/com/mercedesbenz/sechub/PDSDataExampleFile.java @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +package com.mercedesbenz.sechub; + +public enum PDSDataExampleFile { + + PDS_PARAM_TEMPLATE_META_DATA_SYNTAX("src/docs/asciidoc/documents/shared/snippet/pds-param-template-metadata-syntax.json"); + ; + + private String path; + + private PDSDataExampleFile(String path) { + this.path = path; + } + + public String getPath() { + return path; + } +} diff --git a/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFile.java b/sechub-doc/src/test/java/com/mercedesbenz/sechub/SecHubConfigExampleFile.java similarity index 93% rename from sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFile.java rename to sechub-doc/src/test/java/com/mercedesbenz/sechub/SecHubConfigExampleFile.java index 55e691b30..95ae92228 100644 --- a/sechub-doc/src/test/java/com/mercedesbenz/sechub/ExampleFile.java +++ b/sechub-doc/src/test/java/com/mercedesbenz/sechub/SecHubConfigExampleFile.java @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT package com.mercedesbenz.sechub; -public enum ExampleFile { +public enum SecHubConfigExampleFile { DATA_SECTION_EXAMPLE_1("src/docs/asciidoc/documents/shared/configuration/sechub_config_data_section_general_example1.json"), @@ -41,12 +41,11 @@ public enum ExampleFile { WEBSCAN_FORM_BASED_SCRIPT_AUTH_WITH_TOTP("src/docs/asciidoc/documents/shared/configuration/sechub_config_example21_webscan_login_form_with_totp.json"), - PDS_PARAM_TEMPLATE_META_DATA_SYNTAX("src/docs/asciidoc/documents/shared/snippet/pds-param-template-metadata-syntax.json"); ; private String path; - private ExampleFile(String path) { + private SecHubConfigExampleFile(String path) { this.path = path; }