use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class StompBrokerRelayMessageHandlerTests method connectMessage.
private Message<byte[]> connectMessage(String sessionId, String user) {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT);
headers.setSessionId(sessionId);
headers.setUser(new TestPrincipal(user));
headers.setLeaveMutable(true);
return MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method ignoreMessage.
@Test
public void ignoreMessage() {
// no destination
TestPrincipal user = new TestPrincipal("joe");
Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", null);
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual).isNull();
// not a user destination
message = createMessage(SimpMessageType.MESSAGE, user, "123", "/queue/foo");
actual = this.resolver.resolveDestination(message);
assertThat(actual).isNull();
// subscribe + not a user destination
message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", "/queue/foo");
actual = this.resolver.resolveDestination(message);
assertThat(actual).isNull();
// no match on message type
message = createMessage(SimpMessageType.CONNECT, user, "123", "user/joe/queue/foo");
actual = this.resolver.resolveDestination(message);
assertThat(actual).isNull();
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleSubscribeForDestinationWithoutLeadingSlash.
// SPR-14044
@Test
public void handleSubscribeForDestinationWithoutLeadingSlash() {
this.resolver.setRemoveLeadingSlash(true);
TestPrincipal user = new TestPrincipal("joe");
String destination = "/user/jms.queue.call";
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, 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(destination);
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleSubscribe.
@Test
public void handleSubscribe() {
TestPrincipal user = new TestPrincipal("joe");
String sourceDestination = "/user/queue/foo";
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", sourceDestination);
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getSourceDestination()).isEqualTo(sourceDestination);
assertThat(actual.getTargetDestinations().size()).isEqualTo(1);
assertThat(actual.getTargetDestinations().iterator().next()).isEqualTo("/queue/foo-user123");
assertThat(actual.getSubscribeDestination()).isEqualTo(sourceDestination);
assertThat(actual.getUser()).isEqualTo(user.getName());
}
use of org.springframework.core.testfixture.security.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);
assertThat(session.getPrincipal()).isSameAs(user);
verifyNoMoreInteractions(nativeSession);
}
Aggregations