package org.apereo.cas.adaptors.x509.web.flow;

import org.apereo.cas.adaptors.x509.authentication.principal.AbstractX509CertificateTests;
import org.apereo.cas.web.flow.config.X509AuthenticationWebflowConfiguration;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Import;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.webflow.context.servlet.ServletExternalContext;
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.test.MockRequestContext;

import java.security.cert.X509Certificate;

import static org.junit.Assert.*;


/**
 * @author Marvin S. Addison
 * @since 3.0.0
 */
@TestPropertySource(locations = {"classpath:/x509.properties"})
@Import(X509AuthenticationWebflowConfiguration.class)
public class X509CertificateCredentialsNonInteractiveActionTests extends AbstractX509CertificateTests {
    
    @Autowired
    @Qualifier("x509Check")
    private Action action;
    
    @Test
    public void verifyNoCredentialsResultsInError() throws Exception {
        final MockRequestContext context = new MockRequestContext();
        context.setExternalContext(new ServletExternalContext(
                new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
        assertEquals("error", this.action.execute(context).getId());
    }

    @Test
    public void verifyCredentialsResultsInSuccess() throws Exception {
        final MockRequestContext context = new MockRequestContext();
        final MockHttpServletRequest request = new MockHttpServletRequest();
        request.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] {VALID_CERTIFICATE});
        context.setExternalContext(new ServletExternalContext(
                new MockServletContext(), request, new MockHttpServletResponse()));
        assertEquals("success", this.action.execute(context).getId());
    }
}

@@ -132,16 +132,92 @@
 eTests;%0A
+import org.apereo.cas.adaptors.x509.config.X509AuthenticationConfiguration;%0A
 import o
@@ -278,32 +278,32 @@
 wConfiguration;%0A
-
 import org.junit
@@ -1120,16 +1120,25 @@
 @Import(
+value = %7B
 X509Auth
@@ -1173,16 +1173,56 @@
 on.class
+, X509AuthenticationConfiguration.class%7D
 )%0Apublic
@@ -1319,21 +1319,17 @@
 Tests %7B%0A
-    
 %0A
+
     @Aut
@@ -1394,13 +1394,9 @@
 on;%0A
-    
 %0A
+
     
@@ -2008,24 +2008,24 @@
 tRequest();%0A
+
         requ
@@ -2103,17 +2103,16 @@
 ficate%5B%5D
- 
 %7BVALID_C

Fix test case in x509