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

github-actions
2024-11-02 e629ea858ba400232afea9b916b0408e99d74d4d
commit | author | age
57a6c1 1 package org.keycloak.protocol.cas;
MP 2
3 import org.apache.http.HttpEntity;
281a7e 4 import org.apache.http.NameValuePair;
MM 5 import org.apache.http.client.utils.URLEncodedUtils;
57a6c1 6 import org.junit.Test;
MP 7 import org.keycloak.protocol.cas.utils.LogoutHelper;
8 import org.keycloak.saml.common.constants.JBossSAMLURIConstants;
9 import org.keycloak.saml.common.util.DocumentUtil;
10 import org.w3c.dom.Document;
11 import org.w3c.dom.Node;
281a7e 12
MM 13 import java.util.List;
14 import java.util.stream.Collectors;
57a6c1 15
MP 16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18
19 public class LogoutHelperTest {
20     @Test
21     public void testLogoutRequest() throws Exception {
22         HttpEntity requestEntity = LogoutHelper.buildSingleLogoutRequest("ST-test");
281a7e 23
MM 24         List<NameValuePair> parameters = URLEncodedUtils.parse(requestEntity).stream().filter(parameter -> "logoutRequest".equals(parameter.getName())).collect(Collectors.toList());
25         assertEquals(1, parameters.size());
26
27         String logoutRequest = parameters.get(0).getValue();
28         Document doc = DocumentUtil.getDocument(logoutRequest);
57a6c1 29
MP 30         assertEquals("LogoutRequest", doc.getDocumentElement().getLocalName());
31         assertEquals(JBossSAMLURIConstants.PROTOCOL_NSURI.get(), doc.getDocumentElement().getNamespaceURI());
32         assertEquals("2.0", doc.getDocumentElement().getAttribute("Version"));
33         assertFalse(doc.getDocumentElement().getAttribute("ID").isEmpty());
34         assertFalse(doc.getDocumentElement().getAttribute("IssueInstant").isEmpty());
35
36         Node nameID = doc.getDocumentElement().getElementsByTagNameNS(JBossSAMLURIConstants.ASSERTION_NSURI.get(), "NameID").item(0);
37         assertFalse(nameID.getTextContent() == null || nameID.getTextContent().isEmpty());
38
39         Node sessionIndex = doc.getDocumentElement().getElementsByTagNameNS(JBossSAMLURIConstants.PROTOCOL_NSURI.get(), "SessionIndex").item(0);
40         assertEquals("ST-test", sessionIndex.getTextContent());
41     }
42 }