use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestServiceTest method testSendLogoutRequestGetPostRequest.
@Test
public void testSendLogoutRequestGetPostRequest() throws Exception {
String encryptedNameIdWithTime = nameId + "\n" + time;
when(encryptionService.decrypt(any(String.class))).thenReturn(nameId + "\n" + time);
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
when(logoutMessage.buildLogoutRequest(eq(nameId), anyString())).thenReturn(logoutRequest);
Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertTrue("Expected logout url of " + postLogoutUrl, response.getEntity().toString().contains(postLogoutUrl));
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestServiceTest method testSendLogoutRequestTimeout.
@Test
public void testSendLogoutRequestTimeout() throws Exception {
Long badTime = (time - TimeUnit.DAYS.toMillis(1));
String encryptedNameIdWithTime = nameId + "\n" + badTime;
when(encryptionService.decrypt(any(String.class))).thenReturn(nameId + "\n" + badTime);
Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = String.format("Logout request was older than %sms old so it was rejected. Please refresh page and request again.", LOGOUT_PAGE_TIMEOUT).replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestNotParsable.
@Test
public void testGetLogoutRequestNotParsable() throws Exception {
String signature = "signature";
String signatureAlgorithm = "sha1";
String relayState = UUID.randomUUID().toString();
String deflatedSamlRequest = RestSecurity.deflateAndBase64Encode("deflatedSamlRequest");
when(logoutMessage.extractSamlLogoutRequest(eq("deflatedSamlRequest"))).thenReturn(null);
Response response = logoutRequestService.getLogoutRequest(deflatedSamlRequest, null, relayState, signatureAlgorithm, signature);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = "Unable to parse logout request.".replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestServiceTest method testPostLogoutRequestResponseNotParsable.
@Test
public void testPostLogoutRequestResponseNotParsable() throws Exception {
String relayState = UUID.randomUUID().toString();
String encodedSamlResponse = "encodedSamlRequest";
when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(null);
Response response = logoutRequestService.postLogoutRequest(null, encodedSamlResponse, relayState);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = "Unable to parse logout response.".replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestServiceTest method testPostLogoutRequestResponse.
@Test
public void testPostLogoutRequestResponse() throws Exception {
String relayState = UUID.randomUUID().toString();
String encodedSamlResponse = "encodedSamlRequest";
String issuerStr = "issuer";
Issuer issuer = mock(Issuer.class);
LogoutResponse logoutResponse = mock(LogoutResponse.class);
logoutResponse.setIssuer(issuer);
when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(logoutResponse);
when(request.getRequestURL()).thenReturn(new StringBuffer("www.url.com/url"));
when(logoutResponse.getIssuer()).thenReturn(issuer);
when(logoutResponse.getIssueInstant()).thenReturn(new DateTime());
when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20);
when(logoutResponse.getID()).thenReturn("id");
when(issuer.getValue()).thenReturn(issuerStr);
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
Response response = logoutRequestService.postLogoutRequest(null, encodedSamlResponse, relayState);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
assertTrue("Expected a successful logout message", response.getLocation().toString().contains("logged+out+successfully."));
}
Aggregations