Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commonlib: Add methods to get filename & policy name for PolicyTag tags #5956

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,45 @@
* @since 1.29.0
*/
public enum PolicyTag {
DEV_CICD,
DEV_STD,
DEV_FULL,
QA_STD,
QA_FULL,
SEQUENCE,
API;
DEV_CICD("Dev CICD.policy", "Developer CI/CD", "scanpolicies"),
DEV_STD("Dev Standard.policy", "Developer Standard", "scanpolicies"),
DEV_FULL("Dev Full.policy", "Developer Full", "scanpolicies"),
QA_STD("QA Standard.policy", "QA Standard", "scanpolicies"),
QA_FULL("QA Full.policy", "QA Full", "scanpolicies"),
API("API.policy", "API", "scanpolicies"),

SEQUENCE("Sequence.policy", "Sequence", "sequence");

protected static final String PREFIX = "POLICY_";

private final String tag;
private final String fileName;
private final String policyName;
private final String addonId;

private PolicyTag() {
private PolicyTag(String fileName, String policyName, String addonId) {
this.tag = PREFIX + this.name();
this.fileName = fileName;
this.policyName = policyName;
this.addonId = addonId;
}

public String getTag() {
return this.tag;
}

public String getFileName() {
return fileName;
}

public String getPolicyName() {
return policyName;
}

public String getAddonId() {
return addonId;
}

public static List<String> getAllTags() {
return Stream.of(PolicyTag.values()).map(PolicyTag::getTag).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package org.zaproxy.addon.commonlib;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
Expand All @@ -33,19 +35,31 @@

class PolicyTagUnitTest {

private static final String FILE_EXT = ".policy";
private static final List<String> CURRENT_ADDONS = List.of("scanpolicies", "sequence");

@ParameterizedTest
@EnumSource(PolicyTag.class)
void shouldHaveAllTagsStartingWithPolicyyUnderscoreInCapsEnumNamesWithout(PolicyTag tag) {
// Given / When / Then
assertThat(
tag.name(),
describedAs(
"Enum element name should not start with prefix",
not(startsWith(PolicyTag.PREFIX))));
assertThat(
tag.getTag(),
describedAs(
"Tag should start with expected prefix", is(startsWith(PolicyTag.PREFIX))));
assertThat(
tag.name(),
tag.getFileName(),
describedAs(
"Enum element name should not start with prefix",
not(startsWith(PolicyTag.PREFIX))));
"Enum filenames should all end with '.policy'", is(endsWith(FILE_EXT))));
assertThat(
tag.getAddonId(),
describedAs(
"Enum values should be attributed to expected addons",
is(in(CURRENT_ADDONS))));
}

@Test
Expand Down