Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
MouhsinElmajdouby committed Dec 26, 2024
1 parent e497be0 commit 65111b9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public char[] getSecret(OracleJsonObject jsonObject) {

@Override
public String getSecretType() {
return "dedicatedvault";
return "hashicorpvault";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -52,8 +53,7 @@ public InputStream getJson(String secretPath) {

@Override
public String getType() {
// We'll reference this in our JDBC URL, e.g. "jdbc:oracle:thin:@config-dedicatedvault://..."
return "dedicatedvault";
return "hashicorpvault";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package oracle.jdbc.provider.hashicorp.dedicated.configuration;

import oracle.jdbc.provider.TestProperties;
import oracle.jdbc.provider.hashicorp.dedicated.configuration.DedicatedVaultTestProperty;
import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider;
import oracle.jdbc.spi.OracleConfigurationProvider;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Test class for the Dedicated Vault Configuration Provider.
*/
public class DedicatedVaultConfigurationProviderTest {

static {
OracleConfigurationProvider.allowedProviders.add("hashicorpvault");
}


private static final OracleConfigurationProvider PROVIDER =
OracleConfigurationProvider.find("hashicorpvault");


/**
* Verifies if Dedicated Vault Configuration Provider works with TOKEN-based authentication and a specific secret name.
*
* @throws SQLException if the provider encounters an error
*/
@Test
public void testTokenAuthentication() throws SQLException {

String location =
composeUrl(TestProperties.getOrAbort(DedicatedVaultTestProperty.DEDICATED_VAULT_SECRET_PATH),
"KEY="+TestProperties.getOrAbort(DedicatedVaultTestProperty.KEY),
"VAULT_ADDR="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_ADDR),
"VAULT_TOKEN="+TestProperties.getOrAbort(DedicatedVaultTestProperty.VAULT_TOKEN));


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.
*/
private static String composeUrl(String baseUrl, String... options) {
return String.format("%s?%s", baseUrl, String.join("&", options));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package oracle.jdbc.provider.hashicorp.dedicated.configuration;

/**
* Enumeration of test properties for Dedicated Vault.
*/
public enum DedicatedVaultTestProperty {
DEDICATED_VAULT_SECRET_PATH,
KEY,
VAULT_TOKEN,
VAULT_ADDR
}

0 comments on commit 65111b9

Please sign in to comment.