Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class AKVTest : IClassFixture<SQLSetupStrategyAzureKeyVault>
[Collection("AlwaysEncryptedAKV")]
public sealed class AKVTest : IDisposable
{
private readonly SQLSetupStrategyAzureKeyVault _fixture;
private readonly string _akvTableName;
Expand Down Expand Up @@ -191,6 +192,19 @@ public void TestLocalCekCacheIsScopedToProvider()
Assert.StartsWith("The current credential is not configured to acquire tokens for tenant", ex.InnerException.Message);
}

public void Dispose()
{
foreach (string connection in DataTestUtility.AEConnStringsSetup)
{
using (SqlConnection sqlConnection = new SqlConnection(connection))
{
sqlConnection.Open();

Table.DeleteData(_fixture.AKVTestTable.Name, sqlConnection);
}
}
}

private class EmptyKeyStoreProvider : SqlColumnEncryptionKeyStoreProvider
{
public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
/// <summary>
/// Always Encrypted public API Manual tests.
/// </summary>
public sealed class ApiShould : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
[Collection("AlwaysEncryptedCertStore")]
public sealed class ApiShould : IDisposable
{
private SQLSetupStrategy _fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
/// <summary>
/// Always Encrypted public API Manual tests.
/// </summary>
public sealed class BulkCopyAE : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
[Collection("AlwaysEncryptedCertStore")]
public sealed class BulkCopyAE : IDisposable
{
private SQLSetupStrategy fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
/// <summary>
/// Always Encrypted public API Manual tests.
/// </summary>
public class BulkCopyAEErrorMessage : IClassFixture<SQLSetupStrategyCertStoreProvider>
[Collection("AlwaysEncryptedCertStore")]
public class BulkCopyAEErrorMessage
{
private SQLSetupStrategy _fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public sealed class ColumnDecryptErrorTests : IClassFixture<SQLSetupStrategyAzureKeyVault>, IDisposable
[Collection("AlwaysEncryptedAKV")]
public sealed class ColumnDecryptErrorTests : IDisposable
{
private SQLSetupStrategyAzureKeyVault fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class CoreCryptoTests : IClassFixture<SQLSetupStrategyCertStoreProvider>
[Collection("AlwaysEncryptedCertStore")]
public class CoreCryptoTests
{
// Synapse: Always Encrypted not supported in Azure Synapse.
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public sealed class DateOnlyReadTests : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
[Collection("AlwaysEncryptedCertStore")]
public sealed class DateOnlyReadTests : IDisposable
{
private SQLSetupStrategy fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public sealed class End2EndSmokeTests : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
[Collection("AlwaysEncryptedCertStore")]
public sealed class End2EndSmokeTests : IDisposable
{
private SQLSetupStrategy fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class ExceptionTestAKVStore : IClassFixture<SQLSetupStrategyAzureKeyVault>
[Collection("AlwaysEncryptedAKV")]
public class ExceptionTestAKVStore
{
private const string MasterKeyEncAlgo = "RSA_OAEP";
private const string BadMasterKeyEncAlgo = "BadMasterKeyAlgorithm";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class SqlBulkCopyTruncation : IClassFixture<SQLSetupStrategyCertStoreProvider>
[Collection("AlwaysEncryptedCertStore")]
public class SqlBulkCopyTruncation
{
private SQLSetupStrategy _fixture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public sealed class SqlNullValuesTests : IClassFixture<SQLSetupStrategyCertStoreProvider>, IDisposable
[Collection("AlwaysEncryptedCertStore")]
public sealed class SqlNullValuesTests : IDisposable
{
private SQLSetupStrategy fixture;
private readonly string tableName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.TestFixtures
{
/// <summary>
/// This class has no code, and is never created. It serves only to
/// associate the AlwaysEncryptedAKV [CollectionDefinition] and its
/// ICollectionFixture<> interfaces.
///
/// Use this collection definition for tests that rely on the
/// SQLSetupStrategyAzureKeyVault fixture. Always clean data from
/// any tables used directly in the test, as the same fixture instance
/// and database tables are shared across test classes.
/// </summary>
[CollectionDefinition("AlwaysEncryptedAKV")]
public class AlwaysEncryptedAKVCollection : ICollectionFixture<SQLSetupStrategyAzureKeyVault>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.TestFixtures
{
/// <summary>
/// This class has no code, and is never created. It serves only to
/// associate the AlwaysEncryptedCertStore [CollectionDefinition] and its
/// ICollectionFixture<> interfaces.
///
/// Use this collection definition for tests that rely on the
/// SQLSetupStrategyCertStoreProvider fixture. Always clean data from
/// any tables used directly in the test, as the same fixture instance
/// and database tables are shared across test classes.
/// </summary>
[CollectionDefinition("AlwaysEncryptedCertStore")]
public class AlwaysEncryptedCertStoreCollection :ICollectionFixture<SQLSetupStrategyCertStoreProvider>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public static string GetConnectionString(bool fTceEnabled, SqlConnectionStringBu
builder.EnclaveAttestationUrl = sb.EnclaveAttestationUrl;
builder.AttestationProtocol = sb.AttestationProtocol;
}
builder.ConnectTimeout = 10000;
return builder.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class TestTrustedMasterKeyPaths : IClassFixture<SQLSetupStrategyCertStoreProvider>
[Collection("AlwaysEncryptedCertStore")]
public class TestTrustedMasterKeyPaths
{
private readonly string dummyThumbprint;
private readonly string tableName;
Expand Down Expand Up @@ -48,17 +49,18 @@ private void ValidateResultSet(SqlDataReader sqlDataReader)
[ClassData(typeof(AEConnectionStringProvider))]
public void TestTrustedColumnEncryptionMasterKeyPathsWithNullDictionary(string connection)
{
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection);
connBuilder.ConnectTimeout = 10000;
string connStringNow = connBuilder.ToString();
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection)
{
ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled
};

// 1. Default should succeed.
if (SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Count != 0)
{
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Clear();
}

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down Expand Up @@ -86,9 +88,10 @@ FROM [{tableName}]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestTrustedColumnEncryptionMasterKeyPathsWithOneServer(string connection)
{
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection);
connBuilder.ConnectTimeout = 10000;
string connStringNow = connBuilder.ToString();
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection)
{
ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled
};

// 2.. Test with valid key path
//
Expand All @@ -103,7 +106,7 @@ public void TestTrustedColumnEncryptionMasterKeyPathsWithOneServer(string connec
trustedKeyPaths.Add(columnMasterKeyPath);
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Add(connBuilder.DataSource, trustedKeyPaths);

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down Expand Up @@ -131,9 +134,10 @@ FROM [{tableName}]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestTrustedColumnEncryptionMasterKeyPathsWithMultipleServers(string connection)
{
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection);
connBuilder.ConnectTimeout = 10000;
string connStringNow = connBuilder.ToString();
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection)
{
ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled
};

// 3. Test with multiple servers with multiple key paths
//
Expand Down Expand Up @@ -161,7 +165,7 @@ public void TestTrustedColumnEncryptionMasterKeyPathsWithMultipleServers(string
server2TrustedKeyPaths.Add(@"https://balneetestkeyvault.vault.azure.net/keys/CryptoTest4/f4eb1dbbe6a9446599efe3c952614e70");
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Add(@"randomeserver", server2TrustedKeyPaths);

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down Expand Up @@ -189,9 +193,10 @@ FROM [{tableName}]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestTrustedColumnEncryptionMasterKeyPathsWithInvalidInputs(string connection)
{
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection);
connBuilder.ConnectTimeout = 10000;
string connStringNow = connBuilder.ToString();
SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connection)
{
ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled
};

// 1. Test with null List
//
Expand All @@ -207,7 +212,7 @@ public void TestTrustedColumnEncryptionMasterKeyPathsWithInvalidInputs(string co
// Prepare a dictionary with null list.
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Add(connBuilder.DataSource, (List<string>)null);

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down Expand Up @@ -239,7 +244,7 @@ FROM [{tableName}]
List<string> emptyKeyPathList = new List<string>();
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Add(connBuilder.DataSource, emptyKeyPathList);

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down Expand Up @@ -273,7 +278,7 @@ FROM [{tableName}]
invalidKeyPathList.Add(invalidKeyPath);
SqlConnection.ColumnEncryptionTrustedMasterKeyPaths.Add(connBuilder.DataSource, invalidKeyPathList);

using (SqlConnection sqlConnection = new SqlConnection(string.Concat(connStringNow, @";Column Encryption Setting = Enabled;")))
using (SqlConnection sqlConnection = new SqlConnection(connBuilder.ConnectionString))
{
sqlConnection.Open();

Expand Down
Loading
Loading