use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyAttributes.
@Test
public void doNotCopyAttributes() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.setCopyAllAttributes(false);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertEquals(1, attributes.size());
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method defaultConstructor.
@Test
public void defaultConstructor() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertEquals(3, attributes.size());
assertEquals("bar", attributes.get("foo"));
assertEquals("baz", attributes.get("bar"));
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method constructorWithAttributeNames.
@Test
public void constructorWithAttributeNames() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
Set<String> names = Collections.singleton("foo");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertEquals(2, attributes.size());
assertEquals("bar", attributes.get("foo"));
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyHttpSessionId.
@Test
public void doNotCopyHttpSessionId() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.setCopyHttpSessionId(false);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertEquals(1, attributes.size());
assertEquals("bar", attributes.get("foo"));
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class OriginHandshakeInterceptorTests method originValueNoMatch.
@Test
public void originValueNoMatch() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain1.com");
List<String> allowed = Collections.singletonList("http://mydomain2.com");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
}
Aggregations