Search in sources :

Example 66 with MockHttpSession

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

the class WebAuthenticationDetailsMixinTests method webAuthenticationDetailsSerializeTest.

@Test
public void webAuthenticationDetailsSerializeTest() throws JsonProcessingException, JSONException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("/localhost");
    request.setSession(new MockHttpSession(null, "1"));
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    String actualJson = mapper.writeValueAsString(details);
    JSONAssert.assertEquals(AUTHENTICATION_DETAILS_JSON, actualJson, true);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) MockHttpSession(org.springframework.mock.web.MockHttpSession) Test(org.junit.Test)

Example 67 with MockHttpSession

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

the class HttpSessionDestroyedEventTests method setUp.

@Before
public void setUp() {
    session = new MockHttpSession();
    session.setAttribute("notcontext", "notcontext");
    session.setAttribute("null", null);
    session.setAttribute("context", new SecurityContextImpl());
    destroyedEvent = new HttpSessionDestroyedEvent(session);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MockHttpSession(org.springframework.mock.web.MockHttpSession) Before(org.junit.Before)

Example 68 with MockHttpSession

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

the class HttpSessionEventPublisherTests method publishedEventIsReceivedbyListener.

// ~ Methods
// ========================================================================================================
/**
	 * It's not that complicated so we'll just run it straight through here.
	 */
@Test
public void publishedEventIsReceivedbyListener() {
    HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
    StaticWebApplicationContext context = new StaticWebApplicationContext();
    MockServletContext servletContext = new MockServletContext();
    servletContext.setAttribute(StaticWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    context.setServletContext(servletContext);
    context.registerSingleton("listener", MockApplicationListener.class, null);
    context.refresh();
    MockHttpSession session = new MockHttpSession(servletContext);
    MockApplicationListener listener = (MockApplicationListener) context.getBean("listener");
    HttpSessionEvent event = new HttpSessionEvent(session);
    publisher.sessionCreated(event);
    assertThat(listener.getCreatedEvent()).isNotNull();
    assertThat(listener.getDestroyedEvent()).isNull();
    assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
    listener.setCreatedEvent(null);
    listener.setDestroyedEvent(null);
    publisher.sessionDestroyed(event);
    assertThat(listener.getDestroyedEvent()).isNotNull();
    assertThat(listener.getCreatedEvent()).isNull();
    assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
}
Also used : HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) MockHttpSession(org.springframework.mock.web.MockHttpSession) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 69 with MockHttpSession

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

the class HttpSessionEventPublisherTests method sessionDestroyedNullApplicationContext.

// SEC-2599
@Test(expected = IllegalStateException.class)
public void sessionDestroyedNullApplicationContext() {
    HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
    MockServletContext servletContext = new MockServletContext();
    MockHttpSession session = new MockHttpSession(servletContext);
    HttpSessionEvent event = new HttpSessionEvent(session);
    publisher.sessionDestroyed(event);
}
Also used : HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 70 with MockHttpSession

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

the class HttpSessionEventPublisherTests method publishedEventIsReceivedbyListenerChildContext.

@Test
public void publishedEventIsReceivedbyListenerChildContext() {
    HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
    StaticWebApplicationContext context = new StaticWebApplicationContext();
    MockServletContext servletContext = new MockServletContext();
    servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", context);
    context.setServletContext(servletContext);
    context.registerSingleton("listener", MockApplicationListener.class, null);
    context.refresh();
    MockHttpSession session = new MockHttpSession(servletContext);
    MockApplicationListener listener = (MockApplicationListener) context.getBean("listener");
    HttpSessionEvent event = new HttpSessionEvent(session);
    publisher.sessionCreated(event);
    assertThat(listener.getCreatedEvent()).isNotNull();
    assertThat(listener.getDestroyedEvent()).isNull();
    assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
    listener.setCreatedEvent(null);
    listener.setDestroyedEvent(null);
    publisher.sessionDestroyed(event);
    assertThat(listener.getDestroyedEvent()).isNotNull();
    assertThat(listener.getCreatedEvent()).isNull();
    assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
}
Also used : HttpSessionEventPublisher(org.springframework.security.web.session.HttpSessionEventPublisher) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) MockHttpSession(org.springframework.mock.web.MockHttpSession) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

MockHttpSession (org.springframework.mock.web.MockHttpSession)106 Test (org.junit.Test)84 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)34 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)23 HashMap (java.util.HashMap)13 AbstractWebApiTest (org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)13 MockFilterChain (org.springframework.mock.web.MockFilterChain)12 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)11 ModelAndView (org.springframework.web.servlet.ModelAndView)11 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)9 FilterChain (javax.servlet.FilterChain)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 SessionRegistry (org.springframework.security.core.session.SessionRegistry)8 ConcurrentSessionFilter (org.springframework.security.web.session.ConcurrentSessionFilter)8 Principal (org.apereo.cas.authentication.principal.Principal)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 CasProfile (org.pac4j.cas.profile.CasProfile)7 InputStream (java.io.InputStream)6 Before (org.junit.Before)6