Skip to content

Commit

Permalink
Never emit validation errors for default config
Browse files Browse the repository at this point in the history
Add IT to verify this behaviour described in the readme
This closes #2
  • Loading branch information
kwin committed Dec 10, 2024
1 parent 217a230 commit a3ca7ed
Show file tree
Hide file tree
Showing 23 changed files with 332 additions and 55 deletions.
24 changes: 24 additions & 0 deletions src/it/no-config/application-package/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>application-package</artifactId>
<packaging>content-package</packaging>
<parent>
<groupId>biz.netcentric.filevault.validator.aem.namespace.it</groupId>
<artifactId>no-config</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<configuration>
<packageType>mixed</packageType><!-- due to oak index -->
<allowIndexDefinitions>true</allowIndexDefinitions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/mytenant">
</filter>
<filter root="/oak:index/mytenant-custom-1">
</filter>
</workspaceFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:oak="http://jackrabbit.apache.org/oak/ns/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="nt:unstructured"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="oak:QueryIndexDefinition"
type="lucene"
async="async"
compatibilityMode="cloud"
evaluatePathRestrictions="{Boolean}true"
reindex="{Boolean}false"
includedPaths="[/content/mytenant/something]">
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Page">
<jcr:content
jcr:primaryType="cq:PageContent"
sling:configPropertyInherit="{Boolean}false"
enabled="{Boolean}true"/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[mytenant-librarya,mytenant-libraryb]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Folder"
sling:resourceType="/apps/othertenant/components/component2"
sling:resourceSuperType="/apps/othertenant/components/component1"/>
Empty file.
23 changes: 23 additions & 0 deletions src/it/no-config/container-package/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>container-package</artifactId>
<packaging>content-package</packaging>
<parent>
<groupId>biz.netcentric.filevault.validator.aem.namespace.it</groupId>
<artifactId>no-config</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<configuration>
<packageType>container</packageType>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/mytenant/config">
</filter>
</workspaceFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"myproperty1": "myvalue1",
"myproperty2": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"myproperty1": "myvalue1",
"myproperty2": 2
}
27 changes: 27 additions & 0 deletions src/it/no-config/content-package/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>content-package</artifactId>
<packaging>content-package</packaging>
<parent>
<groupId>biz.netcentric.filevault.validator.aem.namespace.it</groupId>
<artifactId>no-config</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<configuration>
<packageType>content</packageType>
<properties>
<installhook.test.class>my.custom.Hook</installhook.test.class>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/home/users/mytenant">
</filter>
<filter root="/conf/mytenant">
</filter>
</workspaceFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:lastModified="{Date}2024-05-13T13:00:57.908+02:00"
cq:lastModifiedBy="admin"
jcr:primaryType="cq:PageContent"
jcr:title="new segment"
sling:resourceType="/apps/mytenant2/components/segment-page"
segmentBoost="{Long}0"
segmentName="new-segment">
</jcr:content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="rep:User"
jcr:uuid="2205dd08-d7c3-3d26-8bf8-ac538edd4bc2"
rep:authorizableId="mytenant-myuser"
rep:password="\{SHA-256}e106977a40196b0e-1000-e6d77348c0f254143bf7e42646eba07784770044e3d98dc63677c95ad0af24d3"
rep:principalName="mytenant-myuser">
</jcr:root>
3 changes: 3 additions & 0 deletions src/it/no-config/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.debug = false
invoker.buildResult = success
invoker.goals = clean verify -fae -e
111 changes: 111 additions & 0 deletions src/it/no-config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>biz.netcentric.filevault.validator.aem.namespace.it</groupId>
<artifactId>no-config</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<failOnDuplicateEntries>false</failOnDuplicateEntries>
<filterSource>src/main/META-INF/vault/filter.xml</filterSource>
<validatorsSettings>
<jackrabbit-filter>
<!-- define additional valid roots which are always provided in AEM -->
<options>
<validRoots>/,/libs,/apps,/oak:index,/etc,/var,/tmp,/conf,/content,/content/campaigns,/content/cq:tags,/content/dam,/content/experience-fragments,/content/projects,/content/screens,/etc/packages,/home/users</validRoots>
<severityForUncoveredAncestorNodes>DEBUG</severityForUncoveredAncestorNodes>
</options>
</jackrabbit-filter>
<jackrabbit-nodetypes>
<options>
<cnds>tccl:aem.cnd</cnds>
</options>
</jackrabbit-nodetypes>
<jackrabbit-packagetype>
<options>
<legacyTypeSeverity>DEBUG</legacyTypeSeverity>
</options>
</jackrabbit-packagetype>
</validatorsSettings>
</configuration>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>biz.netcentric.aem</groupId>
<artifactId>aem-nodetypes</artifactId>
<version>2023.10.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>

