Skip to content

Commit

Permalink
Tinglwan upgrade ojdbc 23.6.0.24.10 (#112)
Browse files Browse the repository at this point in the history
* Update ojdbc8 version to 23.6.0.24.10

* Update run-tests.yaml

* Fix test error in AzureAppConfigurationProviderURLParserTest$TestServicePrincipleSecret.testValidUrlWithSecret

* Fix test error in AzureAppConfigurationProviderURLParserTest$TestServicePrincipleSecret.testValidUrlWithSecret
  • Loading branch information
ting-lan-wang authored Nov 12, 2024
1 parent c2e48e0 commit 84bcc79
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class AzureAppConfigurationProvider
* in a frequency of 60 seconds if the remote location is unreachable.
*/
private static final long MS_RETRY_INTERVAL = 60_000L;
private final OracleConfigurationCache cache = OracleConfigurationCache
private static final OracleConfigurationCache CACHE = OracleConfigurationCache
.create(100);

/**
Expand All @@ -113,7 +113,7 @@ public class AzureAppConfigurationProvider
@Override
public Properties getConnectionProperties(String location) {
// If the location was already consulted, re-use the properties
Properties cachedProp = cache.get(location);
Properties cachedProp = CACHE.get(location);
if (Objects.nonNull(cachedProp)) {
return cachedProp;
}
Expand All @@ -126,15 +126,15 @@ public Properties getConnectionProperties(String location) {

properties.remove(CONFIG_TTL_JSON_OBJECT_NAME);

cache.put(
CACHE.put(
location,
properties,
configTimeToLive,
() -> this.refreshProperties(location),
MS_REFRESH_TIMEOUT,
MS_RETRY_INTERVAL);
} else {
cache.put(location,
CACHE.put(location,
properties,
() -> this.refreshProperties(location),
MS_REFRESH_TIMEOUT,
Expand All @@ -156,6 +156,15 @@ public String getType() {
return "azure";
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
*/
@Override
public OracleConfigurationCache getCache() {
return CACHE;
}

private Properties getRemoteProperties(String location) {
AzureAppConfigurationURLParser appConfig =
new AzureAppConfigurationURLParser(location);
Expand Down Expand Up @@ -271,12 +280,6 @@ private Properties refreshProperties(String location)
throw new OracleConfigurationProviderNetworkError(e);
}
}

