use of org.springframework.core.testfixture.security.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);
assertThat(session.getPrincipal()).isSameAs(user);
}
use of org.springframework.core.testfixture.security.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);
assertThat(session.getPrincipal()).isSameAs(user);
}
use of org.springframework.core.testfixture.security.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
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
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);
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
verifyNoMoreInteractions(this.xhrSendHandler);
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageToClientWithSimpHeartbeat.
@Test
public void handleMessageToClientWithSimpHeartbeat() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.HEARTBEAT);
accessor.setSessionId("s1");
accessor.setUser(new TestPrincipal("joe"));
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
assertThat(actual.getPayload()).isEqualTo("\n");
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method setup.
@BeforeEach
public void setup() {
this.protocolHandler = new StompSubProtocolHandler();
this.channel = Mockito.mock(MessageChannel.class);
this.messageCaptor = ArgumentCaptor.forClass(Message.class);
given(this.channel.send(any())).willReturn(true);
this.session = new TestWebSocketSession();
this.session.setId("s1");
this.session.setPrincipal(new TestPrincipal("joe"));
}
Aggregations