Skip to content

Commit

Permalink
Separated examples to 2 different enums to fix failing unit test #3521
Browse files Browse the repository at this point in the history
  • Loading branch information
de-jcup committed Dec 5, 2024
1 parent 7203934 commit a78848d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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());

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<PDSTemplateMetaData> result = JSONConverter.get().fromJSONtoListOf(PDSTemplateMetaData.class, json);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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"),

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a78848d

Please sign in to comment.