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 org.jumpmind.symmetric.test.TestSetupUtil;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameters;
34 import org.springframework.mock.web.MockFilterChain;
35 import org.springframework.mock.web.MockFilterConfig;
36 import org.springframework.mock.web.MockHttpServletRequest;
37 import org.springframework.mock.web.MockHttpServletResponse;
38
39 /***
40 * This simply makes sure the SymmetricFilter is setup correctly.
41 */
42 @RunWith(Parameterized.class)
43 public class SymmetricRegistrationRequiredTest extends AbstractSymmetricFilterTest {
44
45 private static final String BAD_SECURITY_TOKEN = "2";
46 private static final String BAD_NODE_ID = "2";
47
48 public SymmetricRegistrationRequiredTest(String method, String uri, Map<String, String> parameters)
49 throws Exception {
50 super(method, uri, parameters);
51 }
52
53 @Parameters
54 public static Collection<Object[]> authenticationFilterRegistrationRequiredParams() {
55 final Map<String, String> badAuthentication = new HashMap<String, String>();
56 badAuthentication.put(WebConstants.SECURITY_TOKEN, BAD_SECURITY_TOKEN);
57 badAuthentication.put(WebConstants.NODE_ID, BAD_NODE_ID);
58 return Arrays.asList(new Object[][] { { "GET", "/ack", badAuthentication },
59 { "GET", "/pull", badAuthentication }, { "GET", "/push", badAuthentication } });
60 }
61
62 @Test
63 public void testAuthenticationFilterRegistrationRequired() throws Exception {
64 final SymmetricFilter filter = new SymmetricFilter();
65 filter.init(new MockFilterConfig(servletContext));
66
67 final MockHttpServletRequest request = TestSetupUtil.createMockHttpServletRequest(servletContext, method, uri,
68 parameters);
69 final MockHttpServletResponse response = new MockHttpServletResponse();
70 filter.doFilter(request, response, new MockFilterChain());
71 Assert.assertEquals(response.getStatus(), WebConstants.REGISTRATION_REQUIRED);
72 filter.destroy();
73 }
74
75 }