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.wa.bootstrap;
20  
21  import static org.junit.jupiter.api.Assertions.assertFalse;
22  
23  import java.util.Map;
24  import org.apache.syncope.common.lib.auth.OAuth20AuthModuleConf;
25  import org.apache.syncope.common.lib.auth.SimpleMfaAuthModuleConf;
26  import org.apache.syncope.common.lib.to.AuthModuleTO;
27  import org.apache.syncope.wa.bootstrap.mapping.AuthModulePropertySourceMapper;
28  import org.junit.jupiter.api.Test;
29  
30  public class AuthModulePropertySourceMapperTest {
31  
32      @Test
33      public void mapSimpleMfaAuthModuleConf() {
34          AuthModuleTO authModuleTO = new AuthModuleTO();
35          authModuleTO.setKey("key");
36          authModuleTO.setOrder(0);
37  
38          SimpleMfaAuthModuleConf conf = new SimpleMfaAuthModuleConf();
39  
40          conf.setEmailAttribute("email");
41          conf.setEmailFrom("syncope@apache.org");
42          conf.setEmailSubject("Subject");
43          conf.setEmailText("Text body");
44  
45          conf.setTokenLength(256);
46          conf.setTimeToKillInSeconds(600);
47  
48          Map<String, Object> map = new AuthModulePropertySourceMapper(null).map(authModuleTO, conf);
49          assertFalse(map.keySet().stream().anyMatch(k -> k.endsWith("defined")));
50      }
51  
52      @Test
53      public void mapOAuth20AuthModuleConf() {
54          AuthModuleTO authModuleTO = new AuthModuleTO();
55          authModuleTO.setKey("oauth20");
56          authModuleTO.setOrder(0);
57  
58          OAuth20AuthModuleConf conf = new OAuth20AuthModuleConf();
59  
60          conf.setClientId("1000");
61          conf.setClientSecret("secret");
62          conf.setClientName("oauth20");
63          conf.setEnabled(true);
64          conf.setCustomParams(Map.of("param1", "param1"));
65          conf.setAuthUrl("https://localhost/oauth2/auth");
66          conf.setProfileUrl("https://localhost/oauth2/profile");
67          conf.setProfilePath("/info");
68          conf.setTokenUrl("https://localhost/oauth2/token");
69          conf.setResponseType("code");
70          conf.setScope("cns");
71          conf.setUserIdAttribute("uid");
72          conf.setWithState(true);
73  
74          Map<String, Object> map = new AuthModulePropertySourceMapper(null).map(authModuleTO, conf);
75          assertFalse(map.keySet().stream().anyMatch(k -> k.endsWith("defined")));
76      }
77  }