コード例 #1
0
  @Test
  public void testAnonymous() throws Exception {
    Filter filter = new FalconAuthenticationFilter();

    synchronized (StartupProperties.get()) {
      filter.init(mockConfig);
    }

    CurrentUser.authenticate("nouser");
    Assert.assertEquals(CurrentUser.getUser(), "nouser");

    CurrentUser.authenticate(FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2);
    filter.doFilter(mockRequest, mockResponse, mockChain);
    Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2);
  }
コード例 #2
0
  @Test
  public void testDoFilterWithEmptyDoAsUser() throws Exception {
    Filter filter = new FalconAuthenticationFilter();
    synchronized (StartupProperties.get()) {
      filter.init(mockConfig);
    }

    CurrentUser.authenticate(FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getMethod()).thenReturn("POST");
    Mockito.when(mockRequest.getQueryString())
        .thenReturn("user.name=" + FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM)).thenReturn("");
    filter.doFilter(mockRequest, mockResponse, mockChain);
    Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2);
  }
コード例 #3
0
  @Test
  public void testDoFilterWithDoAsUser() throws Exception {
    Filter filter = new FalconAuthenticationFilter();
    HostnameFilter.HOSTNAME_TL.set("localhost");
    synchronized (StartupProperties.get()) {
      filter.init(mockConfig);
    }

    CurrentUser.authenticate("foo");
    Mockito.when(mockRequest.getMethod()).thenReturn("POST");
    Mockito.when(mockRequest.getQueryString()).thenReturn("user.name=foo");
    Mockito.when(mockRequest.getRemoteUser()).thenReturn("foo");
    Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM))
        .thenReturn("doAsProxyUser");
    Mockito.when(mockRequest.getMethod()).thenReturn("POST");
    filter.doFilter(mockRequest, mockResponse, mockChain);
    Assert.assertEquals(CurrentUser.getUser(), "doAsProxyUser");
  }
コード例 #4
0
  @Test(
      expectedExceptions = AccessControlException.class,
      expectedExceptionsMessageRegExp = "User .* not defined as proxyuser.*")
  public void testDoFilterWithInvalidProxyUser() throws Exception {
    Filter filter = new FalconAuthenticationFilter();
    HostnameFilter.HOSTNAME_TL.set("localhost");
    synchronized (StartupProperties.get()) {
      filter.init(mockConfig);
    }

    CurrentUser.authenticate(FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getMethod()).thenReturn("POST");
    Mockito.when(mockRequest.getQueryString())
        .thenReturn("user.name=" + FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2);
    Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM))
        .thenReturn("doAsProxyUser");
    Mockito.when(mockRequest.getMethod()).thenReturn("POST");
    filter.doFilter(mockRequest, mockResponse, mockChain);
    Assert.assertEquals(CurrentUser.getUser(), "doAsProxyUser");
  }