1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jumpmind.symmetric.web;
22
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.jumpmind.symmetric.test.TestSetupUtil;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.junit.runners.Parameterized;
35 import org.junit.runners.Parameterized.Parameters;
36 import org.springframework.mock.web.MockFilterChain;
37 import org.springframework.mock.web.MockFilterConfig;
38 import org.springframework.mock.web.MockHttpServletRequest;
39 import org.springframework.mock.web.MockHttpServletResponse;
40
41 /***
42 * This simply makes sure the SymmetricFilter is setup correctly.
43 */
44 @RunWith(Parameterized.class)
45 public class AuthenticationFilterTest extends AbstractSymmetricFilterTest {
46
47 public AuthenticationFilterTest(String method, String uri, Map<String, String> parameters) throws Exception {
48 super(method, uri, parameters);
49 }
50
51 @Parameters
52 public static Collection<Object[]> authenticationFilterParams() {
53 final Map<String, String> goodAuthentication = new HashMap<String, String>();
54 goodAuthentication.put(WebConstants.SECURITY_TOKEN, MockNodeService.GOOD_SECURITY_TOKEN);
55 goodAuthentication.put(WebConstants.NODE_ID, MockNodeService.GOOD_NODE_ID);
56 return Arrays.asList(new Object[][] { { "GET", "/ack", goodAuthentication }, { "POST", "/ack", goodAuthentication },
57 { "PUT", "/ack", goodAuthentication }, { "DELETE", "/ack", goodAuthentication },
58 { "TRACE", "/ack", goodAuthentication }, { "OPTIONS", "/ack", goodAuthentication },
59 { "HEAD", "/ack", goodAuthentication }, { "GET", "/pull", goodAuthentication },
60 { "POST", "/pull", goodAuthentication }, { "PUT", "/pull", goodAuthentication },
61 { "DELETE", "/pull", goodAuthentication }, { "TRACE", "/pull", goodAuthentication },
62 { "OPTIONS", "/pull", goodAuthentication }, { "HEAD", "/pull", goodAuthentication },
63 { "GET", "/push", goodAuthentication }, { "POST", "/push", goodAuthentication },
64 { "PUT", "/push", goodAuthentication }, { "DELETE", "/push", goodAuthentication },
65 { "TRACE", "/push", goodAuthentication }, { "OPTIONS", "/push", goodAuthentication },
66 { "HEAD", "/push", goodAuthentication } });
67 }
68
69 @Test
70 public void testAuthenticationFilter() throws Exception {
71
72 final SymmetricFilter filter = new SymmetricFilter();
73 filter.init(new MockFilterConfig(servletContext));
74
75 final MockHttpServletRequest request = TestSetupUtil.createMockHttpServletRequest(servletContext, method, uri, parameters);
76 final MockHttpServletResponse response = new MockHttpServletResponse();
77 filter.doFilter(request, response, new MockFilterChain());
78 Assert.assertEquals(response.getStatus(), HttpServletResponse.SC_FORBIDDEN);
79 filter.destroy();
80 }
81
82 }