Skip to content

Commit 2d68e79

Browse files
tkyclilgreenbirdmuskan124947
authored
release/10.2 Test updates (#2637)
* Updated dependency download to pull from Azure Artifacts * Added requireSecret tag * Cherry-picked: azureAADPrincipialId/azureAADPrincipialSecret to applicationKey/applicationClientID * Cherry-picked: ErrorMessageTest update * Update FedAuth tests to use ManagedIdentity (#2629) * Re-enable AE Tests (#2611) * Added error string to TestResource * Test fixes * Test fixes p2 * Test fixes p3 * Test fixes p4: Update tests to run with ManagedIdentity * Test fixes p5: Added missing brace and removed TestUtils.removeProperty method * Test fixes p5: Adjusted test timings and added missing exception to TestResource * Test fixes p6: Added additional requestSecret tag to more tests * Update pom.xml * Add profiles section to pom.xml * Update Maven repository URL to Apache's repository * Reverted to earlier * Change repository ID from mssql-jdbc to central * Add nimbus-jose-jwt dependency to pom.xml * Update Azure dependencies in pom.xml * Clean up pom.xml by removing commented dependencies * Update azure-identity version to 1.15.3 * Remove nimbus-jose-jwt dependency * Remove bumped versions from pom.xml --------- Co-authored-by: lilgreenbird <[email protected]> Co-authored-by: Muskan Gupta <[email protected]>
1 parent 9306a19 commit 2d68e79

28 files changed

+349
-250
lines changed

pom.xml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@
5050
xAzureSQLDB - - - - For tests not compatible with Azure SQL Database - -
5151
xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse -
5252
xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance
53-
NTLM - - - - - - - For tests using NTLM Authentication mode (excluded by default)
54-
reqExternalSetup - For tests requiring external setup (excluded by default)
55-
clientCertAuth - - For tests requiring client certificate authentication setup (excluded by default)
53+
NTLM - - - For tests using NTLM Authentication mode (excluded by default)
54+
kerberos - - - - For tests using Kerberos authentication (excluded by default)
55+
reqExternalSetup - For tests requiring external setup (excluded by default)
56+
clientCertAuth - - For tests requiring client certificate authentication
57+
setup (excluded by default) - - - - - - - - - - - - - - - - - - - - - - -
58+
requireSecret - For tests requiring setting up secrets manually
5659
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5760
Default testing enabled with SQL Server 2019 (SQLv15) -->
58-
<excludedGroups>xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth</excludedGroups>
59-
61+
<excludedGroups>xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth,kerberos,requireSecret</excludedGroups>
6062
<!-- Use -preview for preview release, leave empty for official release. -->
6163
<releaseExt></releaseExt>
6264

@@ -232,7 +234,30 @@
232234
<scope>test</scope>
233235
</dependency>
234236
</dependencies>
235-
237+
<repositories>
238+
<repository>
239+
<id>central</id>
240+
<url>https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1</url>
241+
<releases>
242+
<enabled>true</enabled>
243+
</releases>
244+
<snapshots>
245+
<enabled>true</enabled>
246+
</snapshots>
247+
</repository>
248+
</repositories>
249+
<pluginRepositories>
250+
<pluginRepository>
251+
<id>central</id>
252+
<url>https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1</url>
253+
<releases>
254+
<enabled>true</enabled>
255+
</releases>
256+
<snapshots>
257+
<enabled>true</enabled>
258+
</snapshots>
259+
</pluginRepository>
260+
</pluginRepositories>
236261
<profiles>
237262
<profile>
238263
<id>jre8</id>

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,25 @@ static void setAEConnectionString(String serverName, String url, String protocol
177177
if (!isSqlLinux() && null != serverName && null != url && null != protocol) {
178178
enclaveProperties = "serverName=" + serverName + ";" + Constants.ENCLAVE_ATTESTATIONURL + "=" + url + ";"
179179
+ Constants.ENCLAVE_ATTESTATIONPROTOCOL + "=" + protocol;
180-
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false" + ";columnEncryptionSetting=enabled"
181-
+ ";" + enclaveProperties;
180+
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false;columnEncryptionSetting=enabled;"
181+
+ enclaveProperties;
182182

183183
// show progress if testing multiple servers
184184
if (enclaveServer.length > 1) {
185185
System.out.println("Testing enclave: " + enclaveProperties);
186186
}
187+
188+
// remove the password in connection string
189+
// this is necessary as updateDataSource will only use 1st occurrence
190+
String password = getConfiguredProperty("enclaveServerPassword");
191+
AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString, Constants.PASSWORD,
192+
password);
187193
} else {
188-
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"
189-
+ ";columnEncryptionSetting=enabled";
194+
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false;columnEncryptionSetting=enabled;";
190195
}
196+
197+
// TODO: update AE test servers to support
198+
AETestConnectionString += ";encrypt=false;trustServerCertificate=true;";
191199
}
192200

193201
@BeforeAll

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/BulkCopySendTemporalDataTypesAsStringAETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
@Tag(Constants.xSQLv12)
5858
@Tag(Constants.xAzureSQLDB)
5959
@Tag(Constants.xAzureSQLDW)
60+
@Tag(Constants.reqExternalSetup)
6061
public class BulkCopySendTemporalDataTypesAsStringAETest extends AESetup {
6162
static String inputFile = "BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy.csv";
6263
static String encoding = "UTF-8";

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
@Tag(Constants.xSQLv12)
5252
@Tag(Constants.xAzureSQLDW)
5353
@Tag(Constants.xAzureSQLDB)
54+
@Tag(Constants.reqExternalSetup)
5455
public class CallableStatementTest extends AESetup {
5556

5657
private static String multiStatementsProcedure = AbstractSQLGenerator

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
@Tag(Constants.xAzureSQLDW)
4343
@Tag(Constants.xAzureSQLDB)
4444
@Tag(Constants.reqExternalSetup)
45+
@Tag(Constants.requireSecret)
4546
public class EnclaveTest extends AESetup {
4647
/**
4748
* Tests basic connection.

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
import com.azure.identity.ClientSecretCredentialBuilder;
3030

3131
import java.util.Set;
32-
import java.util.concurrent.ExecutorService;
33-
import java.util.concurrent.Executors;
34-
import java.util.concurrent.Future;
35-
3632
import org.junit.jupiter.api.Tag;
3733
import org.junit.jupiter.params.ParameterizedTest;
3834
import org.junit.jupiter.params.provider.MethodSource;
@@ -64,6 +60,7 @@
6460
@Tag(Constants.xSQLv12)
6561
@Tag(Constants.xAzureSQLDW)
6662
@Tag(Constants.xAzureSQLDB)
63+
@Tag(Constants.reqExternalSetup)
6764
public class JDBCEncryptionDecryptionTest extends AESetup {
6865
private boolean nullable = false;
6966

@@ -105,8 +102,7 @@ public void testJksName(String serverName, String url, String protocol) throws E
105102
public void testAkvName(String serverName, String url, String protocol) throws Exception {
106103
setAEConnectionString(serverName, url, protocol);
107104

108-
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(
109-
applicationClientID, applicationKey);
105+
SQLServerColumnEncryptionAzureKeyVaultProvider akv = akvProvider;
110106
String keystoreName = "keystoreName";
111107
akv.setName(keystoreName);
112108
assertTrue(akv.getName().equals(keystoreName), "AKV name: " + akv.getName() + " keystoreName: " + keystoreName);
@@ -136,6 +132,7 @@ public void testBadJks(String serverName, String url, String protocol) throws Ex
136132
@SuppressWarnings("unused")
137133
@ParameterizedTest
138134
@MethodSource("enclaveParams")
135+
@Tag(Constants.requireSecret)
139136
public void testBadAkvCallback(String serverName, String url, String protocol) throws Exception {
140137
setAEConnectionString(serverName, url, protocol);
141138

@@ -209,8 +206,7 @@ public void testJksBadEncryptColumnEncryptionKey(String serverName, String url,
209206
public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception {
210207
setAEConnectionString(serverName, url, protocol);
211208

212-
SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
213-
akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey);
209+
SQLServerColumnEncryptionAzureKeyVaultProvider akv = akvProvider;
214210

215211
// null encryptedColumnEncryptionKey
216212
try {
@@ -288,8 +284,7 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str
288284
public void testAkvDecryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception {
289285
setAEConnectionString(serverName, url, protocol);
290286

291-
SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
292-
akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey);
287+
SQLServerColumnEncryptionAzureKeyVaultProvider akv = akvProvider;
293288

294289
// null akvpath
295290
try {
@@ -2268,6 +2263,7 @@ void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, Str
22682263
@ParameterizedTest
22692264
@MethodSource("enclaveParams")
22702265
@Tag(Constants.reqExternalSetup)
2266+
@Tag(Constants.requireSecret)
22712267
public void testAkvNameWithAuthCallback(String serverName, String url, String protocol) throws Exception {
22722268
setAEConnectionString(serverName, url, protocol);
22732269

@@ -2286,6 +2282,7 @@ public void testAkvNameWithAuthCallback(String serverName, String url, String pr
22862282
@ParameterizedTest
22872283
@MethodSource("enclaveParams")
22882284
@Tag(Constants.reqExternalSetup)
2285+
@Tag(Constants.requireSecret)
22892286
public void testAkvNameWithTokenCredential(String serverName, String url, String protocol) throws Exception {
22902287
setAEConnectionString(serverName, url, protocol);
22912288

@@ -2307,6 +2304,7 @@ public void testAkvNameWithTokenCredential(String serverName, String url, String
23072304
@ParameterizedTest
23082305
@MethodSource("enclaveParams")
23092306
@Tag(Constants.reqExternalSetup)
2307+
@Tag(Constants.requireSecret)
23102308
public void testAkvBadEncryptColumnEncryptionKeyWithAuthCallback(String serverName, String url,
23112309
String protocol) throws Exception {
23122310
setAEConnectionString(serverName, url, protocol);

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import java.util.Map;
1919
import java.util.Properties;
2020

21+
import com.azure.identity.CredentialUnavailableException;
22+
import com.azure.identity.ManagedIdentityCredential;
23+
import com.azure.identity.ManagedIdentityCredentialBuilder;
24+
2125
import org.junit.jupiter.api.BeforeEach;
2226
import org.junit.jupiter.api.Tag;
2327
import org.junit.jupiter.api.Test;
@@ -43,6 +47,7 @@
4347
*/
4448
@RunWith(JUnitPlatform.class)
4549
@Tag(Constants.MSI)
50+
@Tag(Constants.requireSecret)
4651
public class MSITest extends AESetup {
4752

4853
/*
@@ -365,11 +370,20 @@ private void testNumericAKV(String connStr) throws SQLException {
365370

366371
@BeforeEach
367372
public void registerAKVProvider() throws Exception {
373+
try {
368374
// unregister the custom providers registered in AESetup
369375
SQLServerConnection.unregisterColumnEncryptionKeyStoreProviders();
370376

371377
Map<String, SQLServerColumnEncryptionKeyStoreProvider> map = new HashMap<String, SQLServerColumnEncryptionKeyStoreProvider>();
372-
if (null != applicationClientID && null != applicationKey) {
378+
if (null != akvProviderManagedClientId) {
379+
System.out.println("ManagedIdentityCredential: registering akvProvider");
380+
381+
ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder()
382+
.clientId(akvProviderManagedClientId).build();
383+
akvProvider = new SQLServerColumnEncryptionAzureKeyVaultProvider(credential);
384+
map.put(Constants.AZURE_KEY_VAULT_NAME, akvProvider);
385+
System.out.println("ManagedIdentityCredential: registered akvProvider");
386+
} else if (null != applicationClientID && null != applicationKey) {
373387
File file = null;
374388
try {
375389
file = new File(Constants.MSSQL_JDBC_PROPERTIES);
@@ -386,8 +400,12 @@ public void registerAKVProvider() throws Exception {
386400
file.delete();
387401
}
388402
}
403+
System.out.println("applicationClientID: registered akvProvider");
389404
}
390405

391406
SQLServerConnection.registerColumnEncryptionKeyStoreProviders(map);
407+
} catch (Exception e) {
408+
System.out.println("MSITest registerAKVProvider exception: " +e.getMessage());
409+
}
392410
}
393411
}

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MultiUserAKVTest.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.junit.platform.runner.JUnitPlatform;
3636
import org.junit.runner.RunWith;
3737

38+
import com.azure.identity.ManagedIdentityCredential;
39+
import com.azure.identity.ManagedIdentityCredentialBuilder;
3840
import com.microsoft.sqlserver.jdbc.RandomUtil;
3941
import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider;
4042
import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider;
@@ -58,6 +60,7 @@
5860
@Tag(Constants.xSQLv12)
5961
@Tag(Constants.xAzureSQLDW)
6062
@Tag(Constants.xAzureSQLDB)
63+
@Tag(Constants.reqExternalSetup)
6164
public class MultiUserAKVTest extends AESetup {
6265

6366
private static Map<String, SQLServerColumnEncryptionKeyStoreProvider> requiredKeyStoreProvider = new HashMap<>();
@@ -99,7 +102,7 @@ public static void testCleanUp() throws Exception {
99102
tempMap.put(Constants.CUSTOM_KEYSTORE_NAME, jksProvider);
100103
}
101104

102-
if (null != akvProvider && null != applicationClientID && null != applicationKey) {
105+
if (null != akvProvider) {
103106
tempMap.put(Constants.AZURE_KEY_VAULT_NAME, akvProvider);
104107
}
105108

@@ -111,7 +114,7 @@ public static void testCleanUp() throws Exception {
111114
@Test
112115
@Tag(Constants.reqExternalSetup)
113116
public void decryptedCekIsCachedDuringDecryption() throws Exception {
114-
SQLServerColumnEncryptionAzureKeyVaultProvider provider = createAKVProvider();
117+
SQLServerColumnEncryptionAzureKeyVaultProvider provider = akvProvider;
115118

116119
if (null == provider) {
117120
fail(TestResource.getResource("R_AKVProviderNull"));
@@ -151,8 +154,9 @@ public void decryptedCekIsCachedDuringDecryption() throws Exception {
151154

152155
@Test
153156
@Tag(Constants.reqExternalSetup)
157+
@Tag(Constants.requireSecret)
154158
public void signatureVerificationResultIsCachedDuringVerification() throws Exception {
155-
SQLServerColumnEncryptionAzureKeyVaultProvider provider = createAKVProvider();
159+
SQLServerColumnEncryptionAzureKeyVaultProvider provider = akvProvider;
156160

157161
if (provider == null) {
158162
fail(TestResource.getResource("R_AKVProviderNull"));
@@ -184,7 +188,7 @@ public void signatureVerificationResultIsCachedDuringVerification() throws Excep
184188
@Test
185189
@Tag(Constants.reqExternalSetup)
186190
public void cekCacheEntryIsEvictedAfterTtlExpires() throws Exception {
187-
SQLServerColumnEncryptionAzureKeyVaultProvider provider = createAKVProvider();
191+
SQLServerColumnEncryptionAzureKeyVaultProvider provider = akvProvider;
188192

189193
if (provider == null) {
190194
fail(TestResource.getResource("R_AKVProviderNull"));
@@ -212,7 +216,7 @@ public void cekCacheEntryIsEvictedAfterTtlExpires() throws Exception {
212216
@Test
213217
@Tag(Constants.reqExternalSetup)
214218
public void cekCacheShouldBeDisabledWhenAkvProviderIsRegisteredGlobally() throws Exception {
215-
SQLServerColumnEncryptionAzureKeyVaultProvider provider = createAKVProvider();
219+
SQLServerColumnEncryptionAzureKeyVaultProvider provider = akvProvider;
216220

217221
if (provider == null) {
218222
fail(TestResource.getResource("R_AKVProviderNull"));
@@ -256,8 +260,9 @@ public void cekCacheShouldBeDisabledWhenAkvProviderIsRegisteredGlobally() throws
256260

257261
@Test
258262
@Tag(Constants.reqExternalSetup)
263+
@Tag(Constants.requireSecret)
259264
public void testLocalCekCacheIsScopedToProvider() throws Exception {
260-
SQLServerColumnEncryptionAzureKeyVaultProvider provider = createAKVProvider();
265+
SQLServerColumnEncryptionAzureKeyVaultProvider provider = akvProvider;
261266

262267
if (provider == null) {
263268
fail(TestResource.getResource("R_AKVProviderNull"));
@@ -268,6 +273,8 @@ public void testLocalCekCacheIsScopedToProvider() throws Exception {
268273
fail((new MessageFormat(TestResource.getResource("R_objectNullOrEmpty"))).format(msgArg));
269274
}
270275

276+
SQLServerConnection.unregisterColumnEncryptionKeyStoreProviders();
277+
271278
SQLServerConnection.unregisterColumnEncryptionKeyStoreProviders();
272279
Map<String, SQLServerColumnEncryptionKeyStoreProvider> providerMap = new HashMap<String, SQLServerColumnEncryptionKeyStoreProvider>();
273280
providerMap.put(Constants.AZURE_KEY_VAULT_NAME, akvProvider);
@@ -325,7 +332,7 @@ public void testLocalCekCacheIsScopedToProvider() throws Exception {
325332
}
326333
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
327334
} catch (SQLServerException ex) {
328-
assertTrue(ex.getMessage().contains("AADSTS700016"));
335+
org.junit.jupiter.api.Assertions.assertTrue(ex.getMessage().contains("AADSTS700016"), ex.getMessage());
329336
}
330337
} finally {
331338
dropObject(AETestConnectionString, "TABLE", customProviderTableName);
@@ -608,31 +615,4 @@ private int getCacheSize(String methodName,
608615

609616
return (int) method.invoke(provider);
610617
}
611-
612-
private SQLServerColumnEncryptionAzureKeyVaultProvider createAKVProvider() throws Exception {
613-
614-
SQLServerColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = null;
615-
616-
if (null != applicationClientID && null != applicationKey) {
617-
File file = null;
618-
try {
619-
file = new File(Constants.MSSQL_JDBC_PROPERTIES);
620-
try (OutputStream os = new FileOutputStream(file);) {
621-
Properties props = new Properties();
622-
// Append to the list of hardcoded endpoints
623-
props.setProperty(Constants.AKV_TRUSTED_ENDPOINTS_KEYWORD, ";vault.azure.net");
624-
props.store(os, "");
625-
}
626-
azureKeyVaultProvider = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID,
627-
applicationKey);
628-
629-
} finally {
630-
if (null != file) {
631-
file.delete();
632-
}
633-
}
634-
}
635-
636-
return azureKeyVaultProvider;
637-
}
638618
}

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
@Tag(Constants.xSQLv12)
4343
@Tag(Constants.xAzureSQLDW)
4444
@Tag(Constants.xAzureSQLDB)
45+
@Tag(Constants.reqExternalSetup)
4546
public class PrecisionScaleTest extends AESetup {
4647
private static java.util.Date date = null;
4748
private static int offsetFromGMT = 0;

src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
@Tag(Constants.xSQLv12)
3030
@Tag(Constants.xAzureSQLDW)
3131
@Tag(Constants.xAzureSQLDB)
32+
@Tag(Constants.reqExternalSetup)
3233
public class RegressionAlwaysEncryptedTest extends AESetup {
3334
static String numericTable[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"},};
3435

0 commit comments

Comments
 (0)