Search in sources :

Example 1 with TestPrincipal

use of org.springframework.web.socket.handler.TestPrincipal in project spring-framework by spring-projects.

the class StandardWebSocketSessionTests method getPrincipalWithConstructorArg.

@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
    TestPrincipal user = new TestPrincipal("joe");
    StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null, user);
    assertSame(user, session.getPrincipal());
}
Also used : TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) Test(org.junit.Test)

Example 2 with TestPrincipal

use of org.springframework.web.socket.handler.TestPrincipal in project spring-framework by spring-projects.

the class StandardWebSocketSessionTests method getPrincipalWithNativeSession.

@Test
@SuppressWarnings("resource")
public void getPrincipalWithNativeSession() {
    TestPrincipal user = new TestPrincipal("joe");
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUserPrincipal()).willReturn(user);
    StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
    session.initializeNativeSession(nativeSession);
    assertSame(user, session.getPrincipal());
}
Also used : TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) Session(javax.websocket.Session) Test(org.junit.Test)

Example 3 with TestPrincipal

use of org.springframework.web.socket.handler.TestPrincipal in project spring-framework by spring-projects.

the class DefaultSockJsServiceTests method handleTransportRequestXhrSendWithDifferentUser.

@Test
public void handleTransportRequestXhrSendWithDifferentUser() throws Exception {
    String sockJsPath = sessionUrlPrefix + "xhr";
    setRequest("POST", sockJsPrefix + sockJsPath);
    this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    // session created
    assertEquals(200, this.servletResponse.getStatus());
    verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
    this.session.setPrincipal(new TestPrincipal("little red riding hood"));
    this.servletRequest.setUserPrincipal(new TestPrincipal("wolf"));
    resetResponse();
    reset(this.xhrSendHandler);
    sockJsPath = sessionUrlPrefix + "xhr_send";
    setRequest("POST", sockJsPrefix + sockJsPath);
    this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertEquals(404, this.servletResponse.getStatus());
    verifyNoMoreInteractions(this.xhrSendHandler);
}
Also used : TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) Test(org.junit.Test)

Example 4 with TestPrincipal

use of org.springframework.web.socket.handler.TestPrincipal in project spring-framework by spring-projects.

the class JettyWebSocketSessionTests method getPrincipalWithConstructorArg.

@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
    TestPrincipal user = new TestPrincipal("joe");
    JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);
    assertSame(user, session.getPrincipal());
}
Also used : TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) Test(org.junit.Test)

Example 5 with TestPrincipal

use of org.springframework.web.socket.handler.TestPrincipal in project spring-framework by spring-projects.

the class JettyWebSocketSessionTests method getPrincipalFromNativeSession.

@Test
@SuppressWarnings("resource")
public void getPrincipalFromNativeSession() {
    TestPrincipal user = new TestPrincipal("joe");
    UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
    given(request.getUserPrincipal()).willReturn(user);
    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(null);
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);
    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);
    reset(nativeSession);
    assertSame(user, session.getPrincipal());
    verifyNoMoreInteractions(nativeSession);
}
Also used : UpgradeResponse(org.eclipse.jetty.websocket.api.UpgradeResponse) TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) UpgradeRequest(org.eclipse.jetty.websocket.api.UpgradeRequest) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 TestPrincipal (org.springframework.web.socket.handler.TestPrincipal)5 Session (javax.websocket.Session)1 Session (org.eclipse.jetty.websocket.api.Session)1 UpgradeRequest (org.eclipse.jetty.websocket.api.UpgradeRequest)1 UpgradeResponse (org.eclipse.jetty.websocket.api.UpgradeResponse)1