Remove code replaced by ShibbolethRunner
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / serviceprovider / AuthenticationFilterTest.java
1 package edu.internet2.middleware.shibboleth.serviceprovider;
2 import java.io.File;
3
4 import com.mockrunner.mock.web.MockFilterConfig;
5 import com.mockrunner.mock.web.MockHttpServletRequest;
6 import com.mockrunner.mock.web.MockHttpServletResponse;
7 import com.mockrunner.mock.web.MockServletContext;
8 import com.mockrunner.mock.web.WebMockObjectFactory;
9 import com.mockrunner.servlet.ServletTestModule;
10
11 import edu.internet2.middleware.shibboleth.resource.AuthenticationFilter;
12 import edu.internet2.middleware.shibboleth.resource.FilterSupport;
13 import edu.internet2.middleware.shibboleth.resource.FilterSupport.RMAppInfo;
14
15 /**
16  * Use Mockrunner to test the Shib Filter
17  */
18 public class AuthenticationFilterTest extends SPTestCase {
19         
20         // The Factory creates the Request, Response, Session, etc.
21         WebMockObjectFactory factory = new WebMockObjectFactory();
22     
23     // The TestModule runs the Servlet and Filter methods in the simulated container
24         ServletTestModule testModule = new ServletTestModule(factory);
25     
26     // Now simulated Servlet API objects
27         MockServletContext servletContext= new MockServletContext();
28         MockFilterConfig filterConfig= factory.getMockFilterConfig();
29     MockHttpServletResponse response = factory.getMockResponse();
30     MockHttpServletRequest request = factory.getMockRequest();
31         
32         // Filter objects
33         private AuthenticationFilter filter;
34         
35         // SP configuration objects
36         private FilterSupport service;
37         private RMAppInfo rmAppInfo;
38
39         protected void setUp() throws Exception {
40                 super.setUp();
41                 
42         // ServletContext (argument to Filters and Servlets)
43                 servletContext.setServletContextName("dummy Servlet Context");
44         servletContext.setInitParameter("requireId", ".+/test.+");
45                 
46                 // The FilterConfig (argument to Filter init)
47                 filterConfig.setupServletContext(servletContext);
48                 filterConfig.setFilterName("Test Filter under JUnit");
49                 
50                 // Create instance of Filter class, add to chain, call its init()
51                 filter = (AuthenticationFilter) testModule.createFilter(AuthenticationFilter.class);
52         
53                 // Initialize an SP Context and Confg
54                 String configFileName = new File("data/spconfig.xml").toURI().toString();
55                 initServiceProvider(configFileName); 
56                 
57                 // Plug an instance of FilterSupportImpl into the Filter
58                 service = new FilterSupportImpl();
59                 AuthenticationFilter.setFilterSupport(service);
60
61         // Get our own copy of SP Config info for Assert statements
62                 rmAppInfo = service.getRMAppInfo("default");
63
64         request.setRemoteAddr("127.0.0.1");
65         request.setContextPath("/secure");
66         request.setProtocol("HTTP/1.1");
67         request.setScheme("https");
68         request.setServerName("sp.example.org");
69         request.setServerPort(9443);
70         }
71     
72     void setRequestUrls(String suffix) {
73         request.setMethod("GET");
74         request.setRequestURI("http://sp.example.org:9443/secure/"+suffix);
75         request.setRequestURL("http://sp.example.org:9443/secure/"+suffix);
76         request.setServletPath("/secure/"+suffix);
77         
78     }
79         
80         public void testInitialGET() {
81                 
82                 setRequestUrls("test.txt");
83         
84                 // Run the Filter against the request
85                 testModule.doFilter();
86                 
87                 // It should generate a Redirect to the WAYF, with added parameters
88                 assertTrue(response.wasRedirectSent());
89                 String wayfurl = response.getHeader("Location");
90                 assertEquals(rmAppInfo.wayfUrl,wayfurl.substring(0,wayfurl.indexOf('?')));
91         }
92
93 }