use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleMessageEncodedUserName.
@Test
public void handleMessageEncodedUserName() {
String userName = "https://joe.openid.example.org/";
TestSimpUser simpUser = new TestSimpUser(userName);
simpUser.addSessions(new TestSimpSession("openid123"));
given(this.registry.getUser(userName)).willReturn(simpUser);
String destination = "/user/" + StringUtils.replace(userName, "/", "%2F") + "/queue/foo";
Message<?> message = createMessage(SimpMessageType.MESSAGE, new TestPrincipal("joe"), null, destination);
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations().size()).isEqualTo(1);
assertThat(actual.getTargetDestinations().iterator().next()).isEqualTo("/queue/foo-useropenid123");
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleMessageForDestinationWithDotSeparator.
// SPR-14044
@Test
public void handleMessageForDestinationWithDotSeparator() {
this.resolver.setRemoveLeadingSlash(true);
TestPrincipal user = new TestPrincipal("joe");
String destination = "/user/joe/jms.queue.call";
Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", destination);
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations().size()).isEqualTo(1);
assertThat(actual.getTargetDestinations().iterator().next()).isEqualTo("jms.queue.call-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/jms.queue.call");
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleUnsubscribe.
@Test
public void handleUnsubscribe() {
TestPrincipal user = new TestPrincipal("joe");
Message<?> message = createMessage(SimpMessageType.UNSUBSCRIBE, user, "123", "/user/queue/foo");
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations().size()).isEqualTo(1);
assertThat(actual.getTargetDestinations().iterator().next()).isEqualTo("/queue/foo-user123");
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class SimpleBrokerMessageHandlerTests method readInactivity.
@Test
public void readInactivity() throws Exception {
this.messageHandler.setHeartbeatValue(new long[] { 0, 1 });
this.messageHandler.setTaskScheduler(this.taskScheduler);
this.messageHandler.start();
ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L));
Runnable heartbeatTask = taskCaptor.getValue();
assertThat(heartbeatTask).isNotNull();
String id = "sess1";
TestPrincipal user = new TestPrincipal("joe");
Message<String> connectMessage = createConnectMessage(id, user, new long[] { 1, 0 });
this.messageHandler.handleMessage(connectMessage);
Thread.sleep(10);
heartbeatTask.run();
verify(this.clientOutChannel, atLeast(2)).send(this.messageCaptor.capture());
List<Message<?>> messages = this.messageCaptor.getAllValues();
assertThat(messages.size()).isEqualTo(2);
MessageHeaders headers = messages.get(0).getHeaders();
assertThat(headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)).isEqualTo(SimpMessageType.CONNECT_ACK);
headers = messages.get(1).getHeaders();
assertThat(headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)).isEqualTo(SimpMessageType.DISCONNECT_ACK);
assertThat(headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)).isEqualTo(id);
assertThat(headers.get(SimpMessageHeaderAccessor.USER_HEADER)).isEqualTo(user);
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class StompBrokerRelayMessageHandlerTests method message.
private Message<byte[]> message(StompCommand command, String sessionId, String user, String destination) {
StompHeaderAccessor accessor = StompHeaderAccessor.create(command);
if (sessionId != null) {
accessor.setSessionId(sessionId);
}
if (user != null) {
accessor.setUser(new TestPrincipal(user));
}
if (destination != null) {
accessor.setDestination(destination);
}
accessor.setLeaveMutable(true);
return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
}
Aggregations