-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor: Enable Azure DatabaseTokenProvider if there is azure=true in D…
…B_QUERYPARAMS (#18451)
- Loading branch information
Showing
3 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...st/java/org/openmetadata/service/util/jdbi/DatabaseAuthenticationProviderFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.openmetadata.service.util.jdbi; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DatabaseAuthenticationProviderFactoryTest { | ||
|
||
@Test | ||
void testGet_withAzureTrueInJdbcUrl_returnsAzureDatabaseAuthenticationProvider() { | ||
String jdbcURL = | ||
"jdbc:postgresql://your-database.postgres.database.azure.com:5432/testdb?azure=true&sslmode=require"; | ||
|
||
Optional<DatabaseAuthenticationProvider> provider = | ||
DatabaseAuthenticationProviderFactory.get(jdbcURL); | ||
assertTrue(provider.isPresent(), "Expected AzureDatabaseAuthenticationProvider to be present"); | ||
assertTrue( | ||
provider.get() instanceof AzureDatabaseAuthenticationProvider, | ||
"Expected instance of AzureDatabaseAuthenticationProvider"); | ||
} | ||
|
||
@Test | ||
void testGet_withoutAzureTrueInJdbcUrl_returnsEmptyOptional() { | ||
String jdbcURL = | ||
"jdbc:postgresql://your-database.postgres.database.azure.com:5432/testdb?sslmode=require"; | ||
Optional<DatabaseAuthenticationProvider> provider = | ||
DatabaseAuthenticationProviderFactory.get(jdbcURL); | ||
assertFalse(provider.isPresent(), "Expected no provider to be present"); | ||
} | ||
|
||
@Test | ||
void testGet_withAwsRdsParamsInJdbcUrl_returnsAwsRdsDatabaseAuthenticationProvider() { | ||
String jdbcURL = | ||
"jdbc:mysql://your-aws-db.rds.amazonaws.com:3306/testdb?awsRegion=us-west-2&allowPublicKeyRetrieval=true"; | ||
Optional<DatabaseAuthenticationProvider> provider = | ||
DatabaseAuthenticationProviderFactory.get(jdbcURL); | ||
assertTrue(provider.isPresent(), "Expected AwsRdsDatabaseAuthenticationProvider to be present"); | ||
assertTrue( | ||
provider.get() instanceof AwsRdsDatabaseAuthenticationProvider, | ||
"Expected instance of AwsRdsDatabaseAuthenticationProvider"); | ||
} | ||
|
||
@Test | ||
void testGet_withInvalidUrl_returnsEmptyOptional() { | ||
String jdbcURL = "jdbc:invalidurl://your-db.test?someParam=true"; | ||
Optional<DatabaseAuthenticationProvider> provider = | ||
DatabaseAuthenticationProviderFactory.get(jdbcURL); | ||
assertFalse(provider.isPresent(), "Expected no provider to be present for invalid URL"); | ||
} | ||
} |