You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2020/09/25 17:22:53 UTC

[sling-org-apache-sling-scripting-sightly-testing] branch master updated: SLING-9768 - The org.apache.sling.api.scripting.SlingScript#getScriptResource implementations should not leak the scripting resolver

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 804f280  SLING-9768 - The org.apache.sling.api.scripting.SlingScript#getScriptResource implementations should not leak the scripting resolver
804f280 is described below

commit 804f28006611cbac82c772f4108ec62f6eb2df3c
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 25 19:21:50 2020 +0200

    SLING-9768 - The org.apache.sling.api.scripting.SlingScript#getScriptResource implementations should not leak the scripting resolver
    
    * added tests
---
 pom.xml                                            | 176 +++++++--------------
 .../partials/include.html}                         |  21 +--
 .../templates-access-control.html}                 |  20 +--
 .../sightly/it/SlingSpecificsSightlyIT.java        |  20 ++-
 src/test/provisioning/scripting.txt                |  27 +++-
 5 files changed, 109 insertions(+), 155 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8f8f980..50b50ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,61 +72,10 @@
         otherwise you can provide your own debug settings
         -->
         <debug.options />
+        <keepInstanceRunning>false</keepInstanceRunning>
     </properties>
 
     <build>
-        <pluginManagement>
-            <plugins>
-                <plugin>
-                    <groupId>org.apache.sling</groupId>
-                    <artifactId>slingstart-maven-plugin</artifactId>
-                    <version>1.9.4</version>
-                    <extensions>true</extensions>
-                    <configuration>
-                        <usePomDependencies>true</usePomDependencies>
-                        <servers>
-                            <server>
-                                <port>${http.port}</port>
-                                <controlPort>${sling.control.port}</controlPort>
-                                <runmode>${sling.run.modes}</runmode>
-                                <contextPath>${http.base.path}</contextPath>
-                                <debug>${debug.options}</debug>
-                            </server>
-                        </servers>
-                        <disableExtendingMavenClasspath>true</disableExtendingMavenClasspath>
-                        <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
-                    </configuration>
-                    <executions>
-                        <execution>
-                            <id>customise-starter</id>
-                            <phase>pre-integration-test</phase>
-                            <goals>
-                                <goal>prepare-package</goal>
-                            </goals>
-                        </execution>
-                        <execution>
-                            <id>package-starter</id>
-                            <phase>pre-integration-test</phase>
-                            <goals>
-                                <goal>package</goal>
-                            </goals>
-                            <configuration>
-                                <attachArtifact>false</attachArtifact>
-                            </configuration>
-                        </execution>
-                        <execution>
-                            <id>start-container</id>
-                            <goals>
-                                <goal>start</goal>
-                                <goal>stop</goal>
-                            </goals>
-                        </execution>
-                    </executions>
-                </plugin>
-            </plugins>
-        </pluginManagement>
-
-
         <plugins>
             <plugin>
                 <artifactId>maven-clean-plugin</artifactId>
@@ -190,7 +139,6 @@
 -plugin.slingmodels: org.apache.sling.bnd.models.ModelsScannerPlugin
 Provide-Capability: ${org.apache.sling.scriptingbundle.maven.plugin.Provide-Capability}
 Require-Capability: osgi.extender;filter:="(&(osgi.extender=sling.scripting)(version>=1.0.0)(!(version>=2.0.0)))",${org.apache.sling.scriptingbundle.maven.plugin.Require-Capability}
-Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-testing
                                 ]]></bnd>
                         </configuration>
                     </execution>
@@ -230,6 +178,56 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
                 </executions>
             </plugin>
             <plugin>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>slingstart-maven-plugin</artifactId>
+                <version>1.9.4</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <usePomDependencies>true</usePomDependencies>
+                    <servers>
+                        <server>
+                            <port>${http.port}</port>
+                            <controlPort>${sling.control.port}</controlPort>
+                            <runmode>${sling.run.modes}</runmode>
+                            <contextPath>${http.base.path}</contextPath>
+                            <debug>${debug.options}</debug>
+                        </server>
+                    </servers>
+                    <disableExtendingMavenClasspath>true</disableExtendingMavenClasspath>
+                    <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
+                    <usePomDependencies>true</usePomDependencies>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>customise-starter</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>prepare-package</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>package-starter</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>package</goal>
+                        </goals>
+                        <configuration>
+                            <attachArtifact>false</attachArtifact>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>start-container</id>
+                        <goals>
+                            <goal>start</goal>
+                            <goal>stop</goal>
+                        </goals>
+                        <configuration>
+                            <keepLaunchpadRunning>${keepInstanceRunning}</keepLaunchpadRunning>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-failsafe-plugin</artifactId>
                 <version>2.19.1</version>
