|
3 | 3 | import io.github.jopenlibs.vault.Vault; |
4 | 4 | import io.github.jopenlibs.vault.VaultConfig; |
5 | 5 | import io.github.jopenlibs.vault.VaultException; |
| 6 | +import io.github.jopenlibs.vault.api.Logical.logicalOperations; |
6 | 7 | import io.github.jopenlibs.vault.response.AuthResponse; |
7 | 8 | import io.github.jopenlibs.vault.response.DataMetadata; |
8 | 9 | import io.github.jopenlibs.vault.response.LogicalResponse; |
@@ -306,6 +307,43 @@ public void testList() throws VaultException { |
306 | 307 | assertTrue(keys.contains("hello")); |
307 | 308 | } |
308 | 309 |
|
| 310 | + /** |
| 311 | + * Write a secret, and then verify that its key shows up in the list, returning their subkeys |
| 312 | + * when we use KV Engine version 2. |
| 313 | + * |
| 314 | + * @throws VaultException On error. |
| 315 | + */ |
| 316 | + @Test |
| 317 | + public void testListSubKeys() throws VaultException { |
| 318 | + final Vault vault = container.getRootVault(); |
| 319 | + final Map<String, Object> testMap = Map.of("value", "world", "test", "done"); |
| 320 | + |
| 321 | + vault.logical().write("secret/hello", testMap); |
| 322 | + final List<String> keys = vault.logical() |
| 323 | + .list("secret/hello", logicalOperations.listSubKeys).getListSubkeys(); |
| 324 | + assertTrue(keys.contains("test")); |
| 325 | + assertTrue(keys.contains("value")); |
| 326 | + } |
| 327 | + |
| 328 | + /** |
| 329 | + * Write a secret, and then verify that its key shows up in the list, returning their subkeys |
| 330 | + * when we use KV Engine version 2. |
| 331 | + * |
| 332 | + * @throws VaultException On error. |
| 333 | + */ |
| 334 | + @Test |
| 335 | + public void testListSubKeysV1() throws VaultException { |
| 336 | + final Vault vault = container.getRootVaultWithCustomVaultConfig( |
| 337 | + new VaultConfig().engineVersion(1)); |
| 338 | + final Map<String, Object> testMap = Map.of("value", "world"); |
| 339 | + |
| 340 | + vault.logical().write("secret/hello", testMap); |
| 341 | + final List<String> keys = vault.logical() |
| 342 | + .list("secret/hello", logicalOperations.listSubKeys).getListSubkeys(); |
| 343 | + assertTrue(keys.contains("value")); |
| 344 | + } |
| 345 | + |
| 346 | + |
309 | 347 | /** |
310 | 348 | * Write a secret, and then verify that its key shows up in the list, using KV Engine version |
311 | 349 | * 1. |
|
0 commit comments