1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }