|
| 1 | +package oracle.jdbc.provider.hashicorp.dedicated.configuration; |
| 2 | + |
| 3 | +import oracle.jdbc.provider.TestProperties; |
| 4 | +import oracle.jdbc.provider.hashicorp.dedicated.configuration.DedicatedVaultTestProperty; |
| 5 | +import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider; |
| 6 | +import oracle.jdbc.spi.OracleConfigurationProvider; |
| 7 | +import org.junit.jupiter.api.BeforeAll; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import java.sql.SQLException; |
| 11 | +import java.util.Properties; |
| 12 | + |
| 13 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test class for the Dedicated Vault Configuration Provider. |
| 17 | + */ |
| 18 | +public class DedicatedVaultConfigurationProviderTest { |
| 19 | + |
| 20 | + static { |
| 21 | + OracleConfigurationProvider.allowedProviders.add("hashicorpvault"); |
| 22 | + } |
| 23 | + |
| 24 | + |
| 25 | + private static final OracleConfigurationProvider PROVIDER = |
| 26 | + OracleConfigurationProvider.find("hashicorpvault"); |
| 27 | + |
| 28 | + |
| 29 | + /** |
| 30 | + * Verifies if Dedicated Vault Configuration Provider works with TOKEN-based authentication and a specific secret name. |
| 31 | + * |
| 32 | + * @throws SQLException if the provider encounters an error |
| 33 | + */ |
| 34 | + @Test |
| 35 | + public void testTokenAuthentication() throws SQLException { |
| 36 | + |
| 37 | + String location = |
| 38 | + composeUrl(TestProperties.getOrAbort(DedicatedVaultTestProperty.DEDICATED_VAULT_SECRET_PATH), |
| 39 | + "KEY="+TestProperties.getOrAbort(DedicatedVaultTestProperty.KEY), |
| 40 | + "VAULT_ADDR="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_ADDR), |
| 41 | + "VAULT_TOKEN="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_TOKEN)); |
| 42 | + |
| 43 | + |
| 44 | + Properties properties = PROVIDER.getConnectionProperties(location); |
| 45 | + |
| 46 | + assertTrue(properties.containsKey("URL"), "Contains property URL"); |
| 47 | + assertTrue(properties.containsKey("user"), "Contains property user"); |
| 48 | + assertTrue(properties.containsKey("password"), "Contains property password"); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Composes a full URL from a base URL and query options. |
| 53 | + */ |
| 54 | + private static String composeUrl(String baseUrl, String... options) { |
| 55 | + return String.format("%s?%s", baseUrl, String.join("&", options)); |
| 56 | + } |
| 57 | +} |
0 commit comments