RED-9869: allow java.text and find ruleIdentifiers with whitespaces/linebreaks
This commit is contained in:
parent
9dbf5c479f
commit
1b67ea1068
@ -45,7 +45,7 @@ public class DroolsValidationService {
|
||||
private final KieContainerCreationService kieContainerCreationService;
|
||||
private final DeprecatedElementsFinder deprecatedElementsFinder;
|
||||
private static final Pattern allowedImportsPattern = Pattern.compile(
|
||||
"^(?:import\\s+static\\s+)?(?:import\\s+)?(?:com\\.knecon\\.fforesight|com\\.iqser\\.red|java\\.util)\\..*;$");
|
||||
"^(?:import\\s+static\\s+)?(?:import\\s+)?(?:com\\.knecon\\.fforesight|com\\.iqser\\.red|java\\.util|java\\.text)\\..*;$");
|
||||
public static final String LINEBREAK_MATCHER = "\\R";
|
||||
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ import lombok.experimental.UtilityClass;
|
||||
public class RuleFileParser {
|
||||
|
||||
private final static Pattern ruleIdentifierInCodeFinder = Pattern.compile(
|
||||
"\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)\\s*\\(\"([a-zA-Z0-9]+.\\d+.\\d+)\",.*(?:, .*)?\\)");
|
||||
"\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)\\s*\\(\\s*\"([a-zA-Z0-9]+.\\d+.\\d+)\"\\s*,\\s*.*(?:\\s*,\\s*.*)\\s*?\\)");
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@ -78,7 +78,8 @@ public class RuleFileParser {
|
||||
.map(GlobalDescr::getLine)
|
||||
.orElse(0),
|
||||
allQueries,
|
||||
ruleClasses, customDroolsValidation);
|
||||
ruleClasses,
|
||||
customDroolsValidation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -361,7 +361,6 @@ class DroolsValidationServiceTest {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void testRulesWithBlacklistedKeyword() {
|
||||
@ -379,16 +378,16 @@ class DroolsValidationServiceTest {
|
||||
String rulesString1 = rulesString.substring(0, indexGlobalStart) + importTenantContext + rulesString.substring(indexGlobalStart);
|
||||
|
||||
String evilRulePart1 = """
|
||||
|
||||
|
||||
//------------------------------------ All the evil rules ------------------------------------
|
||||
|
||||
|
||||
// Rule unit: EV.1
|
||||
rule "EV.1.0: Remove duplicate FileAttributes but also do very evil things"
|
||||
salience 999
|
||||
when
|
||||
$fileAttribute: FileAttribute($label: label, $value: value)
|
||||
$duplicate: FileAttribute(this != $fileAttribute, label == $label, value == $value)
|
||||
""";
|
||||
""";
|
||||
String evilRulePart2 = """
|
||||
then
|
||||
retract($duplicate);
|
||||
@ -408,11 +407,13 @@ class DroolsValidationServiceTest {
|
||||
.forEach(System.out::println);
|
||||
assertFalse(droolsValidation.isCompiled());
|
||||
assertEquals(2, droolsValidation.getBlacklistErrorMessages().size());
|
||||
assertEquals(1, droolsValidation.getBlacklistErrorMessages()
|
||||
assertEquals(1,
|
||||
droolsValidation.getBlacklistErrorMessages()
|
||||
.get(0).getBlacklistedKeywords().size());
|
||||
assertTrue(droolsValidation.getBlacklistErrorMessages()
|
||||
.get(0).getBlacklistedKeywords().contains("TenantContext"));
|
||||
assertEquals(2, droolsValidation.getBlacklistErrorMessages()
|
||||
assertEquals(2,
|
||||
droolsValidation.getBlacklistErrorMessages()
|
||||
.get(1).getBlacklistedKeywords().size());
|
||||
assertTrue(droolsValidation.getBlacklistErrorMessages()
|
||||
.get(1).getBlacklistedKeywords().contains("TenantContext"));
|
||||
@ -429,14 +430,39 @@ class DroolsValidationServiceTest {
|
||||
.forEach(System.out::println);
|
||||
assertFalse(droolsValidation2.isCompiled());
|
||||
assertEquals(2, droolsValidation2.getBlacklistErrorMessages().size());
|
||||
assertEquals(1, droolsValidation2.getBlacklistErrorMessages()
|
||||
assertEquals(1,
|
||||
droolsValidation2.getBlacklistErrorMessages()
|
||||
.get(0).getBlacklistedKeywords().size());
|
||||
assertTrue(droolsValidation2.getBlacklistErrorMessages()
|
||||
.get(0).getBlacklistedKeywords().contains("TenantContext"));
|
||||
assertEquals(1, droolsValidation2.getBlacklistErrorMessages()
|
||||
assertEquals(1,
|
||||
droolsValidation2.getBlacklistErrorMessages()
|
||||
.get(1).getBlacklistedKeywords().size());
|
||||
assertTrue(droolsValidation2.getBlacklistErrorMessages()
|
||||
.get(1).getBlacklistedKeywords().contains("System."));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void assertRuleIdentifierDoesNotMatch() {
|
||||
|
||||
String ruleString = RuleManagementResources.getBaseRuleFileString() + """
|
||||
rule "CBI.0.0: Redact CBI Authors (non vertebrate Study)"
|
||||
when
|
||||
not FileAttribute(label == "Vertebrate Study", value soundslike "Yes" || value.toLowerCase() == "y")
|
||||
$entity: TextEntity(type() == "CBI_author", dictionaryEntry)
|
||||
then
|
||||
$entity.redact(
|
||||
"CBI.1.0",
|
||||
"Author found",
|
||||
"Article 39(e)(3) of Regulation (EC) No 178/2002"
|
||||
);
|
||||
end
|
||||
""";
|
||||
|
||||
RuleFileBluePrint ruleFileBluePrint = RuleFileParser.buildBluePrintFromRulesString(ruleString);
|
||||
|
||||
assertFalse(ruleFileBluePrint.getDroolsValidation().isCompiled());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user