1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core;
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.Assumptions.assumeTrue;
24
25 import java.nio.charset.StandardCharsets;
26 import java.util.Base64;
27 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
28 import org.apache.syncope.common.lib.SyncopeClientException;
29 import org.apache.syncope.common.lib.to.SAML2SPEntityTO;
30 import org.apache.syncope.common.rest.api.service.SAML2SPEntityService;
31 import org.apache.syncope.fit.AbstractITCase;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.api.Test;
34
35 public class SAML2SPEntityITCase extends AbstractITCase {
36
37 private static final String OWNER = "owner";
38
39 private static SAML2SPEntityService WA_SAML2SP_ENTITY_SERVICE;
40
41 @BeforeAll
42 public static void setup() {
43 assumeTrue(CLIENT_FACTORY.getContentType() == SyncopeClientFactoryBean.ContentType.JSON);
44
45 WA_SAML2SP_ENTITY_SERVICE = ANONYMOUS_CLIENT.getService(SAML2SPEntityService.class);
46 }
47
48 private static SAML2SPEntityTO set() {
49 SAML2SPEntityTO entityTO = new SAML2SPEntityTO.Builder().
50 key(OWNER).
51 metadata(Base64.getEncoder().encodeToString("testMetadata".getBytes(StandardCharsets.UTF_8))).
52 build();
53 WA_SAML2SP_ENTITY_SERVICE.set(entityTO);
54
55 return entityTO;
56 }
57
58 @Test
59 public void get() {
60 SAML2SPEntityTO entityTO;
61 try {
62 entityTO = WA_SAML2SP_ENTITY_SERVICE.get(OWNER);
63 } catch (SyncopeClientException e) {
64 entityTO = set();
65 }
66 assertNotNull(entityTO);
67
68 assertEquals(OWNER, entityTO.getKey());
69 }
70
71 @Test
72 public void getAndSet() {
73 SAML2SPEntityTO entityTO;
74 try {
75 entityTO = WA_SAML2SP_ENTITY_SERVICE.get(OWNER);
76 } catch (SyncopeClientException e) {
77 entityTO = set();
78 }
79 assertNotNull(entityTO);
80
81 entityTO.setMetadata(Base64.getEncoder().encodeToString("new metadata".getBytes(StandardCharsets.UTF_8)));
82 WA_SAML2SP_ENTITY_SERVICE.set(entityTO);
83
84 entityTO = WA_SAML2SP_ENTITY_SERVICE.get(entityTO.getKey());
85 assertEquals(
86 "new metadata",
87 new String(Base64.getDecoder().decode(entityTO.getMetadata()), StandardCharsets.UTF_8));
88 }
89 }