From e629ea858ba400232afea9b916b0408e99d74d4d Mon Sep 17 00:00:00 2001
From: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 02 Nov 2024 08:47:24 +0000
Subject: [PATCH] Update to Keycloak 26.0.5

---
 src/test/java/org/keycloak/protocol/cas/ServiceResponseTest.java |   34 ++++++----------------------------
 1 files changed, 6 insertions(+), 28 deletions(-)

diff --git a/src/test/java/org/keycloak/protocol/cas/ServiceResponseTest.java b/src/test/java/org/keycloak/protocol/cas/ServiceResponseTest.java
index b8ebe5a..29ea43a 100644
--- a/src/test/java/org/keycloak/protocol/cas/ServiceResponseTest.java
+++ b/src/test/java/org/keycloak/protocol/cas/ServiceResponseTest.java
@@ -1,7 +1,6 @@
 package org.keycloak.protocol.cas;
 
 import com.jayway.jsonpath.JsonPath;
-import com.sun.xml.bind.v2.util.FatalAdapter;
 import org.junit.Test;
 import org.keycloak.protocol.cas.representations.CASErrorCode;
 import org.keycloak.protocol.cas.representations.CASServiceResponse;
@@ -9,20 +8,14 @@
 import org.keycloak.protocol.cas.utils.ServiceResponseMarshaller;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
-import org.xml.sax.helpers.DefaultHandler;
 import org.xmlunit.xpath.JAXPXPathEngine;
 import org.xmlunit.xpath.XPathEngine;
 
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import java.io.ByteArrayInputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.*;
 
 import static org.junit.Assert.assertEquals;
+import static org.keycloak.protocol.cas.XMLValidator.parseAndValidate;
+import static org.keycloak.protocol.cas.XMLValidator.schemaFromClassPath;
 
 public class ServiceResponseTest {
     private final XPathEngine xpath = new JAXPXPathEngine();
@@ -55,14 +48,14 @@
         // Build and validate XML response
 
         String xml = ServiceResponseMarshaller.marshalXml(response);
-        Document doc = parseAndValidate(xml);
+        Document doc = parseAndValidate(xml, schemaFromClassPath("cas-response-schema.xsd"));
         assertEquals("username", xpath.evaluate("/cas:serviceResponse/cas:authenticationSuccess/cas:user", doc));
         int idx = 0;
         for (Node node : xpath.selectNodes("/cas:serviceResponse/cas:authenticationSuccess/cas:attributes/cas:list", doc)) {
-            assertEquals(((List)attributes.get("list")).get(idx), node.getTextContent());
+            assertEquals(((List<?>)attributes.get("list")).get(idx), node.getTextContent());
             idx++;
         }
-        assertEquals(((List)attributes.get("list")).size(), idx);
+        assertEquals(((List<?>)attributes.get("list")).size(), idx);
         assertEquals(attributes.get("int").toString(), xpath.evaluate("/cas:serviceResponse/cas:authenticationSuccess/cas:attributes/cas:int", doc));
         assertEquals(attributes.get("string").toString(), xpath.evaluate("/cas:serviceResponse/cas:authenticationSuccess/cas:attributes/cas:string", doc));
 
@@ -88,23 +81,8 @@
         // Build and validate XML response
 
         String xml = ServiceResponseMarshaller.marshalXml(response);
-        Document doc = parseAndValidate(xml);
+        Document doc = parseAndValidate(xml, schemaFromClassPath("cas-response-schema.xsd"));
         assertEquals(CASErrorCode.INVALID_REQUEST.name(), xpath.evaluate("/cas:serviceResponse/cas:authenticationFailure/@code", doc));
         assertEquals("Error description", xpath.evaluate("/cas:serviceResponse/cas:authenticationFailure", doc));
-    }
-
-    /**
-     * Parse XML document and validate against CAS schema
-     */
-    private Document parseAndValidate(String xml) throws Exception {
-        Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
-                .newSchema(getClass().getResource("cas-response-schema.xsd"));
-
-        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setSchema(schema);
-        factory.setNamespaceAware(true);
-        DocumentBuilder builder = factory.newDocumentBuilder();
-        builder.setErrorHandler(new FatalAdapter(new DefaultHandler()));
-        return builder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
     }
 }

--
Gitblit v1.9.1