diff --git a/ojdbc-provider-hashicorp/example-test.properties b/ojdbc-provider-hashicorp/example-test.properties index 70d3da5..636c769 100644 --- a/ojdbc-provider-hashicorp/example-test.properties +++ b/ojdbc-provider-hashicorp/example-test.properties @@ -97,6 +97,18 @@ DEDICATED_VAULT_SECRET_PATH=/v1/admin/secret/data/your-secret-path # Optional key to extract a specific value from the JSON secret KEY=your-secret-key +# Username for Userpass authentication +USERNAME=your-username + +# Password for Userpass authentication +PASSWORD=your-password + +# Optional path to the Userpass authentication mount point in Vault (default: userpass) +AUTH_PATH=userpass + +# Optional namespace for Vault API requests +NAMESPACE=your-namespace + ################################################################################ # HCP VAULT SECRETS CONFIGURATION ################################################################################ diff --git a/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultConfigurationProviderTest.java b/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultConfigurationProviderTest.java index df6a514..ba31570 100644 --- a/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultConfigurationProviderTest.java +++ b/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultConfigurationProviderTest.java @@ -101,6 +101,53 @@ public void testTokenAuthenticationWithKeyOption() throws SQLException { assertTrue(properties.containsKey("password"), "Contains property password"); } + /** + * Verifies if Dedicated Vault Configuration Provider works with TOKEN-based + * authentication. + * Without the key option. + */ + @Test + public void testUserPassAuthenticationWithoutKeyOption() throws SQLException { + String location = + composeUrl(TestProperties.getOrAbort(DedicatedVaultTestProperty.DEDICATED_VAULT_SECRET_PATH), + "VAULT_ADDR="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_ADDR), + "VAULT_USERNAME="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_USERNAME), + "VAULT_PASSWORD="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_PASSWORD), + "VAULT_NAMESPACE="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_NAMESPACE), + "authentication=userpass"); + + + Properties properties = PROVIDER.getConnectionProperties(location); + + assertTrue(properties.containsKey("URL"), "Contains property URL"); + assertTrue(properties.containsKey("user"), "Contains property user"); + assertTrue(properties.containsKey("password"), "Contains property password"); + } + + /** + * Verifies if Dedicated Vault Configuration Provider works with TOKEN-based + * authentication. + * With the key option. + */ + @Test + public void testUserPassAuthenticationWithKeyOption() throws SQLException { + String location = + composeUrl(TestProperties.getOrAbort(DedicatedVaultTestProperty.DEDICATED_VAULT_SECRET_PATH_WITH_MULTIPLE_KEYS), + "key="+TestProperties.getOrAbort(DedicatedVaultTestProperty.KEY), + "VAULT_ADDR="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_ADDR), + "VAULT_USERNAME="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_USERNAME), + "VAULT_PASSWORD="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_PASSWORD), + "VAULT_NAMESPACE="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_NAMESPACE), + "authentication=userpass"); + + + Properties properties = PROVIDER.getConnectionProperties(location); + + assertTrue(properties.containsKey("URL"), "Contains property URL"); + assertTrue(properties.containsKey("user"), "Contains property user"); + assertTrue(properties.containsKey("password"), "Contains property password"); + } + /** * Composes a full URL from a base URL and query options. */ diff --git a/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultTestProperty.java b/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultTestProperty.java index c22b567..7ced1e3 100644 --- a/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultTestProperty.java +++ b/ojdbc-provider-hashicorp/src/test/java/oracle/jdbc/provider/hashicorp/hcpvaultdedicated/configuration/DedicatedVaultTestProperty.java @@ -50,5 +50,11 @@ public enum DedicatedVaultTestProperty { VAULT_TOKEN, - VAULT_ADDR + VAULT_ADDR, + + VAULT_USERNAME, + + VAULT_PASSWORD, + + VAULT_NAMESPACE }