Skip to content
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 @@ -72,8 +72,12 @@ public Validator createValidator(@NotNull ValidationContext context, @NotNull Va
optionWhitelistedResourcePaths = settings.getOptions().get(OPTION_WHITELISTED_RESOURCE_PATH_PATTERNS);
}

Collection<String> whitelistedResourcePaths =
Optional.ofNullable(optionWhitelistedResourcePaths).map(op -> Arrays.asList(op.split(","))).orElse(Collections.emptyList());
Collection<String> whitelistedResourcePaths =
Optional.ofNullable(optionWhitelistedResourcePaths)
.map(op -> Arrays.stream(op.split(","))
.map(String::trim)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());

try {
whitelistedResourcePaths.stream().forEach(AemClassificationValidatorFactory::validateResourcePathPattern);
Expand Down Expand Up @@ -116,7 +120,7 @@ public int getServiceRanking() {
static Map<ContentClassification, ValidationMessageSeverity> getSeverityPerClassification(@Nullable String option) {
final Map<ContentClassification, ValidationMessageSeverity> severitiesPerClassification;
return Optional.ofNullable(option)
.map(op -> Arrays.asList(op.split(",")))
.map(op -> Arrays.stream(op.split(",")).map(String::trim).collect(Collectors.toList()))
.map(AemClassificationValidatorFactory::parseSeverityClassification)
.orElse(Collections.emptyMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,34 @@ void testCreateValidator() {
Map<String, String> options = new HashMap<>();
options.put("maps", "tccl:valid-classification.map");
// deprecated option for whitelisting
options.put("whitelistedResourcePathsPatterns", "/resourceType1/.*,/resourceType2");
options.put("severitiesPerClassification", "INTERNAL=DEBUG");
options.put("whitelistedResourcePathsPatterns", "/resourceType1/.*,/resourceType2,\n/resourceType3");
options.put("severitiesPerClassification", "INTERNAL=DEBUG,\nINTERNAL_DEPRECATED=INFO");
ValidatorSettings settings = new ValidatorSettingsImpl(false, ValidationMessageSeverity.WARN, options);
MutableContentClassificationMap map = new MutableContentClassificationMapImpl("Simple");
map.put("/test", ContentClassification.INTERNAL_DEPRECATED, "Deprecated");
Collection<String> whiteListedResourceTypes = new LinkedList<>();
whiteListedResourceTypes.add("/resourceType1/.*");
whiteListedResourceTypes.add("/resourceType2");
whiteListedResourceTypes.add("/resourceType3");
Map<ContentClassification, ValidationMessageSeverity> severitiesPerClassification = new HashMap<>();
severitiesPerClassification.put(ContentClassification.INTERNAL, ValidationMessageSeverity.DEBUG);
severitiesPerClassification.put(ContentClassification.INTERNAL_DEPRECATED, ValidationMessageSeverity.INFO);
AemClassificationValidator expectedValidator = new AemClassificationValidator(ValidationMessageSeverity.WARN, new CompositeContentClassificationMap(map), whiteListedResourceTypes, severitiesPerClassification);
Assertions.assertEquals(expectedValidator, factory.createValidator(null, settings));

options = new HashMap<>();
options.put("maps", "tccl:valid-classification.map");
// new option for whitelisting
options.put("whitelistedResourcePathPatterns", "/resourceType1/.*,/resourceType2");
options.put("severitiesPerClassification", "INTERNAL=DEBUG");
options.put("whitelistedResourcePathPatterns", "/resourceType1/.*,/resourceType2,\n/resourceType3");
options.put("severitiesPerClassification", "INTERNAL=DEBUG,\nINTERNAL_DEPRECATED=INFO");
settings = new ValidatorSettingsImpl(false, ValidationMessageSeverity.WARN, options);
Assertions.assertEquals(expectedValidator, factory.createValidator(null, settings));

// test with multiple validation maps including whitespaces in the maps string
options = new HashMap<>();
options.put("maps", "tccl:valid-classification.map,tccl:empty-map-1.map,\n \t tccl:empty-map-2.map");
options.put("whitelistedResourcePathPatterns", "/resourceType1/.*,/resourceType2");
options.put("severitiesPerClassification", "INTERNAL=DEBUG");
options.put("whitelistedResourcePathPatterns", "/resourceType1/.*,/resourceType2,\n/resourceType3");
options.put("severitiesPerClassification", "INTERNAL=DEBUG,\nINTERNAL_DEPRECATED=INFO");
settings = new ValidatorSettingsImpl(false, ValidationMessageSeverity.WARN, options);
ContentClassificationMap emptyMap = new ContentClassificationMapImpl("");
expectedValidator = new AemClassificationValidator(ValidationMessageSeverity.WARN, new CompositeContentClassificationMap(map, emptyMap, emptyMap), whiteListedResourceTypes, severitiesPerClassification);
Expand Down
Loading