Search in sources :

Example 1 with PerryProperties

use of gov.ca.cwds.PerryProperties in project perry by ca-cwds.

the class TestDevAuthenticationProvider method before.

@Before
public void before() {
    authenticationProvider = new DevAuthenticationProvider();
    authenticationProvider.perryProperties = new PerryProperties();
}
Also used : PerryProperties(gov.ca.cwds.PerryProperties) Before(org.junit.Before)

Example 2 with PerryProperties

use of gov.ca.cwds.PerryProperties 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 3 with PerryProperties

use of gov.ca.cwds.PerryProperties 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 4 with PerryProperties

use of gov.ca.cwds.PerryProperties 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)

Example 5 with PerryProperties

use of gov.ca.cwds.PerryProperties in project perry by ca-cwds.

the class IdentityMappingServiceTest method test.

@Test
public void test() {
    IdentityMappingService identityMappingService = new IdentityMappingService();
    PerryProperties configuration = new PerryProperties();
    identityMappingService.setConfiguration(configuration);
    UniversalUserToken universalUserToken = new UniversalUserToken();
    universalUserToken.setUserId("user");
    String user = identityMappingService.map(universalUserToken, "test");
    assert user.equals("user");
}
Also used : UniversalUserToken(gov.ca.cwds.UniversalUserToken) PerryProperties(gov.ca.cwds.PerryProperties) Test(org.junit.Test)

Aggregations

PerryProperties (gov.ca.cwds.PerryProperties)9 Test (org.junit.Test)8 WhiteList (gov.ca.cwds.service.WhiteList)3 FilterChain (javax.servlet.FilterChain)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)3 UniversalUserToken (gov.ca.cwds.UniversalUserToken)2 UniversalUserTokenExtractor (gov.ca.cwds.service.oauth.UniversalUserTokenExtractor)1 HashMap (java.util.HashMap)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 Before (org.junit.Before)1