diff --git a/pom.xml b/pom.xml index 026144f46..321c4226d 100644 --- a/pom.xml +++ b/pom.xml @@ -42,14 +42,16 @@ xAzureSQLDB - - - - For tests not compatible with Azure SQL Database - - xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse - xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance - NTLM - - - - - - - For tests using NTLM Authentication mode (excluded by default) - kerberos - - - - - For tests using Kerberos authentication (excluded by default) + NTLM - - - For tests using NTLM Authentication mode (excluded by default) + kerberos - - - - For tests using Kerberos authentication (excluded by default) reqExternalSetup - For tests requiring external setup (excluded by default) clientCertAuth - - For tests requiring client certificate authentication - setup (excluded by default) - - - - - - - - - - - - - - - - - - - - - - - + setup (excluded by default) - - - - - - - - - - - - - - - - - - - - - - - + requireSecret - For tests requiring setting up secrets manually - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default testing enabled with SQL Server 2019 (SQLv15) --> - xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth,kerberos + + xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth,kerberos,requireSecret -preview @@ -228,7 +230,8 @@ central - https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1 + + https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1 true @@ -240,7 +243,8 @@ central - https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1 + + https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/mssql-jdbc/maven/v1 true @@ -253,7 +257,8 @@ jre8 - ${project.artifactId}-${project.version}.jre8${releaseExt} + + ${project.artifactId}-${project.version}.jre8${releaseExt} org.apache.maven.plugins @@ -261,14 +266,20 @@ 3.8.0 - **/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java - **/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java - **/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java + + **/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java + + **/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java + + **/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java - **/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java - **/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java - **/com/microsoft/sqlserver/jdbc/JDBC43Test.java + + **/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java + + **/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java + + **/com/microsoft/sqlserver/jdbc/JDBC43Test.java 1.8 1.8 @@ -287,7 +298,8 @@ 3.1.1 - ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -296,7 +308,8 @@ maven-surefire-plugin 3.0.0-M1 - + ${excludedGroups}, xJDBC42 @@ -306,7 +319,8 @@ jre11 - ${project.artifactId}-${project.version}.jre11${releaseExt} + + ${project.artifactId}-${project.version}.jre11${releaseExt} org.apache.maven.plugins @@ -314,7 +328,8 @@ 3.8.0 - **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java + + **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java 11 11 @@ -326,9 +341,11 @@ 3.1.1 - ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF - com.microsoft.sqlserver.jdbc + + com.microsoft.sqlserver.jdbc @@ -339,7 +356,8 @@ jre17 - ${project.artifactId}-${project.version}.jre17${releaseExt} + + ${project.artifactId}-${project.version}.jre17${releaseExt} org.apache.maven.plugins @@ -347,7 +365,8 @@ 3.8.0 - **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java + + **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java 17 17 @@ -359,9 +378,11 @@ 3.1.1 - ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF - com.microsoft.sqlserver.jdbc + + com.microsoft.sqlserver.jdbc @@ -372,7 +393,8 @@ jre21 - ${project.artifactId}-${project.version}.jre21${releaseExt} + + ${project.artifactId}-${project.version}.jre21${releaseExt} org.apache.maven.plugins @@ -380,7 +402,8 @@ 3.8.0 - **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java + + **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java 21 21 @@ -392,9 +415,11 @@ 3.1.1 - ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF - com.microsoft.sqlserver.jdbc + + com.microsoft.sqlserver.jdbc @@ -408,7 +433,8 @@ true - ${project.artifactId}-${project.version}.jre23${releaseExt} + + ${project.artifactId}-${project.version}.jre23${releaseExt} org.apache.maven.plugins @@ -416,7 +442,8 @@ 3.8.0 - **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java + + **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java 23 23 @@ -428,9 +455,11 @@ 3.1.1 - ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF - com.microsoft.sqlserver.jdbc + + com.microsoft.sqlserver.jdbc @@ -477,12 +506,16 @@ - + WARN - org.apache.maven.plugins:maven-verifier-plugin + + org.apache.maven.plugins:maven-verifier-plugin - Please consider using the maven-invoker-plugin + + Please consider using the + maven-invoker-plugin (http://maven.apache.org/plugins/maven-invoker-plugin/)! @@ -535,8 +568,10 @@ com.microsoft.sqlserver.jdbc.dataclassification, microsoft.sql - !microsoft.sql,jdk.net;resolution:=optional,* - com.microsoft.sqlserver.jdbc.osgi.Activator + + !microsoft.sql,jdk.net;resolution:=optional,* + + com.microsoft.sqlserver.jdbc.osgi.Activator @@ -573,7 +608,8 @@ true outdated-dependencies.txt - file:///${session.executionRootDirectory}/maven-version-rules.xml + + file:///${session.executionRootDirectory}/maven-version-rules.xml diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java b/src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java index df9e6b956..da8facdd8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java @@ -12,6 +12,8 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.text.MessageFormat; import java.util.Collections; import java.util.Date; @@ -36,7 +38,6 @@ public class ConfigurableRetryLogic { .getLogger("com.microsoft.sqlserver.jdbc.ConfigurableRetryLogic"); private static final String SEMI_COLON = ";"; private static final String COMMA = ","; - private static final String FORWARD_SLASH = "/"; private static final String EQUALS_SIGN = "="; private static final String RETRY_EXEC = "retryExec"; private static final String RETRY_CONN = "retryConn"; @@ -287,12 +288,19 @@ private static String getCurrentClassPath() throws SQLServerException { try { className = new Object() {}.getClass().getEnclosingClass().getName(); location = Class.forName(className).getProtectionDomain().getCodeSource().getLocation().getPath(); - location = location.substring(0, location.length() - 16); - URI uri = new URI(location + FORWARD_SLASH); - return uri.getPath() + DEFAULT_PROPS_FILE; // For now, we only allow "mssql-jdbc.properties" as file name. + + if (Files.isDirectory(Paths + .get(ConfigurableRetryLogic.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) { + // We check if the Path we get from the CodeSource location is a directory. If so, we are running + // from class files and should remove a suffix (i.e. the props file is in a different location from the + // location returned) + location = location.substring(0, location.length() - ("target/classes/").length()); + } + + return new URI(location).getPath() + DEFAULT_PROPS_FILE; // TODO: Allow custom paths } catch (URISyntaxException e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_URLInvalid")); - Object[] msgArgs = {location + FORWARD_SLASH}; + Object[] msgArgs = {location}; throw new SQLServerException(form.format(msgArgs), null, 0, e); } catch (ClassNotFoundException e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnableToFindClass")); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java b/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java index 2f8dda592..5d2c542a0 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java @@ -19,26 +19,36 @@ public class JaasConfiguration extends Configuration { private final Configuration delegate; private AppConfigurationEntry[] defaultValue; - private static AppConfigurationEntry[] generateDefaultConfiguration() { - if (Util.isIBM()) { + private static AppConfigurationEntry[] generateDefaultConfiguration() throws SQLServerException { + try { + if (Util.isIBM()) { + return loadIbmModule(); + } + Class.forName("com.sun.security.auth.module.Krb5LoginModule"); + Map confDetails = new HashMap<>(); + confDetails.put("useTicketCache", "true"); + return new AppConfigurationEntry[] { + new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", + AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)}; + } catch (ClassNotFoundException e) { + throw new SQLServerException(SQLServerException.getErrString("R_moduleNotFound"), null); + } + } + + private static AppConfigurationEntry[] loadIbmModule() throws SQLServerException { + try { + Class.forName("com.ibm.security.auth.module.Krb5LoginModule"); Map confDetailsWithoutPassword = new HashMap<>(); confDetailsWithoutPassword.put("useDefaultCcache", "true"); Map confDetailsWithPassword = new HashMap<>(); - // We generated a two configurations fallback that is suitable for password and password-less authentication - // See - // https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule"; return new AppConfigurationEntry[] { new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, confDetailsWithoutPassword), new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, confDetailsWithPassword)}; - } else { - Map confDetails = new HashMap<>(); - confDetails.put("useTicketCache", "true"); - return new AppConfigurationEntry[] { - new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", - AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)}; + } catch (ClassNotFoundException ex) { + throw new SQLServerException(SQLServerException.getErrString("R_ibmModuleNotFound"), null); } } @@ -47,8 +57,10 @@ private static AppConfigurationEntry[] generateDefaultConfiguration() { * * @param delegate * a possibly null delegate + * @throws SQLServerException + * if neither Kerberos module is found: com.sun.security.auth.module.Krb5LoginModule or com.ibm.security.auth.module.Krb5LoginModule */ - JaasConfiguration(Configuration delegate) { + JaasConfiguration(Configuration delegate) throws SQLServerException { this.delegate = delegate; this.defaultValue = generateDefaultConfiguration(); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java index d02238196..1541d007f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java @@ -43,9 +43,13 @@ final class KerbAuthentication extends SSPIAuthentication { private GSSContext peerContext = null; static { - // Overrides the default JAAS configuration loader. - // This one will forward to the default one in all cases but the default configuration is empty. - Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration())); + try { + // Overrides the default JAAS configuration loader. + // This one will forward to the default one in all cases but the default configuration is empty. + Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration())); + } catch (SQLServerException e) { + throw new RuntimeException("Failed to set JAAS configuration: " + e.getMessage(), e); + } } /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 9d09e1edd..942bfdc26 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -557,6 +557,8 @@ protected Object[][] getContents() { {"R_InvalidRuleFormat", "Wrong number of parameters supplied to rule. Number of parameters: {0}, expected: 2 or 3."}, {"R_InvalidRetryInterval", "Current retry interval: {0}, is longer than queryTimeout: {1}."}, {"R_UnableToFindClass", "Unable to locate specified class: {0}"}, + {"R_ibmModuleNotFound", "com.ibm.security.auth.module.Krb5LoginModule module was not found."}, + {"R_moduleNotFound", "Neither com.sun.security.auth.module.Krb5LoginModule nor com.ibm.security.auth.module.Krb5LoginModule was found."}, }; } // @formatter:on diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java index 374626cbe..551dd55d7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java @@ -47,9 +47,26 @@ private Util() { static final String SYSTEM_JRE = System.getProperty("java.vendor") + " " + System.getProperty("java.version"); private static final Lock LOCK = new ReentrantLock(); + private static Boolean isIBM = null; + static boolean isIBM() { + if (isIBM != null) { + return isIBM; + } + String vmName = System.getProperty("java.vm.name"); - return SYSTEM_JRE.startsWith("IBM") && vmName.startsWith("IBM"); + if (vmName != null && vmName.startsWith("IBM")) { + isIBM = true; + return isIBM; + } + + try { + Class.forName("com.ibm.security.auth.module.Krb5LoginModule"); + isIBM = true; + } catch (ClassNotFoundException ex) { + isIBM = false; + } + return isIBM; } static String getJVMArchOnWindows() { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/BulkCopySendTemporalDataTypesAsStringAETest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/BulkCopySendTemporalDataTypesAsStringAETest.java index 6dd177ab5..47f717f54 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/BulkCopySendTemporalDataTypesAsStringAETest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/BulkCopySendTemporalDataTypesAsStringAETest.java @@ -58,6 +58,7 @@ @Tag(Constants.xAzureSQLDB) @Tag(Constants.xAzureSQLDW) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class BulkCopySendTemporalDataTypesAsStringAETest extends AESetup { static String inputFile = "BulkCopyCSVSendTemporalDataTypesAsStringForBulkCopy.csv"; static String encoding = "UTF-8"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index d259b35a5..8215250ee 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -54,6 +54,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class CallableStatementTest extends AESetup { private static String multiStatementsProcedure = AbstractSQLGenerator diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java index 4b55573af..43dc7ed66 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -44,6 +44,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class EnclaveTest extends AESetup { /** * Tests basic connection. diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 6f3502933..b7cfac547 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -65,6 +65,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class JDBCEncryptionDecryptionTest extends AESetup { private boolean nullable = false; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java index 9aeb0da8f..360e172a1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java @@ -42,6 +42,7 @@ */ @RunWith(JUnitPlatform.class) @Tag(Constants.MSI) +@Tag(Constants.requireSecret) public class MSITest extends AESetup { /* diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MultiUserAKVTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MultiUserAKVTest.java index 2619a79b5..614895608 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MultiUserAKVTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MultiUserAKVTest.java @@ -59,6 +59,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class MultiUserAKVTest extends AESetup { private static Map requiredKeyStoreProvider = new HashMap<>(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java index cef219d4a..ca4162154 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java @@ -33,6 +33,7 @@ @Tag(Constants.xSQLv12) @Tag(Constants.xSQLv14) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class ParameterMetaDataCacheTest extends AESetup { @BeforeAll diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 162fe8cef..dcbe907b5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -43,6 +43,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class PrecisionScaleTest extends AESetup { private static java.util.Date date = null; private static int offsetFromGMT = 0; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index d8725cdbe..c8f33573a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -30,6 +30,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class RegressionAlwaysEncryptedTest extends AESetup { static String numericTable[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"},}; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java index 5f3c1165c..174755d4b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java @@ -33,6 +33,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) +@Tag(Constants.requireSecret) public class EnclavePackageTest extends AbstractTest { private static String connectionStringEnclave = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java index 47f0a9252..50ecaa768 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java @@ -92,6 +92,45 @@ private static void createKerberosConnection(String connectionString) throws Exc } } + /** + * Test to verify the Kerberos module used + */ + @Test + public void testKerberosConnectionWithDefaultJaasConfig() { + try { + // Set a mock JAAS configuration using the existing method + overwriteJaasConfig(); + + String connectionString = connectionStringKerberos + ";useDefaultJaasConfig=true;"; + createKerberosConnection(connectionString); + + Configuration config = Configuration.getConfiguration(); + AppConfigurationEntry[] entries = config.getAppConfigurationEntry("CLIENT_CONTEXT_NAME"); + Assertions.assertNotNull(entries); + Assertions.assertTrue(entries.length > 0); + if (Util.isIBM()) { + Assertions.assertEquals("com.ibm.security.auth.module.Krb5LoginModule", entries[0].getLoginModuleName()); + } else { + Assertions.assertEquals("com.sun.security.auth.module.Krb5LoginModule", entries[0].getLoginModuleName()); + } + } catch (Exception e) { + Assertions.fail("Exception was thrown: " + e.getMessage()); + } + } + + /** + * Test to verify the JaasConfiguration constructor + */ + @Test + public void testJaasConfigurationConstructor() { + try { + JaasConfiguration config = new JaasConfiguration(Configuration.getConfiguration()); + Assertions.assertNotNull(config); + } catch (SQLServerException e) { + Assertions.fail("Exception was thrown: " + e.getMessage()); + } + } + /** * Overwrites the default JAAS config. Call before making a connection. */ diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java index 72dae99f9..7c7f2240d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java @@ -23,6 +23,7 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class ConcurrentLoginTest extends FedauthCommon { final AtomicReference throwableRef = new AtomicReference(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionEncryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionEncryptionTest.java index a1a2a5fd4..b7e307654 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionEncryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionEncryptionTest.java @@ -29,6 +29,7 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class ConnectionEncryptionTest extends FedauthCommon { static String charTable = TestUtils.escapeSingleQuotes( diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java index 94e70a142..c9e34d8b2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java @@ -31,6 +31,7 @@ @RunWith(JUnitPlatform.class) @Tag("slow") @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class ConnectionSuspensionTest extends FedauthCommon { static String charTable = TestUtils.escapeSingleQuotes( diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java index dd4d95239..ebe87e65c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java @@ -25,6 +25,7 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class ErrorMessageTest extends FedauthCommon { String badUserName = "abc" + azureUserName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java index f3e4e957f..436ca8e17 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java @@ -42,6 +42,7 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class FedauthTest extends FedauthCommon { static String charTable = TestUtils .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBC_FedAuthTest"))); @@ -366,8 +367,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=" + servicePrincipalCertificateApplicationClientId - + ";clientCertificate=" + clientCertificate; + + SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + + servicePrincipalCertificateApplicationClientId + ";clientCertificate=" + clientCertificate; // Should fail on invalid cert field values String invalidPasswordUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase @@ -428,8 +429,8 @@ public void testAADServicePrincipalAuthWrong() { public void testAADServicePrincipalCertAuth() { // certificate from AKV has no password String url = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";authentication=" - + SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + servicePrincipalCertificateApplicationClientId - + ";clientCertificate=" + clientCertificate; + + SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";Username=" + + servicePrincipalCertificateApplicationClientId + ";clientCertificate=" + clientCertificate; String urlEncrypted = url + ";encrypt=false;trustServerCertificate=true;"; SQLServerDataSource ds = new SQLServerDataSource(); @@ -450,7 +451,8 @@ public void testAADServicePrincipalCertAuth() { @Test public void testAADServicePrincipalCertAuthWrong() { String baseUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";authentication=" - + SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";userName=" + servicePrincipalCertificateApplicationClientId; + + SqlAuthentication.ActiveDirectoryServicePrincipalCertificate + ";userName=" + + servicePrincipalCertificateApplicationClientId; // no certificate provided. String url = baseUrl; @@ -469,8 +471,8 @@ public void testAADServicePrincipalCertAuthWrong() { validateException(url, "R_readCertError"); // wrong certificate key or password - url = baseUrl + ";password=" + azurePassword + ";clientCertificate=" + clientCertificate + ";clientKey=wrongKey;" - + "clientPassword=wrongPassword"; + url = baseUrl + ";password=" + azurePassword + ";clientCertificate=" + clientCertificate + + ";clientKey=wrongKey;" + "clientPassword=wrongPassword"; validateException(url, "R_readCertError"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java index 1e0112f02..e42cc9f56 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java @@ -37,6 +37,7 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class FedauthWithAE extends FedauthCommon { static String cmkName1 = Constants.CMK_NAME + "fedauthAE1"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java index 85a232fd0..604782eab 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -58,6 +58,7 @@ @RunWith(JUnitPlatform.class) @Tag("slow") @Tag(Constants.fedAuth) +@Tag(Constants.requireSecret) public class PooledConnectionTest extends FedauthCommon { static String charTable = TestUtils.escapeSingleQuotes( diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java index 8ed409945..3009d2213 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java @@ -47,6 +47,7 @@ private Constants() {} public static final String reqExternalSetup = "reqExternalSetup"; public static final String clientCertAuth = "clientCertAuth"; public static final String fedAuth = "fedAuth"; + public static final String requireSecret = "requireSecret"; public static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); public static final Logger LOGGER = Logger.getLogger("AbstractTest");