1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.inner;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24
25 import java.util.UUID;
26 import org.apache.syncope.common.lib.types.OIDCGrantType;
27 import org.apache.syncope.common.lib.types.OIDCResponseType;
28 import org.apache.syncope.common.lib.types.OIDCSubjectType;
29 import org.apache.syncope.core.persistence.api.dao.OIDCRPClientAppDAO;
30 import org.apache.syncope.core.persistence.api.entity.am.OIDCRPClientApp;
31 import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
32 import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
33 import org.junit.jupiter.api.Test;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.transaction.annotation.Transactional;
36
37 @Transactional("Master")
38 public class OIDCRPTest extends AbstractClientAppTest {
39
40 @Autowired
41 private OIDCRPClientAppDAO oidcrpDAO;
42
43 @Test
44 public void find() {
45 int beforeCount = oidcrpDAO.findAll().size();
46
47 OIDCRPClientApp rp = entityFactory.newEntity(OIDCRPClientApp.class);
48 rp.setName("OIDC");
49 rp.setClientAppId(UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE);
50 rp.setDescription("This is a sample OIDC RP");
51 rp.setClientId("clientid");
52 rp.setClientSecret("secret");
53 rp.setSubjectType(OIDCSubjectType.PUBLIC);
54 rp.getSupportedGrantTypes().add(OIDCGrantType.password);
55 rp.getSupportedResponseTypes().add(OIDCResponseType.CODE);
56
57 AccessPolicy accessPolicy = buildAndSaveAccessPolicy();
58 rp.setAccessPolicy(accessPolicy);
59
60 AuthPolicy authPolicy = buildAndSaveAuthPolicy();
61 rp.setAuthPolicy(authPolicy);
62
63 oidcrpDAO.save(rp);
64
65 assertNotNull(rp);
66 assertNotNull(rp.getKey());
67
68 int afterCount = oidcrpDAO.findAll().size();
69 assertEquals(afterCount, beforeCount + 1);
70
71 rp = oidcrpDAO.findByClientId("clientid");
72 assertNotNull(rp);
73 assertNotNull(rp.getAuthPolicy());
74
75 rp = oidcrpDAO.findByName("OIDC");
76 assertNotNull(rp);
77
78 rp = oidcrpDAO.findByClientAppId(rp.getClientAppId());
79 assertNotNull(rp);
80
81 oidcrpDAO.deleteByClientId("clientid");
82 assertNull(oidcrpDAO.findByName("OIDC"));
83 }
84 }