Search in sources :

Example 76 with MockHttpServletRequest

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

the class OAuth2ClientContextFilterTests method testVanillaCurrentUri.

@Test
public void testVanillaCurrentUri() throws Exception {
    OAuth2ClientContextFilter filter = new OAuth2ClientContextFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setQueryString("foo=bar");
    assertEquals("http://localhost?foo=bar", filter.calculateCurrentUri(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 77 with MockHttpServletRequest

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

the class OAuth2ClientContextFilterTests method testRedirectUri.

public void testRedirectUri(String redirect, Map<String, String> params, String result) throws Exception {
    OAuth2ClientContextFilter filter = new OAuth2ClientContextFilter();
    RedirectStrategy redirectStrategy = Mockito.mock(RedirectStrategy.class);
    filter.setRedirectStrategy(redirectStrategy);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    UserRedirectRequiredException exception = new UserRedirectRequiredException(redirect, params);
    filter.redirectUser(exception, request, response);
    Mockito.verify(redirectStrategy).sendRedirect(request, response, result);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectStrategy(org.springframework.security.web.RedirectStrategy) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) UserRedirectRequiredException(org.springframework.security.oauth2.client.resource.UserRedirectRequiredException)

Example 78 with MockHttpServletRequest

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

the class OAuth2ClientContextFilterTests method testCurrentUriRemovingCode.

@Test
public void testCurrentUriRemovingCode() throws Exception {
    OAuth2ClientContextFilter filter = new OAuth2ClientContextFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setQueryString("code=XXXX&foo=bar");
    assertEquals("http://localhost?foo=bar", filter.calculateCurrentUri(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 79 with MockHttpServletRequest

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

the class SessionManagementConfigServlet31Tests method changeSessionIdDefaultsInServlet31Plus.

@Test
public void changeSessionIdDefaultsInServlet31Plus() throws Exception {
    spy(ReflectionUtils.class);
    Method method = mock(Method.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession();
    request.setServletPath("/login");
    request.setMethod("POST");
    request.setParameter("username", "user");
    request.setParameter("password", "password");
    when(ReflectionUtils.findMethod(HttpServletRequest.class, "changeSessionId")).thenReturn(method);
    loadContext("<http>\n" + "        <form-login/>\n" + "        <session-management/>\n" + "        <csrf disabled='true'/>\n" + "    </http>" + XML_AUTHENTICATION_MANAGER);
    springSecurityFilterChain.doFilter(request, response, chain);
    verifyStatic();
    ReflectionUtils.invokeMethod(same(method), any(HttpServletRequest.class));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Method(java.lang.reflect.Method) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 80 with MockHttpServletRequest

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

the class OpenID4JavaConsumerTests method discoveryExceptionRaisesOpenIDException.

@Test(expected = OpenIDConsumerException.class)
public void discoveryExceptionRaisesOpenIDException() throws Exception {
    ConsumerManager mgr = mock(ConsumerManager.class);
    OpenID4JavaConsumer consumer = new OpenID4JavaConsumer(mgr, new NullAxFetchListFactory());
    when(mgr.discover(anyString())).thenThrow(new DiscoveryException("msg"));
    consumer.beginConsumption(new MockHttpServletRequest(), "", "", "");
}
Also used : ConsumerManager(org.openid4java.consumer.ConsumerManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiscoveryException(org.openid4java.discovery.DiscoveryException)

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