You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/01/09 10:48:07 UTC
[syncope] branch 2_1_X updated: Unit Test for DBPasswordPullActions
(#156)
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/2_1_X by this push:
new 317e7e0 Unit Test for DBPasswordPullActions (#156)
317e7e0 is described below
commit 317e7e0891d9a2dab9a6a66798337cc0b2843669
Author: Davide Cortellucci <da...@gmail.com>
AuthorDate: Thu Jan 9 11:48:01 2020 +0100
Unit Test for DBPasswordPullActions (#156)
---
.../java/pushpull/DBPasswordPullActionsTest.java | 142 +++++++++++++++++++++
1 file changed, 142 insertions(+)
diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java
new file mode 100644
index 0000000..04b3d42
--- /dev/null
+++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.provisioning.java.pushpull;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.syncope.common.lib.patch.PasswordPatch;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.ProvisioningReport;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ConnConfPropSchema;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.provisioning.api.Connector;
+import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
+import org.apache.syncope.core.provisioning.java.AbstractTest;
+import org.identityconnectors.framework.common.objects.SyncDelta;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.quartz.JobExecutionException;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class DBPasswordPullActionsTest extends AbstractTest {
+
+ @Mock
+ private SyncDelta syncDelta;
+
+ @Mock
+ private ProvisioningProfile<?, ?> profile;
+
+ @Mock
+ private UserDAO userDAO;
+
+ @Mock
+ private ProvisioningReport result;
+
+ @Mock
+ private Connector connector;
+
+ @InjectMocks
+ private DBPasswordPullActions dBPasswordPullActions;
+
+ @Mock
+ private ConnInstance connInstance;
+
+ private Set<ConnConfProperty> connConfProperties;
+
+ private UserTO userTO;
+
+ private UserPatch userPatch;
+
+ private String encodedPassword;
+
+ private CipherAlgorithm cipher;
+
+ private ConnConfProperty connConfProperty;
+
+ @BeforeEach
+ public void initTest() {
+ userTO = new UserTO();
+ encodedPassword = "s3cureP4ssw0rd";
+ cipher = CipherAlgorithm.SHA512;
+ ConnConfPropSchema connConfPropSchema = new ConnConfPropSchema();
+ connConfPropSchema.setName("cipherAlgorithm");
+ connConfProperty = new ConnConfProperty();
+ connConfProperty.setSchema(connConfPropSchema);
+ connConfProperties = new HashSet<>();
+ connConfProperties.add(connConfProperty);
+
+ ReflectionTestUtils.setField(dBPasswordPullActions, "encodedPassword", encodedPassword);
+ ReflectionTestUtils.setField(dBPasswordPullActions, "cipher", cipher);
+
+ lenient().when(profile.getConnector()).thenReturn(connector);
+ lenient().when(connector.getConnInstance()).thenReturn(connInstance);
+ lenient().when(connInstance.getConf()).thenReturn(connConfProperties);
+ }
+
+ @Test
+ public void beforeProvision() throws JobExecutionException {
+ String digest = "SHA256";
+ String password = "t3stPassw0rd";
+ userTO.setPassword(password);
+ connConfProperty.getValues().clear();
+ connConfProperty.getValues().add(digest);
+
+ dBPasswordPullActions.beforeProvision(profile, syncDelta, userTO);
+
+ assertEquals(CipherAlgorithm.valueOf(digest), ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+ assertEquals(password, ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+ }
+
+ @Test
+ public void beforeUpdate() throws JobExecutionException {
+ userPatch = new UserPatch();
+ userPatch.setPassword(new PasswordPatch.Builder().value("an0therTestP4ss").build());
+
+ dBPasswordPullActions.beforeUpdate(profile, syncDelta, userTO, userPatch);
+
+ assertEquals(cipher, ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+ assertEquals(encodedPassword, ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+ }
+
+ @Test
+ public void after(@Mock User user) throws JobExecutionException {
+ when(userDAO.find(user.getKey())).thenReturn(user);
+
+ dBPasswordPullActions.after(profile, syncDelta, userTO, result);
+
+ verify(user).setEncodedPassword(anyString(), any(CipherAlgorithm.class));
+ assertNull(ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+ assertNull(ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+ }
+}