* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class SAMLIssuerTrustHandlerUnitTestCase extends TestCase {
public void testIssuer() throws Exception {
SAML2IssuerTrustHandler issuerTrustHandler = new SAML2IssuerTrustHandler();
// Create a Protocol Context
MockHttpSession session = new MockHttpSession();
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest servletRequest = new MockHttpServletRequest(session, "POST");
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
HTTPContext httpContext = new HTTPContext(servletRequest, servletResponse, servletContext);
// Create chainConfig for IDP
TrustType trustType = new TrustType();
Map<String, Object> chainOptionsIdp = new HashMap<String, Object>();
IDPType idpType = new IDPType();
idpType.setTrust(trustType);
chainOptionsIdp.put(GeneralConstants.CONFIGURATION, idpType);
SAML2HandlerChainConfig chainConfigIdp = new DefaultSAML2HandlerChainConfig(chainOptionsIdp);
issuerTrustHandler.initChainConfig(chainConfigIdp);
// Create documentHolder
NameIDType issuer = new NameIDType();
AuthnRequestType authnRequestType = new AuthnRequestType("ID_123456789", null);
authnRequestType.setIssuer(issuer);
SAMLDocumentHolder documentHolder = new SAMLDocumentHolder(authnRequestType);
// Create request and response
SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext, null, documentHolder,
SAML2Handler.HANDLER_TYPE.IDP);
SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
// Test localhost
issuer.setValue("http://localhost:8080/sales");
trustType.setDomains("localhost,google.com,somedomain.com");
issuerTrustHandler.handleRequestType(request, response);
// Test somedomain
issuer.setValue("http://www.somedomain.com:8080/sales/");
issuerTrustHandler.handleRequestType(request, response);
// Test non-trusted domain
try {
issuer.setValue("http://www.evil.com:8080/sales/");
issuerTrustHandler.handleRequestType(request, response);
fail("www.evil.com is non-trusted domain");
}
catch (ProcessingException pe) {
Assert.assertEquals(pe.getCause().getClass(), IssuerNotTrustedException.class);
}
// Test google.com
issuer.setValue("google.com");
issuerTrustHandler.handleRequestType(request, response);
issuer.setValue("google.com/a/mposolda1.com");
issuerTrustHandler.handleRequestType(request, response);
}