Skip to content

Commit 5edf3de

Browse files
committed
Adjust the return propertySource names in unit tests to the full vault path
1 parent 5f6200f commit 5edf3de

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,28 @@ private void defaultKeyTest(String myPathKey, int version) {
7777
assertThat(e.getName()).isEqualTo("myapp");
7878

7979
assertThat(e.getPropertySources()).hasSize(2);
80-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
80+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp");
8181
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
82-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application");
82+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application");
8383
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
8484
}
8585

86+
@Test
87+
public void findOneWithBackend() {
88+
when(keyValueTemplate.get("myapp")).thenReturn(withVaultResponse("foo", "bar"));
89+
90+
var properties = new VaultEnvironmentProperties();
91+
properties.setBackend("custom-path");
92+
93+
var e = springVaultEnvironmentRepository(properties).findOne("myapp", null, null);
94+
95+
assertThat(e.getName()).isEqualTo("myapp");
96+
97+
assertThat(e.getPropertySources()).hasSize(1);
98+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:custom-path/myapp");
99+
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
100+
}
101+
86102
@Test
87103
public void findOneWithSlashesInBackend() {
88104
when(keyValueTemplate.get("myapp")).thenReturn(withVaultResponse("foo", "bar"));
@@ -96,9 +112,9 @@ public void findOneWithSlashesInBackend() {
96112
assertThat(e.getName()).isEqualTo("myapp");
97113

98114
assertThat(e.getPropertySources()).hasSize(2);
99-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
115+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:foo/bar/secret/myapp");
100116
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
101-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application");
117+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:foo/bar/secret/application");
102118
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
103119
}
104120

@@ -115,9 +131,9 @@ public void findOneWithDefaultKeySet() {
115131
assertThat(e.getName()).isEqualTo("myapp");
116132

117133
assertThat(e.getPropertySources()).hasSize(2);
118-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
134+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp");
119135
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
120-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:mydefaultkey");
136+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/mydefaultkey");
121137
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
122138
}
123139

@@ -134,7 +150,7 @@ public void findOneWithEmptyDefaultKey() {
134150
assertThat(e.getName()).isEqualTo("myapp");
135151

136152
assertThat(e.getPropertySources()).hasSize(1);
137-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
153+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp");
138154
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
139155
}
140156

@@ -152,11 +168,11 @@ public void findOneWithDefaultKeyAndMultipleApplicationNames() {
152168
assertThat(e.getName()).isEqualTo("myapp,yourapp");
153169

154170
assertThat(e.getPropertySources()).hasSize(3);
155-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:yourapp");
171+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/yourapp");
156172
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("yourapp-foo", "yourapp-bar"));
157-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:myapp");
173+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/myapp");
158174
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("myapp-foo", "myapp-bar"));
159-
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:mydefaultkey");
175+
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:secret/mydefaultkey");
160176
assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
161177
}
162178

@@ -173,7 +189,7 @@ public void findOneWithDefaultKeySetToApplicationName() {
173189
assertThat(e.getName()).isEqualTo("myapp");
174190

175191
assertThat(e.getPropertySources()).hasSize(1);
176-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
192+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp");
177193
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
178194
}
179195

@@ -191,13 +207,13 @@ public void findOneWithProfile() {
191207
assertThat(e.getName()).isEqualTo("myapp");
192208

193209
assertThat(e.getPropertySources()).hasSize(4);
194-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,pr1");
210+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,pr1");
195211
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo-pr1", "bar-pr1"));
196-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,pr1");
212+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,pr1");
197213
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-pr1-foo", "def-pr1-bar"));
198-
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:myapp");
214+
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:secret/myapp");
199215
assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("foo", "bar"));
200-
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:application");
216+
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:secret/application");
201217
assertThat(e.getPropertySources().get(3).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
202218
}
203219

