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 SymmetricForbiddenFilterTest extends AbstractSymmetricFilterTest {
46
47
48 public SymmetricForbiddenFilterTest(String method, String uri, Map<String, String> parameters) throws Exception {
49 super(method, uri, parameters);
50 }
51
52 @Parameters
53 public static Collection<Object[]> authenticationFilterForbiddenParams() {
54 final Map<String, String> emptyAuthentication = new HashMap<String, String>();
55 emptyAuthentication.put(WebConstants.SECURITY_TOKEN, "");
56 emptyAuthentication.put(WebConstants.NODE_ID, "");
57
58 return Arrays.asList(new Object[][] { { "GET", "/ack", null }, { "GET", "/ack/", null },
59 { "GET", "/ack/more", null }, { "GET", "/ack?name=value", null },
60 { "GET", "/ack?name=value&name=value", null },
61 { "GET", String.format("/ack?%s=1&%s=2", WebConstants.SECURITY_TOKEN, WebConstants.NODE_ID), null },
62 { "GET", "/ack", emptyAuthentication }, { "PUT", "/ack", null }, { "POST", "/ack", null },
63 { "DELETE", "/ack", null }, { "TRACE", "/ack", null }, { "OPTIONS", "/ack", null },
64 { "HEAD", "/ack", null }, { "GET", "/pull", null }, { "GET", "/pull/", null },
65 { "GET", "/pull/more", null }, { "GET", "/pull?name=value", null },
66 { "GET", "/pull?name=value&name=value", null },
67 { "GET", String.format("/pull?%s=1&%s=2", WebConstants.SECURITY_TOKEN, WebConstants.NODE_ID), null },
68 { "GET", "/pull", emptyAuthentication }, { "PUT", "/pull", null }, { "POST", "/pull", null },
69 { "DELETE", "/pull", null }, { "TRACE", "/pull", null }, { "OPTIONS", "/pull", null },
70 { "HEAD", "/pull", null }, { "GET", "/push", null }, { "GET", "/push/", null },
71 { "GET", "/push/more", null }, { "GET", "/push?name=value", null },
72 { "GET", "/push?name=value&name=value", null },
73 { "GET", String.format("/push?%s=1&%s=2", WebConstants.SECURITY_TOKEN, WebConstants.NODE_ID), null },
74 { "GET", "/push", emptyAuthentication }, { "PUT", "/push", null }, { "POST", "/push", null },
75 { "DELETE", "/push", null }, { "TRACE", "/push", null }, { "OPTIONS", "/push", null },
76 { "HEAD", "/push", null }, });
77 }
78
79 @Test
80 public void testAuthenticationFilterForbidden()
81 throws Exception {
82 final SymmetricFilter filter = new SymmetricFilter();
83 filter.init(new MockFilterConfig(servletContext));
84 final MockHttpServletRequest request = TestSetupUtil.createMockHttpServletRequest(servletContext, method, uri, parameters);
85 final MockHttpServletResponse response = new MockHttpServletResponse();
86 filter.doFilter(request, response, new MockFilterChain());
87 Assert.assertEquals(response.getStatus(), HttpServletResponse.SC_FORBIDDEN);
88 filter.destroy();
89 }
90
91 }