View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Keith Naas <knaas@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
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  }