View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.provisioning.java.pushpull;
20  
21  import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
22  import static org.mockito.ArgumentMatchers.any;
23  import static org.mockito.ArgumentMatchers.anyString;
24  import static org.mockito.Mockito.verify;
25  import static org.mockito.Mockito.when;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  import java.util.UUID;
30  import org.apache.syncope.common.lib.to.ProvisioningReport;
31  import org.apache.syncope.common.lib.to.UserTO;
32  import org.apache.syncope.common.lib.types.CipherAlgorithm;
33  import org.apache.syncope.core.persistence.api.dao.UserDAO;
34  import org.apache.syncope.core.persistence.api.entity.user.User;
35  import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
36  import org.apache.syncope.core.provisioning.java.AbstractTest;
37  import org.identityconnectors.common.security.GuardedString;
38  import org.identityconnectors.framework.common.objects.Attribute;
39  import org.identityconnectors.framework.common.objects.AttributeBuilder;
40  import org.identityconnectors.framework.common.objects.ConnectorObject;
41  import org.identityconnectors.framework.common.objects.Name;
42  import org.identityconnectors.framework.common.objects.ObjectClass;
43  import org.identityconnectors.framework.common.objects.SyncDelta;
44  import org.identityconnectors.framework.common.objects.SyncDeltaBuilder;
45  import org.identityconnectors.framework.common.objects.SyncDeltaType;
46  import org.identityconnectors.framework.common.objects.SyncToken;
47  import org.identityconnectors.framework.common.objects.Uid;
48  import org.junit.jupiter.api.Test;
49  import org.mockito.InjectMocks;
50  import org.mockito.Mock;
51  import org.quartz.JobExecutionException;
52  
53  public class LDAPPasswordPullActionsTest extends AbstractTest {
54  
55      @Mock
56      private ProvisioningProfile<?, ?> profile;
57  
58      @Mock
59      private UserDAO userDAO;
60  
61      @Mock
62      private ProvisioningReport result;
63  
64      @InjectMocks
65  
66      private LDAPPasswordPullActions actions;
67  
68      @Test
69      public void afterWithNullUser() throws JobExecutionException {
70          UserTO userTO = new UserTO();
71          userTO.setKey(UUID.randomUUID().toString());
72          when(userDAO.find(userTO.getKey())).thenReturn(null);
73  
74          assertDoesNotThrow(() -> actions.after(profile, null, userTO, result));
75      }
76  
77      @Test
78      public void after(final @Mock User user) throws JobExecutionException {
79          UserTO userTO = new UserTO();
80          userTO.setKey(UUID.randomUUID().toString());
81          when(userDAO.find(userTO.getKey())).thenReturn(user);
82  
83          Set<Attribute> attributes = new HashSet<>();
84          attributes.add(new Uid(UUID.randomUUID().toString()));
85          attributes.add(new Name(UUID.randomUUID().toString()));
86          attributes.add(AttributeBuilder.buildPassword(
87                  new GuardedString("{SSHA}4AwQq1UVDwubSXmR4pnmLsoVR6U2Z7R55kwxRA==".toCharArray())));
88          SyncDelta delta = new SyncDeltaBuilder().
89                  setToken(new SyncToken("sample-token")).
90                  setDeltaType(SyncDeltaType.CREATE_OR_UPDATE).
91                  setUid(new Uid(UUID.randomUUID().toString())).
92                  setObject(new ConnectorObject(ObjectClass.ACCOUNT, attributes)).
93                  build();
94  
95          actions.after(profile, delta, userTO, result);
96  
97          verify(user).setEncodedPassword(anyString(), any(CipherAlgorithm.class));
98      }
99  }