Skip to content

Commit

Permalink
Add new unit Tests for userpass authentication method && update the e…
Browse files Browse the repository at this point in the history
…xample-test.properties file
  • Loading branch information
MouhsinElmajdouby committed Jan 16, 2025
1 parent f6548e8 commit b14c54b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ojdbc-provider-hashicorp/example-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ public enum DedicatedVaultTestProperty {

VAULT_TOKEN,

VAULT_ADDR
VAULT_ADDR,

VAULT_USERNAME,

VAULT_PASSWORD,

VAULT_NAMESPACE
}

0 comments on commit b14c54b

Please sign in to comment.