Refactor WebSessionStore
- Add WebSessionStore.createWebSession. - Remove remove WebSessionStore.changeSessionId - Add WebSessionStore updateLastAccessTime which allows updating the WebSession lastAccessTime without exposing a method on WebSession in an implementation independent way. - Remove WebSessionStore.storeSession. This method is not necessary since the WebSession that is returned allows saving the WebSession. Additionally, it is error prone since the wrong type might be passed into it. Issue: SPR-15875, 15876
This commit is contained in:
committed by
Rossen Stoyanchev
parent
b7280472d6
commit
86912475af
@@ -74,6 +74,9 @@ public class DefaultWebSessionManagerTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(this.store.createWebSession()).thenReturn(Mono.just(createDefaultWebSession()));
|
||||
when(this.store.updateLastAccessTime(any())).thenAnswer( invocation -> Mono.just(invocation.getArgument(0)));
|
||||
|
||||
this.manager = new DefaultWebSessionManager();
|
||||
this.manager.setSessionIdResolver(this.idResolver);
|
||||
this.manager.setSessionStore(this.store);
|
||||
@@ -106,6 +109,7 @@ public class DefaultWebSessionManagerTests {
|
||||
session.save().block();
|
||||
|
||||
String id = session.getId();
|
||||
verify(this.store).createWebSession();
|
||||
verify(this.store).storeSession(any());
|
||||
verify(this.idResolver).setSessionId(any(), eq(id));
|
||||
}
|
||||
@@ -118,6 +122,7 @@ public class DefaultWebSessionManagerTests {
|
||||
session.getAttributes().put("foo", "bar");
|
||||
session.save().block();
|
||||
|
||||
verify(this.store).createWebSession();
|
||||
verify(this.idResolver).setSessionId(any(), any());
|
||||
verify(this.store).storeSession(any());
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
|
||||
assertNotNull(session);
|
||||
Instant lastAccessTime = Clock.offset(this.sessionManager.getClock(), Duration.ofMinutes(-31)).instant();
|
||||
session = new DefaultWebSession(session, lastAccessTime);
|
||||
store.storeSession(session);
|
||||
session.save().block();
|
||||
|
||||
// Third request: expired session, new session created
|
||||
request = RequestEntity.get(createUri()).header("Cookie", "SESSION=" + id).build();
|
||||
|
||||
Reference in New Issue
Block a user