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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations