Search in sources :

Example 11 with DefaultMessageContext

use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.

the class X509CertificateCredentialsRequestHeaderActionTests method verifyErrorInRequestResultsInError.

@Test
public void verifyErrorInRequestResultsInError() throws Exception {
    val context = new MockRequestContext();
    val messageContext = (DefaultMessageContext) context.getMessageContext();
    messageContext.setMessageSource(mock(MessageSource.class));
    val request = new MockHttpServletRequest();
    request.addHeader("ssl_client_cert", VALID_CERTIFICATE.getContent());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getRequestScope().put(REQUEST_ATTRIBUTE_X509_ERROR, "true");
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 12 with DefaultMessageContext

use of org.springframework.binding.message.DefaultMessageContext in project cas by apereo.

the class X509CertificateCredentialsNonInteractiveActionTests method verifyBadCertificateError.

@Test
public void verifyBadCertificateError() throws Exception {
    val context = new MockRequestContext();
    val messageContext = (DefaultMessageContext) context.getMessageContext();
    messageContext.setMessageSource(mock(MessageSource.class));
    val request = new MockHttpServletRequest();
    request.setAttribute(X509CertificateCredentialsNonInteractiveAction.REQUEST_ATTRIBUTE_X509_CERTIFICATE, new X509Certificate[] { new CasX509Certificate(false) });
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) MessageSource(org.springframework.context.MessageSource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) CasX509Certificate(org.apereo.cas.adaptors.x509.authentication.CasX509Certificate) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)12 DefaultMessageContext (org.springframework.binding.message.DefaultMessageContext)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)12 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 MockServletContext (org.springframework.mock.web.MockServletContext)12 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)12 MockRequestContext (org.springframework.webflow.test.MockRequestContext)12 MessageSource (org.springframework.context.MessageSource)11 Test (org.junit.jupiter.api.Test)8 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MessageFormat (java.text.MessageFormat)1 Locale (java.util.Locale)1 CasX509Certificate (org.apereo.cas.adaptors.x509.authentication.CasX509Certificate)1 Authentication (org.apereo.cas.authentication.Authentication)1 DefaultAuthenticationEventExecutionPlan (org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan)1 DefaultAuthenticationManager (org.apereo.cas.authentication.DefaultAuthenticationManager)1 DefaultAuthenticationResultBuilderFactory (org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory)1 DefaultAuthenticationSystemSupport (org.apereo.cas.authentication.DefaultAuthenticationSystemSupport)1 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)1 DefaultAuthenticationTransactionManager (org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)1