|
29 | 29 | import org.springframework.scheduling.TaskScheduler;
|
30 | 30 | import org.springframework.web.socket.AbstractHttpRequestTests;
|
31 | 31 | import org.springframework.web.socket.WebSocketHandler;
|
| 32 | +import org.springframework.web.socket.handler.TestPrincipal; |
32 | 33 | import org.springframework.web.socket.server.HandshakeHandler;
|
33 | 34 | import org.springframework.web.socket.server.support.OriginHandshakeInterceptor;
|
34 | 35 | import org.springframework.web.socket.sockjs.transport.SockJsSessionFactory;
|
@@ -243,6 +244,28 @@ public void handleTransportRequestXhrSend() throws Exception {
|
243 | 244 | verify(this.xhrSendHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
244 | 245 | }
|
245 | 246 |
|
| 247 | + @Test |
| 248 | + public void handleTransportRequestXhrSendWithDifferentUser() throws Exception { |
| 249 | + String sockJsPath = sessionUrlPrefix + "xhr"; |
| 250 | + setRequest("POST", sockJsPrefix + sockJsPath); |
| 251 | + this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); |
| 252 | + |
| 253 | + assertEquals(200, this.servletResponse.getStatus()); // session created |
| 254 | + verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session); |
| 255 | + |
| 256 | + this.session.setPrincipal(new TestPrincipal("little red riding hood")); |
| 257 | + this.servletRequest.setUserPrincipal(new TestPrincipal("wolf")); |
| 258 | + |
| 259 | + resetResponse(); |
| 260 | + reset(this.xhrSendHandler); |
| 261 | + sockJsPath = sessionUrlPrefix + "xhr_send"; |
| 262 | + setRequest("POST", sockJsPrefix + sockJsPath); |
| 263 | + this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); |
| 264 | + |
| 265 | + assertEquals(404, this.servletResponse.getStatus()); |
| 266 | + verifyNoMoreInteractions(this.xhrSendHandler); |
| 267 | + } |
| 268 | + |
246 | 269 | @Test
|
247 | 270 | public void handleTransportRequestJsonp() throws Exception {
|
248 | 271 | TransportHandlingSockJsService jsonpService = new TransportHandlingSockJsService(this.taskScheduler, this.jsonpHandler, this.jsonpSendHandler);
|
|
0 commit comments