@Override
public Properties removeProperties(String location) {
Properties deletedProp = cache.remove(location);
return deletedProp;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import oracle.jdbc.provider.parameter.Parameter;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.parameter.ParameterSetParser;
import oracle.jdbc.util.OracleConfigurationCache;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -89,7 +90,8 @@ public InputStream getJson(String secretIdentifier) {
Map<String, String> optionsWithSecret = new HashMap<>(options);
optionsWithSecret.put(valueFieldName, secretIdentifier);

ParameterSet parameters = PARAMETER_SET_PARSER.parseNamedValues(optionsWithSecret);
ParameterSet parameters = PARAMETER_SET_PARSER
.parseNamedValues(optionsWithSecret);

String secretContent = KeyVaultSecretFactory.getInstance()
.request(parameters)
Expand All @@ -113,4 +115,13 @@ public InputStream getJson(String secretIdentifier) {
public String getType() {
return "azurevault";
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
*/
@Override
public OracleConfigurationCache getCache() {
return CACHE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import oracle.jdbc.provider.azure.authentication.AzureAuthenticationMethod;
import oracle.jdbc.datasource.impl.OracleDataSource;
import oracle.jdbc.provider.azure.AzureTestProperty;
import oracle.jdbc.spi.OracleConfigurationCachableProvider;
import oracle.jdbc.spi.OracleConfigurationProvider;
import oracle.jdbc.util.OracleConfigurationCache;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
Expand All @@ -65,6 +69,14 @@
* specified by its JavaDoc.
*/
public class AzureAppConfigurationProviderURLParserTest {
private static OracleConfigurationCache CACHE;
@BeforeAll
static void init() {
CACHE = ((AzureAppConfigurationProvider)OracleConfigurationProvider
.find("azure"))
.getCache();
}


/**
* Verifies {@link AzureAuthenticationMethod#SERVICE_PRINCIPLE}
Expand All @@ -83,27 +95,40 @@ void beforeEach() {
AzureTestProperty.AZURE_CLIENT_SECRET),
"AZURE_TENANT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_TENANT_ID)};

AzureAppConfigurationProvider provider =
(AzureAppConfigurationProvider)OracleConfigurationProvider
.find("azure");
}
@Test
void testValidUrlWithSecret() throws SQLException {
verifyValidUrl(options);
String url = composeURL(options);
removeCacheEntry(url);
verifyValidUrl(url);
}

@Test
void testInvalidUrlWithSecret() {
verifyInvalidTypeThrowsException(options);
String invalidUrl = composeURL(options)
.replace("@config-azure", "@config-azurex");
removeCacheEntry(invalidUrl);
verifyInvalidTypeThrowsException(invalidUrl);
}

@Test
void testInvalidKeyWithSecret() {
ConfigurationClient client = getSecretCredentialClient();
verifyInvalidKeyThrowsException(client, options);
String url = composeURL(options);
removeCacheEntry(url);
verifyInvalidKeyThrowsException(client, url);
}

@Test
void testNonWhitelistedKeyWithSecret() {
ConfigurationClient client = getSecretCredentialClient();
verifyNonWhitelistedKeyThrowsException(client, options);
String url = composeURL(options);
removeCacheEntry(url);
verifyNonWhitelistedKeyThrowsException(client, url);
}
}

Expand All @@ -112,40 +137,45 @@ void testNonWhitelistedKeyWithSecret() {
*/
@Test
public void testServicePrincipleCertificate() throws SQLException {
verifyValidUrl(
"AUTHENTICATION=AZURE_SERVICE_PRINCIPAL",
"AZURE_CLIENT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_ID),
"AZURE_CLIENT_CERTIFICATE_PATH=" +
TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_CERTIFICATE_PATH),
"AZURE_TENANT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_TENANT_ID));
String url = composeURL(
"AUTHENTICATION=AZURE_SERVICE_PRINCIPAL",
"AZURE_CLIENT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_ID),
"AZURE_CLIENT_CERTIFICATE_PATH=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_CERTIFICATE_PATH),
"AZURE_TENANT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_TENANT_ID));
removeCacheEntry(url);
verifyValidUrl(url);
}

/**
* Verifies {@link AzureAuthenticationMethod#SERVICE_PRINCIPLE}
*/
@Test
public void testServicePrinciplePfxCertificate() throws SQLException {
verifyValidUrl(
"AUTHENTICATION=AZURE_SERVICE_PRINCIPAL",
"AZURE_CLIENT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_ID),
"AZURE_CLIENT_CERTIFICATE_PATH=" +
TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_PFX_CERTIFICATE_PATH),
"AZURE_CLIENT_CERTIFICATE_PASSWORD=" +
TestProperties.getOrAbort(AzureTestProperty.AZURE_CLIENT_PFX_PASSWORD),
"AZURE_TENANT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_TENANT_ID));
String url = composeURL(
"AUTHENTICATION=AZURE_SERVICE_PRINCIPAL",
"AZURE_CLIENT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_ID),
"AZURE_CLIENT_CERTIFICATE_PATH=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_PFX_CERTIFICATE_PATH),
"AZURE_CLIENT_CERTIFICATE_PASSWORD=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_CLIENT_PFX_PASSWORD),
"AZURE_TENANT_ID=" + TestProperties.getOrAbort(
AzureTestProperty.AZURE_TENANT_ID));
removeCacheEntry(url);
verifyValidUrl(url);
}

/** Verifies a valid URL */
private static void verifyValidUrl(String... options) throws SQLException {
private static void verifyValidUrl(String url) throws SQLException {
// Remove the entry from cache before verifying url


// No changes required, configuration provider is loaded at runtime
OracleDataSource ds = new OracleDataSource();
ds.setURL(composeURL(options));
ds.setURL(url);

// Standard JDBC code
int result = -1;
Expand All @@ -161,11 +191,7 @@ private static void verifyValidUrl(String... options) throws SQLException {
/**
* Verifies an exception thrown with an invalid type of the provider
*/
private static void verifyInvalidTypeThrowsException(String... options) {

String invalidUrl = composeURL(options)
.replace("@config-azure", "@config-azurex");

private static void verifyInvalidTypeThrowsException(String invalidUrl) {
Exception exception = assertThrows(Exception.class,
() -> {
OracleDataSource ds = new OracleDataSource();
Expand All @@ -181,7 +207,7 @@ private static void verifyInvalidTypeThrowsException(String... options) {
* Verifies an invalid key value in App configuration throws Exception
*/
private static void verifyInvalidKeyThrowsException(
ConfigurationClient client, String... options) {
ConfigurationClient client, String url) {
// Name of the invalid key to add to the configuration service.
String key = TestProperties.getOrAbort(
AzureTestProperty.AZURE_APP_CONFIG_KEY) + "jdbc/invalidKey";
Expand All @@ -196,7 +222,7 @@ private static void verifyInvalidKeyThrowsException(
SQLException exception = assertThrows(SQLException.class,
() -> {
OracleDataSource ds = new OracleDataSource();
ds.setURL(composeURL(options));
ds.setURL(url);
ds.getConnection();},
"Should throw an SQLException");
// Expected exception:
Expand All @@ -212,7 +238,7 @@ private static void verifyInvalidKeyThrowsException(
* Verifies a non-whitelisted key value in App configuration throws Exception
*/
private static void verifyNonWhitelistedKeyThrowsException(
ConfigurationClient client, String... options) {
ConfigurationClient client, String url) {
// Name of the non-whitelisted key to add to the configuration service.
String key = TestProperties.getOrAbort(
AzureTestProperty.AZURE_APP_CONFIG_KEY) + "jdbc/oracle.jdbc.newPassword";
Expand All @@ -227,7 +253,7 @@ private static void verifyNonWhitelistedKeyThrowsException(
SQLException exception = assertThrows(SQLException.class,
() -> {
OracleDataSource ds = new OracleDataSource();
ds.setURL(composeURL(options));
ds.setURL(url);
ds.getConnection();},
"Should throw an SQLException");
// Expected exception:
Expand Down Expand Up @@ -268,4 +294,14 @@ private static String composeURL(String... options) {
optionsString);
}

/**
* Remove configuration from the cache in
* {@link AzureAppConfigurationProvider} to ensure the tests are independent.
* @param url to be used in the test
*/
private static void removeCacheEntry(String url) {
String location =
url.replaceFirst("jdbc:oracle:thin:@config-azure://", "");
CACHE.remove(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
import oracle.jdbc.driver.OracleConfigurationJsonProvider;
import oracle.jdbc.provider.gcp.objectstorage.GcpCloudStorageFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.util.OracleConfigurationCache;

/**
* A provider for JSON payload which contains configuration from GCP Cloud
* Storage. See {@link #getJson(String)} for the spec of the JSON payload.
*/
public class GcpCloudStorageConfigurationProvider extends OracleConfigurationJsonProvider {
public class GcpCloudStorageConfigurationProvider
extends OracleConfigurationJsonProvider {

public static final String PROJECT_PARAMETER = "project";
public static final String BUCKET_PARAMETER = "bucket";
Expand Down Expand Up @@ -92,4 +94,12 @@ public InputStream getJson(String location) throws SQLException {
return GcpCloudStorageFactory.getInstance().request(parameterSet).getContent();
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
*/
@Override
public OracleConfigurationCache getCache() {
return CACHE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
import oracle.jdbc.driver.OracleConfigurationJsonProvider;
import oracle.jdbc.provider.gcp.secrets.GcpSecretManagerFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.util.OracleConfigurationCache;

/**
* A provider for JSON payload which contains configuration from GCP Secret
* Manager.
* See {@link #getJson(String)} for the spec of the JSON payload.
**/
public class GcpSecretManagerConfigurationProvider extends OracleConfigurationJsonProvider {
public class GcpSecretManagerConfigurationProvider
extends OracleConfigurationJsonProvider {

@Override
public String getType() {
Expand All @@ -78,4 +80,12 @@ public InputStream getJson(String location) throws SQLException {
GcpSecretManagerFactory.getInstance().request(parameterSet).getContent().getData().toByteArray());
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
*/
@Override
public OracleConfigurationCache getCache() {
return CACHE;
}
}
Loading

0 comments on commit 84bcc79

Please sign in to comment.