</build>

<profiles>
<profile>
<!-- this profile is active for content-packages only -->
<id>packaging-contentpackage</id>
<!-- profile inheritance does not work in Maven (https://issues.apache.org/jira/browse/MNG-5127)
therefore the activation section needs to be copied from cq-parent -->
<activation>
<file>
<exists>${basedir}/src/main/jcr_root</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<modules>
<module>application-package</module>
<module>content-package</module>
<module>container-package</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public AuthorizableNamespaceValidator(
Collection<ValidationMessage> messages = new LinkedList<>();
String principalName =
node.getPropertyValue(PROPERTY_PRINCIPAL_NAME).orElse(null);
if (allowedPrincipalNamePatterns.stream()
.noneMatch(pattern -> pattern.matcher(principalName).matches())) {
if (!allowedPrincipalNamePatterns.isEmpty()
&& allowedPrincipalNamePatterns.stream()
.noneMatch(pattern -> pattern.matcher(principalName).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,30 @@ public OsgiConfigurationNamespaceValidator(
// is it a factory configuration?
boolean isFactoryConfig = subname != null;
Collection<ValidationMessage> messages = new LinkedList<>();
if (!isFactoryConfig || restrictFactoryConfigurationsToAllowedPidPatterns) {
if (allowedPidPatterns.stream()
.noneMatch(pattern -> pattern.matcher(pid).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
"OSGi configuration PID '%s' is not allowed to be configured (does not match any of the allowed patterns [%s])",
pid,
allowedPidPatterns.stream()
.map(Pattern::pattern)
.collect(Collectors.joining(",")))));
}
if (!allowedPidPatterns.isEmpty()
&& (!isFactoryConfig || restrictFactoryConfigurationsToAllowedPidPatterns)
&& allowedPidPatterns.stream()
.noneMatch(pattern -> pattern.matcher(pid).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
"OSGi configuration PID '%s' is not allowed to be configured (does not match any of the allowed patterns [%s])",
pid,
allowedPidPatterns.stream().map(Pattern::pattern).collect(Collectors.joining(",")))));
}
if (isFactoryConfig && !allowedFactoryPidNames.isEmpty()) {
if (allowedFactoryPidNames.stream()
.noneMatch(pattern -> pattern.matcher(subname).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
"OSGi factory configuration PID '%s' is not allowed with the given subname '%s' (does not match any of the allowed patterns [%s])",
pid,
subname,
allowedFactoryPidNames.stream()
.map(Pattern::pattern)
.collect(Collectors.joining(",")))));
}
if (isFactoryConfig
&& !allowedFactoryPidNames.isEmpty()
&& allowedFactoryPidNames.stream()
.noneMatch(pattern -> pattern.matcher(subname).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
"OSGi factory configuration PID '%s' is not allowed with the given subname '%s' (does not match any of the allowed patterns [%s])",
pid,
subname,
allowedFactoryPidNames.stream()
.map(Pattern::pattern)
.collect(Collectors.joining(",")))));
}
return messages;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ public PackageIdNamespaceValidator(
return Collections.singleton(new ValidationMessage(severity, "Package ID is missing"));
}
Collection<ValidationMessage> messages = new LinkedList<>();
if (allowedGroupPatterns.stream()
.noneMatch(pattern -> pattern.matcher(id.getGroup()).matches())) {
if (!allowedGroupPatterns.isEmpty()
&& allowedGroupPatterns.stream()
.noneMatch(pattern -> pattern.matcher(id.getGroup()).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
"Package group '%s' is not allowed (does not match any of the group patterns [%s])",
id.getGroup(),
allowedGroupPatterns.stream().map(Pattern::pattern).collect(Collectors.joining(",")))));
}
if (allowedNamePatterns.stream()
.noneMatch(pattern -> pattern.matcher(id.getName()).matches())) {
if (!allowedNamePatterns.isEmpty()
&& allowedNamePatterns.stream()
.noneMatch(pattern -> pattern.matcher(id.getName()).matches())) {
messages.add(new ValidationMessage(
severity,
String.format(
Expand Down
Loading

0 comments on commit a3ca7ed

Please sign in to comment.