You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2023/10/25 09:21:45 UTC

[sling-org-apache-sling-jcr-repoinit] branch test/group-with-extrnal-id updated (41e5733 -> c264c6b)

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

jsedding pushed a change to branch test/group-with-extrnal-id
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git


 discard 41e5733  SLING-12122 - Add unit-test creating group with rep:externalId property
     new c264c6b  SLING-12122 - Add unit-test creating group with rep:externalId property

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (41e5733)
            \
             N -- N -- N   refs/heads/test/group-with-extrnal-id (c264c6b)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../repoinit/CreateGroupWithExternalIdTest.java    | 24 ++++++----------------
 1 file changed, 6 insertions(+), 18 deletions(-)


[sling-org-apache-sling-jcr-repoinit] 01/01: SLING-12122 - Add unit-test creating group with rep:externalId property

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch test/group-with-extrnal-id
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git

commit c264c6bef8abfd6fa565dc58c7bcf1fda9d5dff0
Author: Julian Sedding <js...@apache.org>
AuthorDate: Wed Oct 25 10:52:49 2023 +0200

    SLING-12122 - Add unit-test creating group with rep:externalId property
---
 pom.xml                                            |   6 ++
 .../repoinit/CreateGroupWithExternalIdTest.java    | 115 +++++++++++++++++++++
 2 files changed, 121 insertions(+)

diff --git a/pom.xml b/pom.xml
index 79c0f2c..be12975 100644
--- a/pom.xml
+++ b/pom.xml
@@ -271,6 +271,12 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>oak-auth-external</artifactId>
+            <version>${oak.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.testing</artifactId>
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/CreateGroupWithExternalIdTest.java b/src/test/java/org/apache/sling/jcr/repoinit/CreateGroupWithExternalIdTest.java
new file mode 100644
index 0000000..e145763
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/CreateGroupWithExternalIdTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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 regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.jcr.repoinit;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.oak.jcr.Jcr;
+import org.apache.jackrabbit.oak.security.internal.SecurityProviderBuilder;
+import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.ExternalPrincipalConfiguration;
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.jcr.repoinit.impl.UserUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Test;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+
+public class CreateGroupWithExternalIdTest {
+
+    private static final String GROUP_NAME = "testGroup";
+
+    @Test
+    public void setRepExternalIdPropertyOnExistingGroupFails() throws RepositoryException, RepoInitParsingException {
+        // validates the test setup more than anything else
+        TestUtil U = createTestUtil();
+
+        U.assertGroup(GROUP_NAME + " should not yet exist", GROUP_NAME, false);
+
+        U.parseAndExecute("create group " + GROUP_NAME);
+        U.assertGroup(GROUP_NAME + " should exist", GROUP_NAME, true);
+
+        assertThrows(ConstraintViolationException.class, () -> U.parseAndExecute(
+                "set properties on authorizable(" + GROUP_NAME + ")",
+                "  set rep:externalId to \"" + GROUP_NAME + ";ldap\"",
+                "end"
+        ));
+        // The ConstraintViolationException does not refresh the session automatically,
+        // so the invalid changes are still transiently present and need to be explicitly dropped.
+        U.getAdminSession().refresh(false);
+
+        final Authorizable group = UserUtil.getAuthorizable(U.getAdminSession(), GROUP_NAME);
+        assertNull(GROUP_NAME + " should not have a rep:externalId property", group.getProperty("rep:externalId"));
+    }
+
+    @Test
+    public void setRepExternalIdPropertyOnNewGroupSucceeds() throws RepositoryException, RepoInitParsingException {
+        TestUtil U = createTestUtil();
+
+        U.assertGroup(GROUP_NAME + " should not yet exist", GROUP_NAME, false);
+
+        // Do this twice in order to test initial creation and update scenarios.
+        for (int i = 0; i < 2; i++) {
+            U.parseAndExecute(
+                    "create group " + GROUP_NAME,
+                    "set properties on authorizable(" + GROUP_NAME + ")",
+                    "  set rep:externalId to \"" + GROUP_NAME + ";ldap\"",
+                    "end"
+            );
+            U.assertGroup(GROUP_NAME + " should have been created", GROUP_NAME, true);
+
+            final Authorizable group = UserUtil.getAuthorizable(U.getAdminSession(), GROUP_NAME);
+            final Value[] externalIdValues = group.getProperty("rep:externalId");
+            assertEquals(1, externalIdValues.length);
+            assertEquals(GROUP_NAME + ";ldap", externalIdValues[0].getString());
+        }
+    }
+
+    @NotNull
+    private static TestUtil createTestUtil() throws RepositoryException {
+        final SecurityProvider securityProvider = createSecurityProvider();
+
+        final Repository repository = new Jcr()
+                .with(securityProvider)
+                .createRepository();
+        final Session adminSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        return new TestUtil(adminSession);
+    }
+
+    @NotNull
+    private static SecurityProvider createSecurityProvider() {
+        return SecurityProviderBuilder.newBuilder()
+                .with(
+                        null, ConfigurationParameters.EMPTY,
+                        null, ConfigurationParameters.EMPTY,
+                        null, ConfigurationParameters.EMPTY,
+                        null, ConfigurationParameters.EMPTY,
+                        new ExternalPrincipalConfiguration(), ConfigurationParameters.EMPTY,
+                        null, ConfigurationParameters.EMPTY)
+                .build();
+    }
+}
\ No newline at end of file