mirror of https://github.com/jacekkow/keycloak-protocol-cas

github-actions
2020-11-06 174ac960610050346b0c5a7380a07f6dbcdbc093
commit | author | age
74023a 1 package org.keycloak.protocol.cas;
EH 2
3 import org.junit.Test;
4 import org.keycloak.dom.saml.v1.protocol.SAML11ResponseType;
5 import org.keycloak.protocol.cas.representations.CASErrorCode;
6 import org.keycloak.protocol.cas.representations.SamlResponseHelper;
7 import org.keycloak.protocol.cas.utils.CASValidationException;
8 import org.w3c.dom.Document;
9
10 import javax.ws.rs.core.Response;
11 import java.util.Collections;
12
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 public class SamlResponseTest {
17     @Test
18     public void successResponseIsWrappedInSOAP() {
19         SAML11ResponseType response = SamlResponseHelper.successResponse("keycloak", "test@example.com", Collections.emptyMap());
20         String soapResult = SamlResponseHelper.soap(response);
21         assertTrue(soapResult.contains("samlp:Success"));
22         assertTrue(soapResult.contains("test@example.com"));
23         assertTrue(soapResult.contains("keycloak"));
24     }
25
26     @Test
27     public void failureResponseIsWrappedInSOAP() {
28         SAML11ResponseType response = SamlResponseHelper.errorResponse(new CASValidationException(CASErrorCode.INVALID_TICKET, "Nope", Response.Status.BAD_REQUEST));
29         String nope = SamlResponseHelper.soap(response);
30         assertTrue(nope.contains("Nope"));
31     }
32
33     @Test
34     public void validateSchemaResponseFailure() throws Exception {
35         SAML11ResponseType response = SamlResponseHelper.errorResponse(new CASValidationException(CASErrorCode.INVALID_TICKET, "Nope", Response.Status.BAD_REQUEST));
36         String output = SamlResponseHelper.toString(SamlResponseHelper.toDOM(response));
37         Document doc = XMLValidator.parseAndValidate(output, XMLValidator.schemaFromClassPath("oasis-sstc-saml-schema-protocol-1.1.xsd"));
38         assertNotNull(doc);
39     }
40
41     @Test
42     public void validateSchemaResponseSuccess() throws Exception {
43         SAML11ResponseType response = SamlResponseHelper.successResponse("keycloak", "test@example.com", Collections.emptyMap());
44         String output = SamlResponseHelper.toString(SamlResponseHelper.toDOM(response));
45         Document doc = XMLValidator.parseAndValidate(output, XMLValidator.schemaFromClassPath("oasis-sstc-saml-schema-protocol-1.1.xsd"));
46         assertNotNull(doc);
47     }
48 }