@@ -217,17 +233,17 @@ public void findOneWithMultipleProfiles() {
217233
assertThat(e.getName()).isEqualTo("myapp");
218234

219235
assertThat(e.getPropertySources()).hasSize(6);
220-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,pr2");
236+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,pr2");
221237
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo-pr2", "bar-pr2"));
222-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,pr2");
238+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,pr2");
223239
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-pr2-foo", "def-pr2-bar"));
224-
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:myapp,pr1");
240+
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:secret/myapp,pr1");
225241
assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("foo-pr1", "bar-pr1"));
226-
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:application,pr1");
242+
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:secret/application,pr1");
227243
assertThat(e.getPropertySources().get(3).getSource()).isEqualTo(Map.of("def-pr1-foo", "def-pr1-bar"));
228-
assertThat(e.getPropertySources().get(4).getName()).isEqualTo("vault:myapp");
244+
assertThat(e.getPropertySources().get(4).getName()).isEqualTo("vault:secret/myapp");
229245
assertThat(e.getPropertySources().get(4).getSource()).isEqualTo(Map.of("foo", "bar"));
230-
assertThat(e.getPropertySources().get(5).getName()).isEqualTo("vault:application");
246+
assertThat(e.getPropertySources().get(5).getName()).isEqualTo("vault:secret/application");
231247
assertThat(e.getPropertySources().get(5).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
232248
}
233249

@@ -244,9 +260,9 @@ public void findOneWithVaultVersioning() {
244260
assertThat(e.getName()).isEqualTo("myapp");
245261

246262
assertThat(e.getPropertySources()).hasSize(2);
247-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp");
263+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp");
248264
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
249-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application");
265+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application");
250266
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
251267
}
252268

@@ -263,9 +279,9 @@ public void findOneWithDefaultLabelWhenLabelEnabled() {
263279
assertThat(e.getName()).isEqualTo("myapp");
264280

265281
assertThat(e.getPropertySources()).hasSize(2);
266-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,default,main");
282+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,default,main");
267283
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
268-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,default,main");
284+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,default,main");
269285
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
270286
}
271287

@@ -284,13 +300,13 @@ public void findOneWithProfileAndDefaultLabelWhenLabelEnabled() {
284300
assertThat(e.getName()).isEqualTo("myapp");
285301

286302
assertThat(e.getPropertySources()).hasSize(4);
287-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,pr1,main");
303+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,pr1,main");
288304
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("pr1-foo", "pr1-bar"));
289-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,pr1,main");
305+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,pr1,main");
290306
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-pr1-foo", "def-pr1-bar"));
291-
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:myapp,default,main");
307+
assertThat(e.getPropertySources().get(2).getName()).isEqualTo("vault:secret/myapp,default,main");
292308
assertThat(e.getPropertySources().get(2).getSource()).isEqualTo(Map.of("foo", "bar"));
293-
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:application,default,main");
309+
assertThat(e.getPropertySources().get(3).getName()).isEqualTo("vault:secret/application,default,main");
294310
assertThat(e.getPropertySources().get(3).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
295311
}
296312

@@ -308,9 +324,9 @@ public void findOneWithCustomDefaultLabelWhenLabelEnabled() {
308324
assertThat(e.getName()).isEqualTo("myapp");
309325

310326
assertThat(e.getPropertySources()).hasSize(2);
311-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,default,custom");
327+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,default,custom");
312328
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
313-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,default,custom");
329+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,default,custom");
314330
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
315331
}
316332

@@ -328,9 +344,9 @@ public void findOneWithCustomLabelWhenLabelEnabled() {
328344
assertThat(e.getName()).isEqualTo("myapp");
329345

330346
assertThat(e.getPropertySources()).hasSize(2);
331-
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:myapp,default,my-label");
347+
assertThat(e.getPropertySources().get(0).getName()).isEqualTo("vault:secret/myapp,default,my-label");
332348
assertThat(e.getPropertySources().get(0).getSource()).isEqualTo(Map.of("foo", "bar"));
333-
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:application,default,my-label");
349+
assertThat(e.getPropertySources().get(1).getName()).isEqualTo("vault:secret/application,default,my-label");
334350
assertThat(e.getPropertySources().get(1).getSource()).isEqualTo(Map.of("def-foo", "def-bar"));
335351
}
336352

0 commit comments

Comments
 (0)