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.assertDoesNotThrow;
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.pac4j.saml.metadata.keystore.SAML2KeystoreGenerator;
36 import org.springframework.core.io.ClassPathResource;
37
38 public class WASAML2ClientKeystoreGeneratorTest extends BaseWASAML2ClientTest {
39
40 private static WARestClient getWaRestClient() throws Exception {
41 SAML2SPEntityTO keystoreTO = 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(keystoreTO);
49 doNothing().when(service).set(any(SAML2SPEntityTO.class));
50
51 WARestClient waRestClient = mock(WARestClient.class);
52 when(waRestClient.getService(SAML2SPEntityService.class)).thenReturn(service);
53 return waRestClient;
54 }
55
56 @Test
57 public void generate() throws Exception {
58 SAML2Client client = getSAML2Client();
59 SAML2KeystoreGenerator generator = new WASAML2ClientKeystoreGenerator(getWaRestClient(), client);
60 assertDoesNotThrow(generator::generate);
61 }
62 }