Skip to content

Commit

Permalink
Merge pull request #5956 from kingthorin/poltag-convenience2
Browse files Browse the repository at this point in the history
commonlib: Add methods to get filename & policy name for PolicyTag tags
  • Loading branch information
psiinon authored Nov 28, 2024
2 parents 0ef904b + cad33e5 commit 6601642
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
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

0 comments on commit 6601642

Please sign in to comment.