use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenGetAttributesAndSizeThenDelegatesToCreateSession.
@Test
public void createSessionWhenGetAttributesAndSizeThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
Map<String, Object> attributes = createdWebSession.getAttributes();
assertThat(attributes.size()).isEqualTo(0);
given(this.createSession.getAttributeNames()).willReturn(Collections.singleton("a"));
assertThat(attributes.size()).isEqualTo(1);
}
use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenGetAttributesAndValuesThenDelegatesToCreateSession.
@Test
public void createSessionWhenGetAttributesAndValuesThenDelegatesToCreateSession() {
given(this.createSession.getAttributeNames()).willReturn(Collections.singleton("a"));
given(this.createSession.getAttribute("a")).willReturn("b");
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
Map<String, Object> attributes = createdWebSession.getAttributes();
assertThat(attributes.values()).containsExactly("b");
}
use of org.springframework.web.server.WebSession in project spring-security by spring-projects.
the class WebSessionServerSecurityContextRepositoryTests method saveWhenNewContextThenChangeSessionId.
@Test
public void saveWhenNewContextThenChangeSessionId() {
String originalSessionId = this.exchange.getSession().block().getId();
this.repository.save(this.exchange, new SecurityContextImpl()).block();
WebSession session = this.exchange.getSession().block();
assertThat(session.getId()).isNotEqualTo(originalSessionId);
}
use of org.springframework.web.server.WebSession in project spring-security by spring-projects.
the class WebSessionServerCsrfTokenRepositoryTests method saveTokenWhenNullThenDeletes.
@Test
public void saveTokenWhenNullThenDeletes() {
CsrfToken token = this.repository.generateToken(this.exchange).block();
Mono<Void> result = this.repository.saveToken(this.exchange, null);
StepVerifier.create(result).verifyComplete();
WebSession session = this.exchange.getSession().block();
assertThat(session.getAttributes()).isEmpty();
}
use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class SessionAttributesHandlerTests method retrieveAttributes.
@Test
public void retrieveAttributes() {
WebSession session = new MockWebSession();
session.getAttributes().put("attr1", "value1");
session.getAttributes().put("attr2", "value2");
session.getAttributes().put("attr3", new TestBean());
session.getAttributes().put("attr4", new TestBean());
assertThat(sessionAttributesHandler.retrieveAttributes(session).keySet()).as("Named attributes (attr1, attr2) should be 'known' right away").isEqualTo(new HashSet<>(asList("attr1", "attr2")));
// Resolve 'attr3' by type
sessionAttributesHandler.isHandlerSessionAttribute("attr3", TestBean.class);
assertThat(sessionAttributesHandler.retrieveAttributes(session).keySet()).as("Named attributes (attr1, attr2) and resolved attribute (att3) should be 'known'").isEqualTo(new HashSet<>(asList("attr1", "attr2", "attr3")));
}
Aggregations