Skip to content

Commit

Permalink
More test cases for bad formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rupert-griffin committed Jul 31, 2024
1 parent ffcc64f commit 9773d7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/main/java/emissary/output/filter/AbstractFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,11 @@ protected void initializeOutputTypes(@Nullable final Configurator config) {
}

protected void initializeDenylist(final Configurator config) {
Pattern charSet = Pattern.compile("^[\\w*]+[\\w*.]*[\\w*]+$"); // Match if acceptable characters are in correct order
Pattern repeatedPeriods = Pattern.compile("\\.\\."); // Match if any sequential `.` characters
Pattern charSetOrdering = Pattern.compile("^[\\w*]+(\\.[\\w*]+)*$"); // Match if acceptable characters are in correct order
Pattern viewNameFormat = Pattern.compile("^\\w+(\\.\\w+)?\\*?$"); // Match if String is word sequence with optional `*` suffix

for (String entry : config.findEntriesAsSet("DENYLIST")) {
if (charSet.matcher(entry).matches() && !repeatedPeriods.matcher(entry).matches()) {
if (charSetOrdering.matcher(entry).matches()) {
String viewName = validateAndRemoveDenylistFiletype(entry);

if (viewName.chars().filter(ch -> ch == '.').count() > 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/emissary/output/filter/AbstractFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void testIncorrectConfigs() {
"type*.*view", "*type.*view", "ty*pe.*view", "*.*view", ".*view", "*view",
"type*.vi*ew", "*type.vi*ew", "ty*pe.vi*ew", "*.vi*ew", ".vi*ew", "vi*ew",
"type*.view*", "*type.view*", "ty*pe.view*", "*.view*", ".view*",
"type.", "*", "type.*", ".", "type.view.", ".type.view", ".type.view.");
"type.", "*", "type.*", ".", "type.view.", ".type.view", ".type.view.",
"type..view", "type.view.view.view", "type.view*.view*", "type.view**", "view**");
for (String entry : invalidEntries) {
final Configurator config = new ServiceConfigGuide();
config.addEntry("DENYLIST", entry);
Expand Down

0 comments on commit 9773d7b

Please sign in to comment.