You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:56:09 UTC

[sling-org-apache-sling-nosql-generic] 06/23: SLING-4381 disallow storing data in root resource

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

rombert pushed a commit to annotated tag org.apache.sling.nosql.generic-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-nosql-generic.git

commit 97f137aa9a3d95f059fbc80e2987bfa4c4303114
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu May 21 07:02:40 2015 +0000

    SLING-4381 disallow storing data in root resource
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/generic@1680744 13f79535-47bb-0310-9956-ffa450edef68
---
 .../generic/resource/impl/NoSqlResourceProvider.java      |  3 +++
 .../impl/AbstractNoSqlResourceProviderRootTest.java       | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
index 5621566..a1bc13f 100644
--- a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
+++ b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
@@ -194,6 +194,9 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
                notifyRemoved(path);
             }
             for (NoSqlData item : changedResources.values()) {
+                if (ROOT_PATH.equals(item.getPath())) {
+                    throw new PersistenceException("Unable to store resource at {}" + item.getPath(), null, item.getPath(), null);
+                }
                 boolean created = adapter.store(item);
                 if (created) {
                     notifyAdded(item.getPath());
diff --git a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
index b346aa6..3b4966f 100644
--- a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
+++ b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.ModifiableValueMap;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceUtil;
@@ -75,5 +76,19 @@ public abstract class AbstractNoSqlResourceProviderRootTest {
         
         context.resourceResolver().delete(test);
     }
+    
+    @Test(expected = PersistenceException.class)
+    public void testDeleteRootPath() throws PersistenceException {
+        Resource root = context.resourceResolver().getResource("/");
+        context.resourceResolver().delete(root);
+    }
+
+    @Test(expected = Throwable.class)
+    public void testUpdateRootPath() throws PersistenceException {
+        Resource root = context.resourceResolver().getResource("/");
+        ModifiableValueMap props = root.adaptTo(ModifiableValueMap.class);
+        props.put("prop1", "value1");
+        context.resourceResolver().commit();
+    }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.