@@ -263,6 +261,7 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
                         <launchpad.http.port>${http.port}</launchpad.http.port>
                         <launchpad.http.server.url>http://${test.host}:${http.port}</launchpad.http.server.url>
                         <launchpad.servlet.context>${http.base.path}</launchpad.servlet.context>
+                        <IT.expected.bundles.count>178</IT.expected.bundles.count>
                     </systemPropertyVariables>
                 </configuration>
             </plugin>
@@ -276,70 +275,6 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
         </plugins>
     </build>
 
-    <profiles>
-        <profile>
-            <id>snapshot-launchpad</id>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.sling</groupId>
-                        <artifactId>slingstart-maven-plugin</artifactId>
-                        <configuration>
-                            <model>
-                                [feature name=sling]
-                                # Dependencies
-                                [artifacts]
-                                org.apache.sling/org.apache.sling.starter/12-SNAPSHOT/slingstart
-                                org.apache.sling/org.apache.sling.commons.compiler/2.4.0
-                                org.apache.sling/org.apache.sling.servlets.resolver/2.7.6
-                                org.apache.sling/org.apache.sling.scripting.core/2.3.0
-                            </model>
-                            <modelPattern>sightly.txt</modelPattern>
-                        </configuration>
-                    </plugin>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-failsafe-plugin</artifactId>
-                        <configuration>
-                            <systemPropertyVariables>
-                                <IT.expected.bundles.count>183</IT.expected.bundles.count>
-                            </systemPropertyVariables>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-        <profile>
-            <id>release</id>
-            <activation>
-                <activeByDefault>false</activeByDefault>
-            </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.sling</groupId>
-                        <artifactId>slingstart-maven-plugin</artifactId>
-                        <configuration>
-                            <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
-                        </configuration>
-                    </plugin>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-failsafe-plugin</artifactId>
-                        <configuration>
-                            <systemPropertyVariables>
-                                <IT.expected.bundles.count>179</IT.expected.bundles.count>
-                            </systemPropertyVariables>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-
     <dependencies>
 
         <dependency>
@@ -433,6 +368,13 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.core</artifactId>
+            <version>2.3.3-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
         <!-- Dependencies for the Test Build and Run -->
         <dependency>
             <groupId>org.apache.sling</groupId>
diff --git a/src/main/resources/SLING-INF/content/sightly-testing.xml b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/partials/include.html
similarity index 62%
copy from src/main/resources/SLING-INF/content/sightly-testing.xml
copy to src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/partials/include.html
index b686859..b53dc75 100644
--- a/src/main/resources/SLING-INF/content/sightly-testing.xml
+++ b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/partials/include.html
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ~ Licensed to the Apache Software Foundation (ASF) under one
   ~ or more contributor license agreements.  See the NOTICE file
   ~ distributed with this work for additional information
@@ -16,18 +15,6 @@
   ~ KIND, either express or implied.  See the License for the
   ~ specific language governing permissions and limitations
   ~ under the License.
-  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-<node>
-    <name>precompiled</name>
-    <primaryNodeType>nt:unstructured</primaryNodeType>
-    <property>
-        <name>sling:resourceType</name>
-        <value>org/apache/sling/scripting/sightly/testing/precompiled</value>
-        <type>String</type>
-    </property>
-    <property>
-        <name>jcr:title</name>
-        <value>HTL Precompiled Scripts Test</value>
-        <type>String</type>
-    </property>
-</node>
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+<div class="precompiled-include-wrapper" data-sly-use.templates="/apps/sightly/scripts/templates-access-control/partials/templates.html"
+     data-sly-call="${templates.template}"></div>
diff --git a/src/main/resources/SLING-INF/content/sightly-testing.xml b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/templates-access-control.html
similarity index 62%
rename from src/main/resources/SLING-INF/content/sightly-testing.xml
rename to src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/templates-access-control.html
index b686859..ddf3e3a 100644
--- a/src/main/resources/SLING-INF/content/sightly-testing.xml
+++ b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/templates-access-control/templates-access-control.html
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ~ Licensed to the Apache Software Foundation (ASF) under one
   ~ or more contributor license agreements.  See the NOTICE file
   ~ distributed with this work for additional information
@@ -16,18 +15,5 @@
   ~ KIND, either express or implied.  See the License for the
   ~ specific language governing permissions and limitations
   ~ under the License.
