Search in sources :

Example 1 with WhiteList

use of gov.ca.cwds.service.WhiteList in project perry by ca-cwds.

the class TestLoginServiceValidatorFilter method testLoginUrlNotMatchesAndInvalidCallback.

@Test
public void testLoginUrlNotMatchesAndInvalidCallback() throws IOException, ServletException {
    LoginServiceValidatorFilter validatorFilter = new LoginServiceValidatorFilter();
    RequestMatcher requestMatcher = Mockito.mock(RequestMatcher.class);
    validatorFilter.setRequestMatcher(requestMatcher);
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
    Mockito.when(requestMatcher.matches(httpServletRequest)).thenReturn(false);
    Mockito.when(httpServletRequest.getRequestURI()).thenReturn("requestUrl");
    Mockito.when(httpServletRequest.getParameter("callback")).thenReturn("invalidCallbackUrl");
    WhiteList whiteList = new WhiteList();
    PerryProperties perryProperties = new PerryProperties();
    perryProperties.setWhiteList("callbackUrl");
    whiteList.setConfiguration(perryProperties);
    validatorFilter.setWhiteList(whiteList);
    validatorFilter.doFilter(httpServletRequest, httpServletResponse, Mockito.mock(FilterChain.class));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) FilterChain(javax.servlet.FilterChain) WhiteList(gov.ca.cwds.service.WhiteList) HttpServletResponse(javax.servlet.http.HttpServletResponse) PerryProperties(gov.ca.cwds.PerryProperties) Test(org.junit.Test)

Example 2 with WhiteList

use of gov.ca.cwds.service.WhiteList in project perry by ca-cwds.

the class TestLoginServiceValidatorFilter method testLoginUrlMatchesAndValidCallback.

@Test
public void testLoginUrlMatchesAndValidCallback() throws IOException, ServletException {
    LoginServiceValidatorFilter validatorFilter = new LoginServiceValidatorFilter();
    RequestMatcher requestMatcher = Mockito.mock(RequestMatcher.class);
    validatorFilter.setRequestMatcher(requestMatcher);
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
    Mockito.when(requestMatcher.matches(httpServletRequest)).thenReturn(true);
    Mockito.when(httpServletRequest.getRequestURI()).thenReturn("requestUrl");
    Mockito.when(httpServletRequest.getParameter("callback")).thenReturn("callbackUrl");
    WhiteList whiteList = new WhiteList();
    PerryProperties perryProperties = new PerryProperties();
    perryProperties.setWhiteList("callbackUrl");
    whiteList.setConfiguration(perryProperties);
    validatorFilter.setWhiteList(whiteList);
    validatorFilter.doFilter(httpServletRequest, httpServletResponse, Mockito.mock(FilterChain.class));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) FilterChain(javax.servlet.FilterChain) WhiteList(gov.ca.cwds.service.WhiteList) HttpServletResponse(javax.servlet.http.HttpServletResponse) PerryProperties(gov.ca.cwds.PerryProperties) Test(org.junit.Test)

Example 3 with WhiteList

use of gov.ca.cwds.service.WhiteList in project perry by ca-cwds.

the class TestLoginServiceValidatorFilter method testLoginUrlMatchesAndInvalidCallback.

@Test
public void testLoginUrlMatchesAndInvalidCallback() throws IOException, ServletException {
    LoginServiceValidatorFilter validatorFilter = new LoginServiceValidatorFilter();
    RequestMatcher requestMatcher = Mockito.mock(RequestMatcher.class);
    validatorFilter.setRequestMatcher(requestMatcher);
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
    Mockito.when(requestMatcher.matches(httpServletRequest)).thenReturn(true);
    Mockito.when(httpServletRequest.getRequestURI()).thenReturn("requestUrl");
    RequestDispatcher requestDispatcher = Mockito.mock(RequestDispatcher.class);
    Mockito.when(httpServletRequest.getRequestDispatcher("/error")).thenReturn(requestDispatcher);
    Mockito.when(httpServletRequest.getParameter("callback")).thenReturn("invalidCallbackUrl");
    WhiteList whiteList = new WhiteList();
    PerryProperties perryProperties = new PerryProperties();
    perryProperties.setWhiteList("callbackUrl");
    whiteList.setConfiguration(perryProperties);
    validatorFilter.setWhiteList(whiteList);
    validatorFilter.doFilter(httpServletRequest, httpServletResponse, Mockito.mock(FilterChain.class));
    Mockito.verify(requestDispatcher).forward(httpServletRequest, httpServletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) FilterChain(javax.servlet.FilterChain) WhiteList(gov.ca.cwds.service.WhiteList) HttpServletResponse(javax.servlet.http.HttpServletResponse) PerryProperties(gov.ca.cwds.PerryProperties) RequestDispatcher(javax.servlet.RequestDispatcher) Test(org.junit.Test)

Aggregations

PerryProperties (gov.ca.cwds.PerryProperties)3 WhiteList (gov.ca.cwds.service.WhiteList)3 FilterChain (javax.servlet.FilterChain)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Test (org.junit.Test)3 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)3 RequestDispatcher (javax.servlet.RequestDispatcher)1