Skip to content

Commit

Permalink
Service principal cert test update for internal pipelines (#2440)
Browse files Browse the repository at this point in the history
* Updated entra auth service principal cert tests to use specific service principal id

* Additional test update

* Test update

* Test update
  • Loading branch information
tkyc committed Jun 6, 2024
1 parent 722c910 commit d90ba9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ public void testActiveDirectoryPasswordFailureOnSubsequentConnectionsWithInvalid
public void testAADServicePrincipalCertAuthFailureOnSubsequentConnectionsWithInvalidatedTokenCacheWithInvalidPassword() throws Exception {
// Should succeed on valid cert field values
String url = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";authentication="
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + applicationClientID
+ ";password=" + certificatePassword + ";clientCertificate=" + clientCertificate;
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + servicePrincipalCertificateApplicationClientId
+ ";clientCertificate=" + clientCertificate;

// Should fail on invalid cert field values
String invalidPasswordUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase
Expand Down Expand Up @@ -428,8 +428,8 @@ public void testAADServicePrincipalAuthWrong() {
public void testAADServicePrincipalCertAuth() {
// certificate from AKV has no password
String url = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";authentication="
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + applicationClientID
+ ";password=" + certificatePassword + ";clientCertificate=" + clientCertificate;
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + servicePrincipalCertificateApplicationClientId
+ ";clientCertificate=" + clientCertificate;
String urlEncrypted = url + ";encrypt=false;trustServerCertificate=true;";

SQLServerDataSource ds = new SQLServerDataSource();
Expand All @@ -450,7 +450,7 @@ public void testAADServicePrincipalCertAuth() {
@Test
public void testAADServicePrincipalCertAuthWrong() {
String baseUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";authentication="
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";userName=" + applicationClientID;
+ SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";userName=" + servicePrincipalCertificateApplicationClientId;

// no certificate provided.
String url = baseUrl;
Expand All @@ -469,7 +469,7 @@ public void testAADServicePrincipalCertAuthWrong() {
validateException(url, "R_readCertError");

// wrong certificate key or password
url = baseUrl + "password=" + azurePassword + ";clientCertificate=" + clientCertificate + ";clientKey=wrongKey;"
url = baseUrl + ";password=" + azurePassword + ";clientCertificate=" + clientCertificate + ";clientKey=wrongKey;"
+ "clientPassword=wrongPassword";
validateException(url, "R_readCertError");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public abstract class AbstractTest {

protected static String applicationClientID = null;
protected static String applicationKey = null;
protected static String servicePrincipalCertificateApplicationClientId = null;
protected static String tenantID;
protected static String[] keyIDs = null;

Expand Down Expand Up @@ -162,6 +163,7 @@ public static void setup() throws Exception {
applicationClientID = getConfiguredProperty("applicationClientID");
applicationKey = getConfiguredProperty("applicationKey");
tenantID = getConfiguredProperty("tenantID");
servicePrincipalCertificateApplicationClientId = getConfiguredProperty("servicePrincipalCertificateApplicationClientId");

accessTokenClientId = getConfiguredProperty("accessTokenClientId");
accessTokenSecret = getConfiguredProperty("accessTokenSecret");
Expand Down

0 comments on commit d90ba9a

Please sign in to comment.