-  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-<node>
-    <name>precompiled</name>
-    <primaryNodeType>nt:unstructured</primaryNodeType>
-    <property>
-        <name>sling:resourceType</name>
-        <value>org/apache/sling/scripting/sightly/testing/precompiled</value>
-        <type>String</type>
-    </property>
-    <property>
-        <name>jcr:title</name>
-        <value>HTL Precompiled Scripts Test</value>
-        <type>String</type>
-    </property>
-</node>
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+<div class="precompiled-wrapper" data-sly-include="partials/include.html"></div>
diff --git a/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java b/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
index e00e1bf..0bd8632 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
@@ -27,11 +27,9 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.sling.testing.clients.util.FormEntityBuilder;
-import org.apache.sling.testing.junit.rules.annotation.IgnoreIfProperty;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import io.sightly.tck.Constants;
 import io.sightly.tck.html.HTMLExtractor;
 import io.sightly.tck.http.Client;
 
@@ -433,6 +431,24 @@ public class SlingSpecificsSightlyIT {
         );
     }
 
+    @Test
+    public void testSlingTemplatesAccessControlRepositoryScripts() {
+        Client client = new Client();
+        String classic = launchpadURL + "/content/sightly-testing/templates-access-control/classic.html";
+        String classicPageContent = client.getStringContent(classic, 200);
+        assertEquals("template loaded", HTMLExtractor.innerHTML(classic, classicPageContent, "div.wrapper > div.include-wrapper > div" +
+                ".template"));
+    }
+
+    @Test
+    public void testSlingTemplatesAccessControlBundledScripts() {
+        Client client = new Client();
+        String precompiled = launchpadURL + "/content/sightly-testing/templates-access-control/precompiled.html";
+        String precompiledPageContent = client.getStringContent(precompiled, 200);
+        assertEquals("template loaded", HTMLExtractor.innerHTML(precompiled, precompiledPageContent, "div.precompiled-wrapper > div" +
+                ".precompiled-include-wrapper > div.template"));
+    }
+
     private void restartSightlyEngineBundle() throws InterruptedException, IOException {
         HttpClient httpClient = HttpClientBuilder.create().build();
         HttpPost post = new HttpPost(launchpadURL + "/system/console/bundles/org.apache.sling.scripting.sightly");
diff --git a/src/test/provisioning/scripting.txt b/src/test/provisioning/scripting.txt
index ee24386..9cac8fd 100644
--- a/src/test/provisioning/scripting.txt
+++ b/src/test/provisioning/scripting.txt
@@ -20,8 +20,18 @@
 [feature name=sling]
 
 [artifacts]
+    # HTL
+    org.apache.sling/org.apache.sling.scripting.sightly.runtime
+    org.apache.sling/org.apache.sling.scripting.sightly.compiler
+    org.apache.sling/org.apache.sling.scripting.sightly.compiler.java
+    org.apache.sling/org.apache.sling.scripting.sightly
+    org.apache.sling/org.apache.sling.scripting.sightly.js.provider
+    org.apache.sling/org.apache.sling.scripting.sightly.testing-content
+    org.apache.sling/org.apache.sling.scripting.sightly.testing
+
+
     org.apache.sling/org.apache.sling.scripting.api/2.2.0
-    org.apache.sling/org.apache.sling.scripting.core/2.3.0
+    org.apache.sling/org.apache.sling.scripting.core
     org.apache.sling/org.apache.sling.scripting.javascript/3.1.2
     org.apache.sling/org.apache.sling.scripting.jsp/2.4.0
     org.apache.sling/org.apache.sling.scripting.jsp-api/1.0.2
@@ -42,7 +52,11 @@
         deny    jcr:all     on /
         allow   jcr:read    on /libs,/apps
     end
-    # SLING-5848 - Define service user and ACLs for Scripting >>>
+
+    create path (sling:Folder) /sightlytck/scripts
+    set ACL for sling-scripting
+        allow   jcr:read    on /sightlytck/scripts
+    end
 
 
 [configurations]
@@ -55,3 +69,12 @@
             "org.apache.sling.scripting.core\=sling-scripting",
             "org.apache.sling.scripting.sightly.js.provider\=sling-scripting",
         ]
+
+    org.apache.sling.commons.log.LogManager.factory.config-2ef75700-a318-4eae-bed4-86777e1bdfd2
+        org.apache.sling.commons.log.pattern="{0,date,dd.MM.yyyy\ HH:mm:ss.SSS}\ *{4}*\ [{2}]\ {3}\ {5}"
+        org.apache.sling.commons.log.names=["org.apache.sling.scripting.sightly.js.impl.jsapi.ProxyAsyncScriptableFactory"]
+        org.apache.sling.commons.log.file="logs/error.log"
+        org.apache.sling.commons.log.level="error"
+
+    org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl
+        resource.resolver.searchpath=["/apps", "/libs", "/sightlytck/scripts"]