| | |
| | | package org.keycloak.protocol.cas; |
| | | |
| | | import org.junit.Test; |
| | | import org.keycloak.protocol.cas.representations.CasServiceResponse; |
| | | import org.keycloak.protocol.cas.representations.CASErrorCode; |
| | | import org.keycloak.protocol.cas.representations.CASServiceResponse; |
| | | import org.keycloak.protocol.cas.utils.ServiceResponseHelper; |
| | | import org.keycloak.protocol.cas.utils.ServiceResponseMarshaller; |
| | | |
| | |
| | | private static final String EXPECTED_JSON_FAILURE = "{\n" + |
| | | " \"serviceResponse\" : {\n" + |
| | | " \"authenticationFailure\" : {\n" + |
| | | " \"code\" : \"ERROR_CODE\",\n" + |
| | | " \"code\" : \"INVALID_REQUEST\",\n" + |
| | | " \"description\" : \"Error description\"\n" + |
| | | " }\n" + |
| | | " }\n" + |
| | | "}"; |
| | | private static final String EXPECTED_XML_FAILURE = "<cas:serviceResponse xmlns:cas=\"http://www.yale.edu/tp/cas\">\n" + |
| | | " <cas:authenticationFailure code=\"ERROR_CODE\">Error description</cas:authenticationFailure>\n" + |
| | | " <cas:authenticationFailure code=\"INVALID_REQUEST\">Error description</cas:authenticationFailure>\n" + |
| | | "</cas:serviceResponse>"; |
| | | |
| | | @Test |
| | |
| | | attributes.put("int", 123); |
| | | attributes.put("string", "abc"); |
| | | |
| | | CasServiceResponse response = ServiceResponseHelper.createSuccess("username", attributes, "PGTIOU-test", |
| | | CASServiceResponse response = ServiceResponseHelper.createSuccess("username", attributes, "PGTIOU-test", |
| | | Arrays.asList("https://proxy1/pgtUrl", "https://proxy2/pgtUrl")); |
| | | |
| | | assertEquals(EXPECTED_JSON_SUCCESS, ServiceResponseMarshaller.marshalJson(response)); |
| | |
| | | |
| | | @Test |
| | | public void testErrorResponse() throws Exception { |
| | | CasServiceResponse response = ServiceResponseHelper.createFailure("ERROR_CODE", "Error description"); |
| | | CASServiceResponse response = ServiceResponseHelper.createFailure(CASErrorCode.INVALID_REQUEST, "Error description"); |
| | | |
| | | assertEquals(EXPECTED_JSON_FAILURE, ServiceResponseMarshaller.marshalJson(response)); |
| | | assertEquals(EXPECTED_XML_FAILURE, ServiceResponseMarshaller.marshalXml(response)); |