|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2019 the original author or authors. |
| 2 | + * Copyright 2014-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 |
|
25 | 25 | import org.springframework.beans.factory.annotation.Autowired;
|
26 | 26 | import org.springframework.context.annotation.Configuration;
|
| 27 | +import org.springframework.data.redis.core.ReactiveRedisOperations; |
27 | 28 | import org.springframework.session.Session;
|
28 | 29 | import org.springframework.session.data.redis.ReactiveRedisSessionRepository.RedisSession;
|
29 | 30 | import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
|
30 | 31 | import org.springframework.test.context.ContextConfiguration;
|
31 | 32 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
32 | 33 | import org.springframework.test.context.web.WebAppConfiguration;
|
| 34 | +import org.springframework.test.util.ReflectionTestUtils; |
33 | 35 |
|
34 | 36 | import static org.assertj.core.api.Assertions.assertThat;
|
35 | 37 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
| 38 | +import static org.mockito.ArgumentMatchers.endsWith; |
| 39 | +import static org.mockito.BDDMockito.given; |
| 40 | +import static org.mockito.Mockito.reset; |
| 41 | +import static org.mockito.Mockito.spy; |
36 | 42 |
|
37 | 43 | /**
|
38 | 44 | * Integration tests for {@link ReactiveRedisSessionRepository}.
|
@@ -215,6 +221,30 @@ void changeSessionSaveOldSessionInstance() {
|
215 | 221 | assertThat(this.repository.findById(session.getId()).block()).isNotNull();
|
216 | 222 | }
|
217 | 223 |
|
| 224 | + // gh-2281 |
| 225 | + @Test |
| 226 | + @SuppressWarnings("unchecked") |
| 227 | + void saveChangeSessionIdAfterCheckWhenOriginalKeyDoesNotExistsThenIgnoreError() { |
| 228 | + ReactiveRedisOperations<String, Object> sessionRedisOperations = (ReactiveRedisOperations<String, Object>) ReflectionTestUtils |
| 229 | + .getField(this.repository, "sessionRedisOperations"); |
| 230 | + ReactiveRedisOperations<String, Object> spyOperations = spy(sessionRedisOperations); |
| 231 | + ReflectionTestUtils.setField(this.repository, "sessionRedisOperations", spyOperations); |
| 232 | + |
| 233 | + RedisSession toSave = this.repository.createSession().block(); |
| 234 | + String sessionId = toSave.getId(); |
| 235 | + |
| 236 | + given(spyOperations.hasKey(endsWith(sessionId))).willReturn(Mono.just(true)); |
| 237 | + |
| 238 | + this.repository.save(toSave).block(); |
| 239 | + RedisSession session = this.repository.findById(sessionId).block(); |
| 240 | + this.repository.deleteById(sessionId).block(); |
| 241 | + String newSessionId = session.changeSessionId(); |
| 242 | + this.repository.save(session).block(); |
| 243 | + assertThat(this.repository.findById(sessionId).block()).isNull(); |
| 244 | + assertThat(this.repository.findById(newSessionId).block()).isNull(); |
| 245 | + reset(spyOperations); |
| 246 | + } |
| 247 | + |
218 | 248 | @Configuration
|
219 | 249 | @EnableRedisWebSession
|
220 | 250 | static class Config extends BaseConfig {
|
|
0 commit comments