diff --git a/BUILDGUIDE.md b/BUILDGUIDE.md index cdd98d85a5..9d17a6f5f5 100644 --- a/BUILDGUIDE.md +++ b/BUILDGUIDE.md @@ -123,6 +123,7 @@ Manual Tests require the below setup to run: |FileStreamDirectory | (Optional) If File Stream is enabled on SQL Server, pass local directory path to be used for setting up File Stream enabled database. | `D:\\escaped\\absolute\\path\\to\\directory\\` | |UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`| |IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`| + |MakecertPath | The full path to makecert.exe. This is not required if the path is present in the PATH environment variable. | `D:\\escaped\\absolute\\path\\to\\makecert.exe` | ### Commands to run Manual Tests: diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs index 91a0b6e7fb..66d3c3588d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs @@ -31,7 +31,8 @@ internal static void CreateCertificate(string certificateName, string certificat Assert.False(string.IsNullOrWhiteSpace(certificateName), "FAILED: certificateName should not be null or empty."); Assert.False(string.IsNullOrWhiteSpace(certificateLocation), "FAILED: certificateLocation should not be null or empty."); - ProcessStartInfo processStartInfo = new ProcessStartInfo(@"makecert"); + string makecertPath = string.IsNullOrEmpty(DataTestUtility.MakecertPath) ? "makecert" : DataTestUtility.MakecertPath; + ProcessStartInfo processStartInfo = new ProcessStartInfo(makecertPath); processStartInfo.Arguments = string.Format(@"-n ""CN={0}"" -pe -sr {1} -r -eku 1.3.6.1.5.5.8.2.2,1.3.6.1.4.1.311.10.3.11 -ss my -sky exchange -sp ""{2}"" -sy {3} -len 2048 -a sha256", certificateName, certificateLocation, diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index c3aa7b0486..e6ff0a3bf6 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -48,6 +48,7 @@ public static class DataTestUtility public static readonly bool UseManagedSNIOnWindows = false; public static readonly bool IsAzureSynapse = false; public static Uri AKVBaseUri = null; + public static readonly string MakecertPath = null; public static string FileStreamDirectory = null; public static readonly string DNSCachingConnString = null; @@ -99,6 +100,7 @@ static DataTestUtility() IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR; EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString; UserManagedIdentityClientId = c.UserManagedIdentityClientId; + MakecertPath = c.MakecertPath; System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs index ae52a6efab..104a657133 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs @@ -54,10 +54,10 @@ public class AdapterTest public AdapterTest() { // create random name for temp tables - _randomGuid = Guid.NewGuid().ToString(); - _tempTable = Environment.MachineName + "_" + _randomGuid; + _tempTable = DataTestUtility.GetUniqueName("AdapterTest"); _tempTable = _tempTable.Replace('-', '_'); + _randomGuid = Guid.NewGuid().ToString(); _tempKey = "employee_id_key_" + Environment.TickCount.ToString() + _randomGuid; _tempKey = _tempKey.Replace('-', '_'); @@ -179,15 +179,15 @@ public void PrepUnprepTest() public void SqlVariantTest() { string tableName = DataTestUtility.GenerateObjectName(); - try + // good test for null values and unicode strings + using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) + using (SqlCommand cmd = new SqlCommand(null, conn)) + using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) { - ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)"); - - // good test for null values and unicode strings - using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) - using (SqlCommand cmd = new SqlCommand(null, conn)) - using (SqlDataAdapter sqlAdapter = new SqlDataAdapter()) + try { + ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)"); + cmd.Connection.Open(); // the ORDER BY clause tests that we correctly ignore the ORDER token @@ -263,10 +263,10 @@ public void SqlVariantTest() } } } - } - finally - { - ExecuteNonQueryCommand("DROP TABLE " + tableName); + finally + { + DataTestUtility.DropTable(conn, tableName); + } } } @@ -659,7 +659,7 @@ public void UpdateTest() } finally { - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); + DataTestUtility.DropTable(conn, _tempTable); } } } @@ -757,7 +757,7 @@ public void BulkUpdateTest() } finally { - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); + DataTestUtility.DropTable(conn, _tempTable); } } } @@ -768,25 +768,27 @@ public void BulkUpdateTest() [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] public void UpdateRefreshTest() { + string identTableName = DataTestUtility.GetUniqueName("ID_"); string createIdentTable = - "CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," + + $"CREATE TABLE {identTableName} (id int IDENTITY," + "LastName nvarchar(50) NULL," + "Firstname nvarchar(50) NULL)"; + string spName = DataTestUtility.GetUniqueName("sp_insert", withBracket: false); string spCreateInsert = - "CREATE PROCEDURE sp_insert" + _tempTable + + $"CREATE PROCEDURE {spName}" + "(@FirstName nvarchar(50), @LastName nvarchar(50), @id int OUTPUT) " + "AS INSERT INTO " + _tempTable + " (FirstName, LastName) " + "VALUES (@FirstName, @LastName); " + "SELECT @id=@@IDENTITY"; - string spDropInsert = "DROP PROCEDURE sp_insert" + _tempTable; + string spDropInsert = $"DROP PROCEDURE {spName}"; bool dropSP = false; using (SqlDataAdapter adapter = new SqlDataAdapter()) using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) using (SqlCommand cmd = new SqlCommand(null, conn)) - using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + " from ID_" + _tempTable, conn)) + using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + $" from {identTableName}", conn)) using (SqlCommand tableClean = new SqlCommand("", conn)) { ExecuteNonQueryCommand(createIdentTable); @@ -794,7 +796,7 @@ public void UpdateRefreshTest() { adapter.InsertCommand = new SqlCommand() { - CommandText = "sp_insert" + _tempTable, + CommandText = spName, CommandType = CommandType.StoredProcedure }; adapter.InsertCommand.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.NVarChar, 50, "FirstName")); @@ -851,9 +853,9 @@ public void UpdateRefreshTest() { if (dropSP) { - ExecuteNonQueryCommand(spDropInsert); - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); - ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable); + DataTestUtility.DropStoredProcedure(conn, spName); + DataTestUtility.DropTable(conn, _tempTable); + DataTestUtility.DropTable(conn, identTableName); } } } @@ -873,18 +875,18 @@ public void UpdateNullTest() "VALUES (@val_cvarbin, @val_cimage)"; bool dropSP = false; - try - { - ExecuteNonQueryCommand(createTable); - ExecuteNonQueryCommand(createSP); - dropSP = true; - using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) - using (SqlCommand cmdInsert = new SqlCommand(procName, conn)) - using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn)) - using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn)) - using (SqlDataAdapter adapter = new SqlDataAdapter()) + using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) + using (SqlCommand cmdInsert = new SqlCommand(procName, conn)) + using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn)) + using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn)) + using (SqlDataAdapter adapter = new SqlDataAdapter()) + { + try { + ExecuteNonQueryCommand(createTable); + ExecuteNonQueryCommand(createSP); + dropSP = true; conn.Open(); cmdInsert.CommandType = CommandType.StoredProcedure; @@ -905,13 +907,13 @@ public void UpdateNullTest() DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][0], "Unexpected value."); DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][1], "Unexpected value."); } - } - finally - { - if (dropSP) + finally { - ExecuteNonQueryCommand("DROP PROCEDURE " + procName); - ExecuteNonQueryCommand("DROP TABLE " + tableName); + if (dropSP) + { + DataTestUtility.DropStoredProcedure(conn, procName); + DataTestUtility.DropTable(conn, tableName); + } } } } @@ -930,18 +932,18 @@ public void UpdateOffsetTest() "VALUES (@val_cvarbin, @val_cimage)"; bool dropSP = false; - try - { - ExecuteNonQueryCommand(createTable); - ExecuteNonQueryCommand(createSP); - dropSP = true; - using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) - using (SqlCommand cmdInsert = new SqlCommand(procName, conn)) - using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn)) - using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn)) - using (SqlDataAdapter adapter = new SqlDataAdapter()) + using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) + using (SqlCommand cmdInsert = new SqlCommand(procName, conn)) + using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn)) + using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn)) + using (SqlDataAdapter adapter = new SqlDataAdapter()) + { + try { + ExecuteNonQueryCommand(createTable); + ExecuteNonQueryCommand(createSP); + dropSP = true; conn.Open(); cmdInsert.CommandType = CommandType.StoredProcedure; @@ -978,13 +980,13 @@ public void UpdateOffsetTest() val = (byte[])(ds.Tables[0].Rows[0][1]); Assert.True(ByteArraysEqual(expectedBytes2, val), "FAILED: Test 2: Unequal byte arrays."); } - } - finally - { - if (dropSP) + finally { - ExecuteNonQueryCommand("DROP PROCEDURE " + procName); - ExecuteNonQueryCommand("DROP TABLE " + tableName); + if (dropSP) + { + DataTestUtility.DropStoredProcedure(conn, procName); + DataTestUtility.DropTable(conn, tableName); + } } } } @@ -1069,7 +1071,7 @@ public void AutoGenUpdateTest() } finally { - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); + DataTestUtility.DropTable(conn, _tempTable); } } } @@ -1078,16 +1080,17 @@ public void AutoGenUpdateTest() [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] public void AutoGenErrorTest() { + string identTableName = DataTestUtility.GetUniqueName("ID_"); string createIdentTable = - "CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," + + $"CREATE TABLE {identTableName} (id int IDENTITY," + "LastName nvarchar(50) NULL," + "Firstname nvarchar(50) NULL)"; - try + using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) + using (SqlCommand cmd = new SqlCommand($"SELECT * into {_tempTable} from {identTableName}", conn)) + using (SqlDataAdapter adapter = new SqlDataAdapter()) { - using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) - using (SqlCommand cmd = new SqlCommand("SELECT * into " + _tempTable + " from ID_" + _tempTable, conn)) - using (SqlDataAdapter adapter = new SqlDataAdapter()) + try { ExecuteNonQueryCommand(createIdentTable); @@ -1110,11 +1113,11 @@ public void AutoGenErrorTest() SqlCommandBuilder builder = new SqlCommandBuilder(adapter); adapter.Update(ds, _tempTable); } - } - finally - { - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); - ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable); + finally + { + DataTestUtility.DropTable(conn, _tempTable); + DataTestUtility.DropTable(conn, identTableName); + } } } @@ -1206,7 +1209,7 @@ public void AutoGenBulkUpdateTest() } finally { - ExecuteNonQueryCommand("DROP TABLE " + _tempTable); + DataTestUtility.DropTable(conn, _tempTable); } } } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs index d3413622b2..5b2c31b22b 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs @@ -38,6 +38,7 @@ public class Config public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring public string EnclaveAzureDatabaseConnString = null; public string UserManagedIdentityClientId = null; + public string MakecertPath = null; public static Config Load(string configPath = @"config.json") { diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json index 69bacdc3f9..043b73c4c9 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json @@ -26,5 +26,6 @@ "IsDNSCachingSupportedTR": false, "IsAzureSynapse": false, "EnclaveAzureDatabaseConnString": "", - "UserManagedIdentityClientId": "" + "UserManagedIdentityClientId": "", + "MakecertPath": "" }