|
| 1 | +package oracle.jdbc.provider.hashicorp.hcpvault.configuration; |
| 2 | + |
| 3 | +import oracle.jdbc.provider.TestProperties; |
| 4 | +import oracle.jdbc.spi.OracleConfigurationProvider; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import java.sql.SQLException; |
| 8 | +import java.util.Properties; |
| 9 | + |
| 10 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 11 | + |
| 12 | +/** |
| 13 | + * Test class for the HCP Vault Configuration Provider. |
| 14 | + */ |
| 15 | +public class HcpVaultConfigurationProviderTest { |
| 16 | + |
| 17 | + static { |
| 18 | + OracleConfigurationProvider.allowedProviders.add("hcpvault"); |
| 19 | + } |
| 20 | + |
| 21 | + private static final OracleConfigurationProvider PROVIDER = |
| 22 | + OracleConfigurationProvider.find("hcpvault"); |
| 23 | + |
| 24 | + /** |
| 25 | + * Verifies if HCP Vault Configuration Provider works with CLIENT_CREDENTIALS authentication |
| 26 | + * |
| 27 | + * @throws SQLException if the provider encounters an error |
| 28 | + */ |
| 29 | + @Test |
| 30 | + public void testClientCredentialsAuthentication() throws SQLException { |
| 31 | + // Load parameters from TestProperties |
| 32 | + String baseUrl = TestProperties.getOrAbort(HcpVaultTestProperty.APP_NAME); |
| 33 | + String orgId = "ORG_ID=" + TestProperties.getOrAbort(HcpVaultTestProperty.ORG_ID); |
| 34 | + String projectId = "PROJECT_ID=" + TestProperties.getOrAbort(HcpVaultTestProperty.PROJECT_ID); |
| 35 | + String clientId = "CLIENT_ID=" + TestProperties.getOrAbort(HcpVaultTestProperty.CLIENT_ID); |
| 36 | + String clientSecret = "CLIENT_SECRET=" + TestProperties.getOrAbort(HcpVaultTestProperty.CLIENT_SECRET); |
| 37 | + String secretName = "SECRET_NAME=" + TestProperties.getOrAbort(HcpVaultTestProperty.SECRET_NAME); |
| 38 | + // Compose the connection URL |
| 39 | + String location = composeUrl(baseUrl, orgId, projectId, clientId, clientSecret, secretName); |
| 40 | + |
| 41 | + // Fetch properties using the provider |
| 42 | + Properties properties = PROVIDER.getConnectionProperties(location); |
| 43 | + |
| 44 | + // Assert required properties |
| 45 | + assertTrue(properties.containsKey("URL"), "Contains property URL"); |
| 46 | + assertTrue(properties.containsKey("user"), "Contains property user"); |
| 47 | + assertTrue(properties.containsKey("password"), "Contains property password"); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Composes a full URL from a base URL and query options. |
| 52 | + */ |
| 53 | + private static String composeUrl(String baseUrl, String... options) { |
| 54 | + return String.format("%s?%s", baseUrl, String.join("&", options)); |
| 55 | + } |
| 56 | +} |
0 commit comments