1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.wa.starter.pac4j.saml;
20
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.ArgumentMatchers.anyString;
24 import static org.mockito.Mockito.doNothing;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27
28 import java.nio.charset.StandardCharsets;
29 import org.apache.commons.io.IOUtils;
30 import org.apache.syncope.common.lib.to.SAML2SPEntityTO;
31 import org.apache.syncope.common.rest.api.service.SAML2SPEntityService;
32 import org.apache.syncope.wa.bootstrap.WARestClient;
33 import org.junit.jupiter.api.Test;
34 import org.pac4j.saml.client.SAML2Client;
35 import org.springframework.core.io.ClassPathResource;
36
37 public class WASAML2ClientCustomizerTest extends BaseWASAML2ClientTest {
38
39 @Test
40 public void customize() throws Exception {
41 SAML2SPEntityTO entityTO = new SAML2SPEntityTO.Builder()
42 .key("CAS")
43 .keystore(getKeystoreAsString())
44 .metadata(IOUtils.toString(new ClassPathResource("sp-metadata.xml").getInputStream(),
45 StandardCharsets.UTF_8))
46 .build();
47 SAML2SPEntityService service = mock(SAML2SPEntityService.class);
48 when(service.get(anyString())).thenReturn(entityTO);
49 doNothing().when(service).set(any(SAML2SPEntityTO.class));
50
51 WARestClient waRestClient = mock(WARestClient.class);
52 when(waRestClient.getService(SAML2SPEntityService.class)).thenReturn(service);
53
54 WASAML2ClientCustomizer customizer = new WASAML2ClientCustomizer(waRestClient);
55 SAML2Client client = getSAML2Client();
56 customizer.customize(client);
57 client.init();
58 assertTrue(client.getConfiguration().getKeystoreGenerator() instanceof WASAML2ClientKeystoreGenerator);
59 assertTrue(client.getConfiguration().toMetadataGenerator() instanceof WASAML2ClientMetadataGenerator);
60 }
61 }