|
20 | 20 | import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest; |
21 | 21 | import com.amazonaws.services.secretsmanager.model.GetSecretValueResult; |
22 | 22 | import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException; |
23 | | -import com.fasterxml.jackson.core.JsonProcessingException; |
24 | 23 | import org.junit.jupiter.api.BeforeEach; |
25 | 24 | import org.junit.jupiter.api.Test; |
26 | 25 | import org.mockito.ArgumentCaptor; |
@@ -87,13 +86,31 @@ void throwsExceptionWhenSecretNotFound() { |
87 | 86 | } |
88 | 87 |
|
89 | 88 | @Test |
90 | | - void throwsExceptionWhenSecretIsNotJsonSecret() { |
| 89 | + void shouldProcessTextSecretWhenSecretIsNotJsonSecret() { |
91 | 90 | GetSecretValueResult secretValueResult = new GetSecretValueResult() |
92 | | - .withSecretString("plain text secret string, not json secret"); |
93 | | - when(client.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult); |
| 91 | + .withSecretString("plain text secret string, not json secret").withName("/config/myservice"); |
| 92 | + when(client.getSecretValue(secretValueRequestArgumentCaptor.capture())).thenReturn(secretValueResult); |
| 93 | + |
| 94 | + propertySource.init(); |
| 95 | + |
| 96 | + assertThat(secretValueRequestArgumentCaptor.getValue().getSecretId()).isEqualTo("/config/myservice"); |
| 97 | + assertThat(propertySource.getPropertyNames()).containsExactly("myservice"); |
| 98 | + assertThat(propertySource.getProperty("myservice")).isEqualTo("plain text secret string, not json secret"); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void shouldProcessTextSecretWithPrefix() { |
| 103 | + propertySource = new AwsSecretsManagerPropertySource("/config/myservice2?prefix=service2.", client); |
| 104 | + GetSecretValueResult secretValueResult = new GetSecretValueResult() |
| 105 | + .withSecretString("plain text secret string, not json secret").withName("/config/myservice2"); |
| 106 | + when(client.getSecretValue(secretValueRequestArgumentCaptor.capture())).thenReturn(secretValueResult); |
94 | 107 |
|
95 | | - assertThatThrownBy(() -> propertySource.init()).isInstanceOf(RuntimeException.class) |
96 | | - .extracting(Throwable::getCause).isInstanceOf(JsonProcessingException.class); |
| 108 | + propertySource.init(); |
| 109 | + |
| 110 | + assertThat(secretValueRequestArgumentCaptor.getValue().getSecretId()).isEqualTo("/config/myservice2"); |
| 111 | + assertThat(propertySource.getPropertyNames()).containsExactly("service2.myservice2"); |
| 112 | + assertThat(propertySource.getProperty("service2.myservice2")) |
| 113 | + .isEqualTo("plain text secret string, not json secret"); |
97 | 114 | } |
98 | 115 |
|
99 | 116 | } |
0 commit comments