use of org.springframework.core.testfixture.security.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);
assertThat(session.getPrincipal()).isSameAs(user);
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method addOneSessionId.
@Test
public void addOneSessionId() {
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
registry.onApplicationEvent(event);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(registry.getUserCount()).isEqualTo(1);
assertThat(simpUser.getSessions().size()).isEqualTo(1);
assertThat(simpUser.getSession("123")).isNotNull();
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method addMultipleSessionIds.
@Test
public void addMultipleSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
message = createMessage(SimpMessageType.CONNECT_ACK, "456");
event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
message = createMessage(SimpMessageType.CONNECT_ACK, "789");
event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(registry.getUserCount()).isEqualTo(1);
assertThat(simpUser.getSessions().size()).isEqualTo(3);
assertThat(simpUser.getSession("123")).isNotNull();
assertThat(simpUser.getSession("456")).isNotNull();
assertThat(simpUser.getSession("789")).isNotNull();
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method removeSessionIds.
@Test
public void removeSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
message = createMessage(SimpMessageType.CONNECT_ACK, "456");
connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
message = createMessage(SimpMessageType.CONNECT_ACK, "789");
connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(simpUser.getSessions().size()).isEqualTo(3);
CloseStatus status = CloseStatus.GOING_AWAY;
message = createMessage(SimpMessageType.DISCONNECT, "456");
SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, message, "456", status, user);
registry.onApplicationEvent(disconnectEvent);
message = createMessage(SimpMessageType.DISCONNECT, "789");
disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
registry.onApplicationEvent(disconnectEvent);
assertThat(simpUser.getSessions().size()).isEqualTo(1);
assertThat(simpUser.getSession("123")).isNotNull();
}
use of org.springframework.core.testfixture.security.TestPrincipal in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method findSubscriptions.
@Test
public void findSubscriptions() throws Exception {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub1", "/match");
SessionSubscribeEvent subscribeEvent = new SessionSubscribeEvent(this, message, user);
registry.onApplicationEvent(subscribeEvent);
message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub2", "/match");
subscribeEvent = new SessionSubscribeEvent(this, message, user);
registry.onApplicationEvent(subscribeEvent);
message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub3", "/not-a-match");
subscribeEvent = new SessionSubscribeEvent(this, message, user);
registry.onApplicationEvent(subscribeEvent);
Set<SimpSubscription> matches = registry.findSubscriptions(subscription -> subscription.getDestination().equals("/match"));
assertThat(matches.size()).isEqualTo(2);
Iterator<SimpSubscription> iterator = matches.iterator();
Set<String> sessionIds = new HashSet<>(2);
sessionIds.add(iterator.next().getId());
sessionIds.add(iterator.next().getId());
assertThat(sessionIds).isEqualTo(new HashSet<>(Arrays.asList("sub1", "sub2")));
}
Aggregations