Search in sources :

Example 91 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.

the class ServiceThemeResolverTests method verifyGetDefaultServiceWithNoServicesManager.

@Test
public void verifyGetDefaultServiceWithNoServicesManager() {
    this.serviceThemeResolver = new ServiceThemeResolver(DEFAULT_THEME_NAME, null, mobileBrowsers);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "myServiceId");
    request.addHeader(WebUtils.USER_AGENT_HEADER, MOZILLA);
    assertEquals(DEFAULT_THEME_NAME, this.serviceThemeResolver.resolveThemeName(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 92 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class CasAuthenticationFilterTests method testAuthenticateProxyUrl.

@Test
public void testAuthenticateProxyUrl() throws Exception {
    CasAuthenticationFilter filter = new CasAuthenticationFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setServletPath("/pgtCallback");
    filter.setProxyGrantingTicketStorage(mock(ProxyGrantingTicketStorage.class));
    filter.setProxyReceptorUrl(request.getServletPath());
    assertThat(filter.attemptAuthentication(request, response)).isNull();
}
Also used : ProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 93 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class CasAuthenticationFilterTests method testChainNotInvokedForProxyReceptor.

// SEC-1592
@Test
public void testChainNotInvokedForProxyReceptor() throws Exception {
    CasAuthenticationFilter filter = new CasAuthenticationFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    request.setServletPath("/pgtCallback");
    filter.setProxyGrantingTicketStorage(mock(ProxyGrantingTicketStorage.class));
    filter.setProxyReceptorUrl(request.getServletPath());
    filter.doFilter(request, response, chain);
    verifyZeroInteractions(chain);
}
Also used : ProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 94 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class CasAuthenticationFilterTests method testRequiresAuthenticationProxyRequest.

@Test
public void testRequiresAuthenticationProxyRequest() {
    CasAuthenticationFilter filter = new CasAuthenticationFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setServletPath("/pgtCallback");
    assertThat(filter.requiresAuthentication(request, response)).isFalse();
    filter.setProxyReceptorUrl(request.getServletPath());
    assertThat(filter.requiresAuthentication(request, response)).isFalse();
    filter.setProxyGrantingTicketStorage(mock(ProxyGrantingTicketStorage.class));
    assertThat(filter.requiresAuthentication(request, response)).isTrue();
    request.setServletPath("/other");
    assertThat(filter.requiresAuthentication(request, response)).isFalse();
}
Also used : ProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 95 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project spring-security by spring-projects.

the class CasAuthenticationFilterTests method testNullServiceTicketHandledGracefully.

@Test(expected = AuthenticationException.class)
public void testNullServiceTicketHandledGracefully() throws Exception {
    CasAuthenticationFilter filter = new CasAuthenticationFilter();
    filter.setAuthenticationManager(new AuthenticationManager() {

        public Authentication authenticate(Authentication a) {
            throw new BadCredentialsException("Rejected");
        }
    });
    filter.attemptAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse());
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) Authentication(org.springframework.security.core.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3144 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1989 Test (org.junit.jupiter.api.Test)1907 lombok.val (lombok.val)1124 Test (org.junit.Test)752 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)482 MockServletContext (org.springframework.mock.web.MockServletContext)471 MockRequestContext (org.springframework.webflow.test.MockRequestContext)468 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)245 MockFilterChain (org.springframework.mock.web.MockFilterChain)238 JEEContext (org.pac4j.core.context.JEEContext)156 Authentication (org.springframework.security.core.Authentication)144 BeforeEach (org.junit.jupiter.api.BeforeEach)132 HashMap (java.util.HashMap)123 FilterChain (jakarta.servlet.FilterChain)117 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)108 MockHttpSession (org.springframework.mock.web.MockHttpSession)98 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)96 Before (org.junit.Before)82 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)78