|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2021 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.
|
|
20 | 20 | import java.util.Map;
|
21 | 21 | import java.util.UUID;
|
22 | 22 |
|
| 23 | +import io.lettuce.core.RedisCommandExecutionException; |
23 | 24 | import org.junit.jupiter.api.BeforeEach;
|
24 | 25 | import org.junit.jupiter.api.Test;
|
25 | 26 | import org.junit.jupiter.api.extension.ExtendWith;
|
26 | 27 |
|
27 | 28 | import org.springframework.beans.factory.annotation.Autowired;
|
28 | 29 | import org.springframework.context.annotation.Bean;
|
29 | 30 | import org.springframework.context.annotation.Configuration;
|
| 31 | +import org.springframework.data.redis.RedisSystemException; |
30 | 32 | import org.springframework.data.redis.connection.DefaultMessage;
|
31 | 33 | import org.springframework.data.redis.core.RedisOperations;
|
32 | 34 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
45 | 47 | import org.springframework.test.context.ContextConfiguration;
|
46 | 48 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
47 | 49 | import org.springframework.test.context.web.WebAppConfiguration;
|
| 50 | +import org.springframework.test.util.ReflectionTestUtils; |
48 | 51 |
|
49 | 52 | import static org.assertj.core.api.Assertions.assertThat;
|
| 53 | +import static org.mockito.ArgumentMatchers.any; |
| 54 | +import static org.mockito.BDDMockito.willThrow; |
| 55 | +import static org.mockito.Mockito.reset; |
| 56 | +import static org.mockito.Mockito.spy; |
50 | 57 |
|
51 | 58 | /**
|
52 | 59 | * Integration tests for {@link RedisIndexedSessionRepository}.
|
@@ -682,6 +689,33 @@ void changeSessionIdSaveConcurrently() {
|
682 | 689 | assertThat(this.repository.findById(copy2.getId())).isNull();
|
683 | 690 | }
|
684 | 691 |
|
| 692 | + // gh-1743 |
| 693 | + @Test |
| 694 | + @SuppressWarnings("unchecked") |
| 695 | + void saveChangeSessionIdWhenFailedRenameOperationExceptionContainsMoreDetailsThenIgnoreError() { |
| 696 | + RedisOperations<Object, Object> sessionRedisOperations = (RedisOperations<Object, Object>) ReflectionTestUtils |
| 697 | + .getField(this.repository, "sessionRedisOperations"); |
| 698 | + RedisOperations<Object, Object> spyOperations = spy(sessionRedisOperations); |
| 699 | + ReflectionTestUtils.setField(this.repository, "sessionRedisOperations", spyOperations); |
| 700 | + |
| 701 | + RedisSession toSave = this.repository.createSession(); |
| 702 | + String sessionId = toSave.getId(); |
| 703 | + |
| 704 | + this.repository.save(toSave); |
| 705 | + RedisIndexedSessionRepository.RedisSession session = this.repository.findById(sessionId); |
| 706 | + this.repository.deleteById(sessionId); |
| 707 | + String newSessionId = session.changeSessionId(); |
| 708 | + |
| 709 | + RedisSystemException redisSystemException = new RedisSystemException(null, |
| 710 | + new RedisCommandExecutionException("ERR no such key. channel: [id: 0xec125091,...")); |
| 711 | + willThrow(redisSystemException).given(spyOperations).rename(any(), any()); |
| 712 | + |
| 713 | + this.repository.save(session); |
| 714 | + assertThat(this.repository.findById(sessionId)).isNull(); |
| 715 | + assertThat(this.repository.findById(newSessionId)).isNull(); |
| 716 | + reset(spyOperations); |
| 717 | + } |
| 718 | + |
685 | 719 | private String getSecurityName() {
|
686 | 720 | return this.context.getAuthentication().getName();
|
687 | 721 | }
|
|
0 commit comments