|
27 | 27 | import org.springframework.scheduling.TaskScheduler;
|
28 | 28 | import org.springframework.web.socket.AbstractHttpRequestTests;
|
29 | 29 | import org.springframework.web.socket.WebSocketHandler;
|
| 30 | +import org.springframework.web.socket.handler.TestPrincipal; |
30 | 31 | import org.springframework.web.socket.sockjs.transport.SockJsSessionFactory;
|
31 | 32 | import org.springframework.web.socket.sockjs.transport.TransportHandler;
|
32 | 33 | import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService;
|
@@ -178,6 +179,28 @@ public void handleTransportRequestXhrSend() throws Exception {
|
178 | 179 | verify(this.xhrSendHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
179 | 180 | }
|
180 | 181 |
|
| 182 | + @Test |
| 183 | + public void handleTransportRequestXhrSendWithDifferentUser() throws Exception { |
| 184 | + String sockJsPath = sessionUrlPrefix + "xhr"; |
| 185 | + setRequest("POST", sockJsPrefix + sockJsPath); |
| 186 | + this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); |
| 187 | + |
| 188 | + assertEquals(200, this.servletResponse.getStatus()); // session created |
| 189 | + verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session); |
| 190 | + |
| 191 | + this.session.setPrincipal(new TestPrincipal("little red riding hood")); |
| 192 | + this.servletRequest.setUserPrincipal(new TestPrincipal("wolf")); |
| 193 | + |
| 194 | + resetResponse(); |
| 195 | + reset(this.xhrSendHandler); |
| 196 | + sockJsPath = sessionUrlPrefix + "xhr_send"; |
| 197 | + setRequest("POST", sockJsPrefix + sockJsPath); |
| 198 | + this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); |
| 199 | + |
| 200 | + assertEquals(404, this.servletResponse.getStatus()); |
| 201 | + verifyNoMoreInteractions(this.xhrSendHandler); |
| 202 | + } |
| 203 | + |
181 | 204 |
|
182 | 205 | interface SessionCreatingTransportHandler extends TransportHandler, SockJsSessionFactory {
|
183 | 206 | }
|
|
0 commit comments