use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class SimpMessageHeaderAccessorTests method getDetailedLogMessageWithValuesSet.
@Test
public void getDetailedLogMessageWithValuesSet() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setDestination("/destination");
accessor.setSubscriptionId("subscription");
accessor.setSessionId("session");
accessor.setUser(new TestPrincipal("user"));
accessor.setSessionAttributes(Collections.<String, Object>singletonMap("key", "value"));
accessor.setNativeHeader("nativeKey", "nativeValue");
assertThat(accessor.getDetailedLogMessage("p")).isEqualTo(("MESSAGE destination=/destination subscriptionId=subscription " + "session=session user=user attributes={key=value} nativeHeaders=" + "{nativeKey=[nativeValue]} payload=p"));
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleSubscribeInvalidUserName.
// gh-23836
@Test
public void handleSubscribeInvalidUserName() {
TestPrincipal user = new TestPrincipal("joe%2F");
String sourceDestination = "/user/queue/foo";
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", sourceDestination);
assertThatIllegalArgumentException().isThrownBy(() -> this.resolver.resolveDestination(message));
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleMessageToOtherUser.
// SPR-12444
@Test
public void handleMessageToOtherUser() {
TestSimpUser otherSimpUser = new TestSimpUser("anna");
otherSimpUser.addSessions(new TestSimpSession("456"));
given(this.registry.getUser("anna")).willReturn(otherSimpUser);
TestPrincipal user = new TestPrincipal("joe");
TestPrincipal otherUser = new TestPrincipal("anna");
String sourceDestination = "/user/anna/queue/foo";
Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "456", 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-user456");
assertThat(actual.getSubscribeDestination()).isEqualTo("/user/queue/foo");
assertThat(actual.getUser()).isEqualTo(otherUser.getName());
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleSubscribeOneUserMultipleSessions.
// SPR-11325
@Test
public void handleSubscribeOneUserMultipleSessions() {
TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123"), new TestSimpSession("456"));
given(this.registry.getUser("joe")).willReturn(simpUser);
TestPrincipal user = new TestPrincipal("joe");
Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "456", "/user/queue/foo");
UserDestinationResult actual = this.resolver.resolveDestination(message);
assertThat(actual.getTargetDestinations().size()).isEqualTo(1);
assertThat(actual.getTargetDestinations().iterator().next()).isEqualTo("/queue/foo-user456");
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultUserDestinationResolverTests method handleMessage.
@Test
public void handleMessage() {
TestPrincipal user = new TestPrincipal("joe");
String sourceDestination = "/user/joe/queue/foo";
Message<?> message = createMessage(SimpMessageType.MESSAGE, 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("/user/queue/foo");
assertThat(actual.getUser()).isEqualTo(user.getName());
}
Aggregations