Skip to content

Commit 7dfa969

Browse files
committed
- Added back some blocks that were removed by cherry-picks.
- Added console diagnostics to see when Enclave tables are dropped.
1 parent cca23e5 commit 7dfa969

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,55 @@ public void TestRoundTripWithCSPAndCertStoreProvider()
157157
}
158158
}
159159

160+
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
161+
[ClassData(typeof(AEConnectionStringProvider))]
162+
public void TestEncryptDecryptWithCSP(string connectionString)
163+
{
164+
string providerName = @"Microsoft Enhanced RSA and AES Cryptographic Provider";
165+
string keyIdentifier = DataTestUtility.GetUniqueNameForSqlServer("CSP");
166+
167+
try
168+
{
169+
CertificateUtilityWin.RSAPersistKeyInCsp(providerName, keyIdentifier);
170+
string cspPath = String.Concat(providerName, @"/", keyIdentifier);
171+
172+
SQLSetupStrategyCspExt sqlSetupStrategyCsp = new SQLSetupStrategyCspExt(cspPath);
173+
string tableName = sqlSetupStrategyCsp.CspProviderTable.Name;
174+
175+
try
176+
{
177+
using SqlConnection sqlConn = new(connectionString);
178+
sqlConn.Open();
179+
180+
Table.DeleteData(tableName, sqlConn);
181+
182+
// insert 1 row data
183+
Customer customer = new Customer(45, "Microsoft", "Corporation");
184+
185+
DatabaseHelper.InsertCustomerData(sqlConn, null, tableName, customer);
186+
187+
// Test INPUT parameter on an encrypted parameter
188+
using SqlCommand sqlCommand = new(@$"SELECT CustomerId, FirstName, LastName FROM [{tableName}] WHERE FirstName = @firstName",
189+
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled);
190+
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
191+
Console.WriteLine(@"Exception: {0}");
192+
customerFirstParam.Direction = System.Data.ParameterDirection.Input;
193+
194+
using SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
195+
ValidateResultSet(sqlDataReader);
196+
}
197+
finally
198+
{
199+
// clean up database resources
200+
sqlSetupStrategyCsp.Dispose();
201+
}
202+
}
203+
finally
204+
{
205+
CertificateUtilityWin.RSADeleteKeyInCsp(providerName, keyIdentifier);
206+
}
207+
}
208+
160209
/// <summary>
161210
/// Validates that the results are the ones expected.
162211
/// </summary>

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/Table.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public override void Drop(SqlConnection sqlConnection)
1919
command.CommandText = sql;
2020
command.ExecuteNonQuery();
2121
}
22+
23+
// TODO: Remove.
24+
System.Console.WriteLine($"Dropped table {Name} from {sqlConnection.ConnectionString}");
2225
}
2326

2427
public static void DeleteData(string tableName, SqlConnection sqlConnection)

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ private static bool CanCreateAliases()
398398
return false;
399399
}
400400

401+
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
402+
{
403+
WindowsPrincipal principal = new(identity);
404+
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
405+
{
406+
return false;
407+
}
408+
}
409+
401410
using RegistryKey key = Registry.LocalMachine.OpenSubKey(ConnectToPath, true);
402411
if (key == null)
403412
{

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Data;
99
using System.Data.SqlTypes;
1010
using System.Threading;
11-
using Microsoft.Data.SqlClient.Server;
1211
using Xunit;
1312

1413
namespace Microsoft.Data.SqlClient.ManualTesting.Tests

0 commit comments

Comments
 (0)