You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by mm...@apache.org on 2020/03/09 10:03:27 UTC

[syncope] branch SYNCOPE-163-1 updated (302fe33 -> 9cfd082)

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

mmoayyed pushed a change to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git.


    from 302fe33  fix tests
     new 66b1085  more tests for access and attr policies
     new 9cfd082  more tests

The 2 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:
 ...eleasePolicyTest.java => AccessPolicyTest.java} | 44 ++++++-----
 .../core/persistence/jpa/inner/PolicyTest.java     |  6 +-
 .../java/data/ImplementationDataBinderImpl.java    | 13 ++++
 .../java/data/PolicyDataBinderImpl.java            |  9 +++
 .../syncope/fit/core/OIDCRelyingPartyITCase.java   |  6 +-
 .../org/apache/syncope/fit/core/PolicyITCase.java  | 89 ++++++++++++++++++++--
 6 files changed, 138 insertions(+), 29 deletions(-)
 copy core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/{AttrReleasePolicyTest.java => AccessPolicyTest.java} (67%)


[syncope] 01/02: more tests for access and attr policies

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

mmoayyed pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 66b108534e7ceb9f89817e551868ae9b0849a0a1
Author: Misagh Moayyed <mm...@gmail.com>
AuthorDate: Mon Mar 9 13:11:06 2020 +0330

    more tests for access and attr policies
---
 .../persistence/jpa/inner/AccessPolicyTest.java    | 107 +++++++++++++++++++++
 .../core/persistence/jpa/inner/PolicyTest.java     |   5 +-
 .../java/data/ImplementationDataBinderImpl.java    |  13 +++
 .../java/data/PolicyDataBinderImpl.java            |   9 ++
 .../syncope/fit/core/OIDCRelyingPartyITCase.java   |   6 +-
 .../org/apache/syncope/fit/core/PolicyITCase.java  |  89 +++++++++++++++--
 6 files changed, 220 insertions(+), 9 deletions(-)

diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java
new file mode 100644
index 0000000..cf0004d8
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.syncope.core.persistence.jpa.inner;
+
+import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
+import org.apache.syncope.common.lib.attrs.AllowedAttrReleasePolicyConf;
+import org.apache.syncope.common.lib.types.AMImplementationType;
+import org.apache.syncope.common.lib.types.ImplementationEngine;
+import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
+import org.apache.syncope.core.persistence.api.dao.authentication.AccessPolicyDAO;
+import org.apache.syncope.core.persistence.api.entity.Implementation;
+import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@Transactional("Master")
+public class AccessPolicyTest extends AbstractTest {
+
+    @Autowired
+    private AccessPolicyDAO accessPolicyDAO;
+
+    @Autowired
+    private ImplementationDAO implementationDAO;
+
+    @Test
+    public void find() {
+        AccessPolicy policy = accessPolicyDAO.find("617735c7-deb3-40b3-8a9a-683037e523a2");
+        assertNull(policy);
+        policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+        assertNotNull(policy);
+        policy = accessPolicyDAO.find(UUID.randomUUID().toString());
+        assertNull(policy);
+    }
+
+    @Test
+    public void findAll() {
+        List<AccessPolicy> policies = accessPolicyDAO.findAll();
+        assertNotNull(policies);
+        assertEquals(1, policies.size());
+    }
+
+    @Test
+    public void save() {
+        int beforeCount = accessPolicyDAO.findAll().size();
+        AccessPolicy policy = entityFactory.newEntity(AccessPolicy.class);
+        policy.setName("AttrReleasePolicyAllowEverything");
+        policy.setDescription("This is a sample attr release policy that releases everything");
+
+        DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
+        conf.setRequiredAttributes(Map.of("cn", List.of("syncope")));
+        conf.setName("AttrReleasePolicyAllowEverything");
+
+        Implementation type = entityFactory.newEntity(Implementation.class);
+        type.setKey("AttrReleasePolicyAllowEverything");
+        type.setEngine(ImplementationEngine.JAVA);
+        type.setType(AMImplementationType.ACCESS_POLICY_CONFIGURATIONS);
+        type.setBody(POJOHelper.serialize(conf));
+        type = implementationDAO.save(type);
+
+        policy.addConfiguration(type);
+        accessPolicyDAO.save(policy);
+
+        assertNotNull(policy);
+        assertNotNull(policy.getKey());
+
+        int afterCount = accessPolicyDAO.findAll().size();
+        assertEquals(afterCount, beforeCount + 1);
+    }
+
+    @Test
+    public void delete() {
+        AccessPolicy policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+        assertNotNull(policy);
+        accessPolicyDAO.delete("419935c7-deb3-40b3-8a9a-683037e523a2");
+        policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+        assertNull(policy);
+    }
+}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
index 0dd95be..085b431 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
@@ -46,7 +46,10 @@ import org.springframework.transaction.annotation.Transactional;
 import java.util.List;
 import java.util.UUID;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 @Transactional("Master")
 public class PolicyTest extends AbstractTest {
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ImplementationDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ImplementationDataBinderImpl.java
index 2ce29f9..69ee3b4 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ImplementationDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ImplementationDataBinderImpl.java
@@ -22,6 +22,7 @@ import java.lang.reflect.Modifier;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.access.AccessPolicyConf;
+import org.apache.syncope.common.lib.attrs.AttrReleasePolicyConf;
 import org.apache.syncope.common.lib.authentication.module.AuthenticationModuleConf;
 import org.apache.syncope.common.lib.authentication.policy.AuthenticationPolicyConf;
 import org.apache.syncope.common.lib.policy.RuleConf;
@@ -40,6 +41,7 @@ import org.apache.syncope.core.persistence.api.entity.EntityFactory;
 import org.apache.syncope.core.persistence.api.entity.Implementation;
 import org.apache.syncope.core.persistence.api.entity.authentication.AuthenticationModule;
 import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
 import org.apache.syncope.core.provisioning.api.LogicActions;
 import org.apache.syncope.core.provisioning.api.data.ImplementationDataBinder;
@@ -168,6 +170,9 @@ public class ImplementationDataBinderImpl implements ImplementationDataBinder {
                     base = AuthenticationPolicy.class;
                     break;
 
+                case AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS:
+                    base = AttrReleasePolicy.class;
+                    break;
                 default:
             }
 
@@ -185,6 +190,14 @@ public class ImplementationDataBinderImpl implements ImplementationDataBinder {
                         throw sce;
                     }
                     break;
+                case AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS:
+                    AttrReleasePolicyConf policyConf =
+                        POJOHelper.deserialize(implementation.getBody(), AttrReleasePolicyConf.class);
+                    if (policyConf == null) {
+                        sce.getElements().add("Could not deserialize as AttrReleasePolicy");
+                        throw sce;
+                    }
+                    break;
                 case AMImplementationType.AUTH_MODULE_CONFIGURATIONS:
                     AuthenticationModuleConf authenticationModuleConf =
                             POJOHelper.deserialize(implementation.getBody(), AuthenticationModuleConf.class);
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
index 005e992..a7ec8e3 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
@@ -217,6 +217,15 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             AccessPolicyTO accessPolicyTO = AccessPolicyTO.class.cast(policyTO);
 
             accessPolicy.setName(accessPolicyTO.getKey());
+        } else if (policyTO instanceof AttrReleasePolicyTO) {
+            if (result == null) {
+                result = (T) entityFactory.newEntity(AttrReleasePolicy.class);
+            }
+
+            AttrReleasePolicy attrReleasePolicy = AttrReleasePolicy.class.cast(result);
+            AttrReleasePolicyTO attrReleasePolicyTO = AttrReleasePolicyTO.class.cast(policyTO);
+
+            attrReleasePolicy.setName(attrReleasePolicyTO.getKey());
         }
 
         if (result != null) {
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
index 7ad36a9..3c7d0d6 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
@@ -26,7 +26,11 @@ import org.apache.syncope.fit.AbstractITCase;
 import org.junit.jupiter.api.Test;
 import org.apache.syncope.common.lib.to.AccessPolicyTO;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import org.apache.syncope.common.lib.SyncopeClientException;
 
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
index 529c117..be722ba 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
@@ -22,6 +22,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
+import org.apache.syncope.common.lib.attrs.AllowedAttrReleasePolicyConf;
 import org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf;
 import org.apache.syncope.common.lib.policy.AccountPolicyTO;
 import org.apache.syncope.common.lib.policy.DefaultAccountRuleConf;
@@ -30,6 +31,7 @@ import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
 import org.apache.syncope.common.lib.policy.PullPolicyTO;
 import org.apache.syncope.common.lib.policy.PushPolicyTO;
 import org.apache.syncope.common.lib.to.AccessPolicyTO;
+import org.apache.syncope.common.lib.to.AttrReleasePolicyTO;
 import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
 import org.apache.syncope.common.lib.to.ImplementationTO;
 import org.apache.syncope.common.lib.types.AMImplementationType;
@@ -53,13 +55,17 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Set;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public class PolicyITCase extends AbstractITCase {
 
     private static AuthenticationPolicyTO buildAuthenticationPolicyTO() {
         final String authPolicyName = "TestAuthenticationPolicy" + getUUIDString();
-
         ImplementationTO implementationTO = null;
         try {
             implementationTO = implementationService.read(
@@ -90,6 +96,38 @@ public class PolicyITCase extends AbstractITCase {
         return policy;
     }
 
+    private static AttrReleasePolicyTO buildAttributeReleasePolicyTO(final String policyName) {
+        ImplementationTO implementationTO = null;
+        try {
+            implementationTO = implementationService.read(
+                AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS, policyName);
+        } catch (SyncopeClientException e) {
+            if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
+                implementationTO = new ImplementationTO();
+                implementationTO.setKey(policyName);
+                implementationTO.setEngine(ImplementationEngine.JAVA);
+                implementationTO.setType(AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS);
+
+                AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
+                conf.setName("MyDefaultAttrReleasePolicyConf");
+                conf.setAllowedAttributes(List.of("cn", "givenName"));
+                implementationTO.setBody(POJOHelper.serialize(conf));
+
+                Response response = implementationService.create(implementationTO);
+                implementationTO = implementationService.read(
+                    implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
+                assertNotNull(implementationTO);
+            }
+        }
+        assertNotNull(implementationTO);
+
+        AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
+        policy.setDescription("Test Attribute Release policy");
+        policy.setKey(implementationTO.getKey());
+
+        return policy;
+    }
+
     private static AccessPolicyTO buildAccessPolicyTO() {
         final String accessPolicyName = "TestAccessPolicy" + getUUIDString();
 
@@ -252,8 +290,7 @@ public class PolicyITCase extends AbstractITCase {
     }
 
     @Test
-    public void update() {
-//         1. Password policy
+    public void updatePasswordPolicy() {
         PasswordPolicyTO globalPolicy = policyService.read(PolicyType.PASSWORD, "ce93fcda-dc3a-4369-a7b0-a6108c261c85");
 
         PasswordPolicyTO policy = SerializationUtils.clone(globalPolicy);
@@ -280,9 +317,10 @@ public class PolicyITCase extends AbstractITCase {
         ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
         assertEquals(22, ruleConf.getMaxLength());
         assertEquals(8, ruleConf.getMinLength());
+    }
 
-        // 2. Authentication policy
-
+    @Test
+    public void updateAuthenticationPolicy() {
         AuthenticationPolicyTO newAuthPolicyTO = buildAuthenticationPolicyTO();
         assertNotNull(newAuthPolicyTO);
         newAuthPolicyTO = createPolicy(PolicyType.AUTHENTICATION, newAuthPolicyTO);
@@ -307,8 +345,10 @@ public class PolicyITCase extends AbstractITCase {
         assertNotNull(authPolicyConf);
         assertEquals(2, authPolicyConf.getAuthenticationModules().size());
         assertTrue(authPolicyConf.getAuthenticationModules().contains("LdapAuthentication"));
+    }
 
-        // 3. Access policy
+    @Test
+    public void updateAccessPolicy() {
         AccessPolicyTO globalAccessPolicyTO =
             policyService.read(PolicyType.ACCESS, "419935c7-deb3-40b3-8a9a-683037e523a2");
         assertNotNull(globalAccessPolicyTO);
@@ -342,6 +382,41 @@ public class PolicyITCase extends AbstractITCase {
     }
 
     @Test
+    public void updateAttrReleasePolicy() {
+        AttrReleasePolicyTO policyTO =
+            policyService.read(PolicyType.ATTR_RELEASE, "319935c7-deb3-40b3-8a9a-683037e523a2");
+        assertNotNull(policyTO);
+
+        final String policyName = "TestAttrReleasePolicy" + getUUIDString();
+        AttrReleasePolicyTO newPolicyTO = buildAttributeReleasePolicyTO(policyName);
+        newPolicyTO = createPolicy(PolicyType.ATTR_RELEASE, newPolicyTO);
+        assertNotNull(newPolicyTO);
+
+        ImplementationTO implementationTO = implementationService.read(
+            AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS, policyName);
+        assertNotNull(implementationTO);
+        assertFalse(StringUtils.isBlank(implementationTO.getBody()));
+
+        AllowedAttrReleasePolicyConf policyConf =
+            POJOHelper.deserialize(implementationTO.getBody(), AllowedAttrReleasePolicyConf.class);
+        assertNotNull(policyConf);
+        policyConf.setAllowedAttributes(List.of("cn", "givenName", "postalCode"));
+        implementationTO.setBody(POJOHelper.serialize(policyConf));
+
+        // update new policy
+        policyService.update(PolicyType.ATTR_RELEASE, newPolicyTO);
+        newPolicyTO = policyService.read(PolicyType.ATTR_RELEASE, newPolicyTO.getKey());
+        assertNotNull(newPolicyTO);
+
+        policyConf = POJOHelper.deserialize(implementationTO.getBody(), AllowedAttrReleasePolicyConf.class);
+        assertEquals(3, policyConf.getAllowedAttributes().size());
+        assertTrue(policyConf.getAllowedAttributes().contains("cn"));
+        assertTrue(policyConf.getAllowedAttributes().contains("postalCode"));
+        assertTrue(policyConf.getAllowedAttributes().contains("givenName"));
+
+    }
+
+    @Test
     public void delete() throws IOException {
         PullPolicyTO policy = buildPullPolicyTO();
 


[syncope] 02/02: more tests

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

mmoayyed pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 9cfd082e20433f325424747e1ada0b0f29cef5bf
Author: Misagh Moayyed <mm...@gmail.com>
AuthorDate: Mon Mar 9 13:33:10 2020 +0330

    more tests
---
 .../java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
index 085b431..c8f3b6b 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
@@ -48,6 +48,7 @@ import java.util.UUID;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertEquals;