Skip to content
Merged
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
4 changes: 2 additions & 2 deletions BUILDGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Tests can be built and run with custom Target Frameworks. See the below examples
```bash
> msbuild /t:BuildTestsNetCore /p:TargetNetCoreVersion=netcoreapp3.1
# Build the tests for custom TargetFramework (.NET Core)
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | netcoreapp5.0
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | net5.0
```

### Running Tests:
Expand All @@ -221,7 +221,7 @@ Tests can be built and run with custom Target Frameworks. See the below examples

> dotnet test /p:TargetNetCoreVersion=netcoreapp3.1 ...
# Use above property to run Functional Tests with custom TargetFramework (.NET Core)
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | netcoreapp5.0
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | net5.0
```

## Using Managed SNI on Windows
Expand Down
48 changes: 24 additions & 24 deletions RunTests.cmd

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void CertificateNotFound()
Assert.Matches(expectedMessage, e.Message);
}

#if NET46
#if NETFX
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp)]
public void CertificateWithNoPrivateKey()
Expand All @@ -68,7 +68,7 @@ public class ExceptionCertFixture : IDisposable
public static string thumbprint;
public static byte[] cek;
public static byte[] encryptedCek;
#if NET46
#if NETFX
public static X509Certificate2 masterKeyCertificateNPK; // no private key
public static string thumbprintNPK; // No private key
public static string masterKeyPathNPK;
Expand All @@ -84,7 +84,7 @@ public ExceptionCertFixture()
certificatePath = string.Format("CurrentUser/My/{0}", thumbprint);
cek = Utility.GenerateRandomBytes(32);
encryptedCek = certStoreProvider.EncryptColumnEncryptionKey(certificatePath, "RSA_OAEP", cek);
#if NET46
#if NETFX
if(masterKeyCertificateNPK == null)
{
masterKeyCertificateNPK = Utility.CreateCertificateWithNoPrivateKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void Dispose()

public static void AddKeyToCsp(string containerName)
{

CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = containerName;
RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider(KEY_SIZE, cspParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>FunctionalTests</AssemblyName>
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
<TargetGroup Condition="$(TargetFramework.StartsWith('net4'))">netfx</TargetGroup>
<TargetGroup Condition="$(TargetGroup) == ''">netcoreapp</TargetGroup>
<Configurations>Debug;Release;net461-Release;net461-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release</Configurations>
<Platforms>AnyCPU;x86;x64</Platforms>
<DefineConstants Condition="'$(TargetGroup)'=='netfx'">$(DefineConstants);NETFX</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);NETCOREAPP</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp' AND !$(TargetFramework.StartsWith('netcoreapp'))">$(DefineConstants);NET50_OR_LATER</DefineConstants>
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform).$(AssemblyName)</IntermediateOutputPath>
<OutputPath>$(BinFolder)$(Configuration).$(Platform).$(AssemblyName)</OutputPath>
</PropertyGroup>
<ItemGroup Condition="!$(ReferenceType.Contains('NetStandard'))">
<Compile Include="SqlConnectionStringBuilderPoolBlockingTest.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="AlwaysEncryptedTests\ExceptionsAlgorithmErrors.cs" />
<Compile Include="AlwaysEncryptedTests\ExceptionsCertStore.cs" />
<ItemGroup Condition="'OsGroup'=='Windows'">
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCertificateStoreProviderShould.cs" />
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCngProviderShould.cs" />
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCspProviderShould.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="AlwaysEncryptedTests\ExceptionsAlgorithmErrors.cs" />
<Compile Include="AlwaysEncryptedTests\ExceptionsCertStore.cs" />
<Compile Include="AlwaysEncryptedTests\ConnectionStringBuilderShould.cs" />
<Compile Include="AlwaysEncryptedTests\DummyKeyStoreProvider.cs" />
<Compile Include="AlwaysEncryptedTests\ExceptionRegisterKeyStoreProvider.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Constructor1()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -46,7 +46,7 @@ public void Constructor2()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -64,7 +64,7 @@ public void Constructor2()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -89,7 +89,7 @@ public void Constructor3()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -107,7 +107,7 @@ public void Constructor3()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -125,7 +125,7 @@ public void Constructor3()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand Down Expand Up @@ -166,7 +166,7 @@ public void Constructor4()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -184,7 +184,7 @@ public void Constructor4()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -202,7 +202,7 @@ public void Constructor4()
Assert.Null(cmd.Container);
Assert.True(cmd.DesignTimeVisible);
Assert.Null(cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -224,7 +224,7 @@ public void Clone()
cmd.CommandType = CommandType.StoredProcedure;
cmd.DesignTimeVisible = false;
cmd.Notification = notificationReq;
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand All @@ -240,7 +240,7 @@ public void Clone()
Assert.Null(cmd.Connection);
Assert.False(cmd.DesignTimeVisible);
Assert.Same(notificationReq, cmd.Notification);
#if NET461
#if NETFX
// see https://github.com/dotnet/SqlClient/issues/17
Assert.True(cmd.NotificationAutoEnlist);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void SerializationTest()
Assert.Equal(e.StackTrace, sqlEx.StackTrace);
}

#if !NET50_OR_LATER
[Fact]
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
public static void SqlExcpetionSerializationTest()
Expand All @@ -53,6 +54,7 @@ public static void SqlExcpetionSerializationTest()
}
}
}
#endif

[Fact]
public void JSONSerializationTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ConversionTests()
certStoreProvider);
databaseObjects.Add(columnEncryptionKey);

foreach(string connectionStr in DataTestUtility.AEConnStringsSetup)
foreach (string connectionStr in DataTestUtility.AEConnStringsSetup)
{
using (SqlConnection sqlConnection = new SqlConnection(connectionStr))
{
Expand Down Expand Up @@ -1346,7 +1346,7 @@ private void SetParamSizeScalePrecision(ref SqlParameter param, ColumnMetaData c
public void Dispose()
{
databaseObjects.Reverse();
foreach(string connectionStr in DataTestUtility.AEConnStringsSetup)
foreach (string connectionStr in DataTestUtility.AEConnStringsSetup)
{
using (SqlConnection sqlConnection = new SqlConnection(connectionStr))
{
Expand Down Expand Up @@ -1429,14 +1429,14 @@ public IEnumerator<object[]> GetEnumerator()
yield return new object[] { connStrAE, SqlDbType.DateTime2, SqlDbType.DateTime2 };
yield return new object[] { connStrAE, SqlDbType.DateTimeOffset, SqlDbType.DateTimeOffset };
yield return new object[] { connStrAE, SqlDbType.Float, SqlDbType.Float };
yield return new object[] { connStrAE, SqlDbType.Real, SqlDbType.Real};
yield return new object[] { connStrAE, SqlDbType.Real, SqlDbType.Real };
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}


public class TestOutOfRangeValuesData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
using System.Security.Cryptography.X509Certificates;
using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup;
using Xunit;
#if NET50_OR_LATER
using System.Runtime.Versioning;
#endif

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
/// <summary>
/// Always Encrypted public CspProvider Manual tests.
/// TODO: These tests are marked as Windows only for now but should be run for all platforms once the Master Key is accessible to this app from Azure Key Vault.
/// </summary>
#if NET50_OR_LATER
[SupportedOSPlatform("windows")]
#endif
[PlatformSpecific(TestPlatforms.Windows)]
public class CspProviderExt
{
Expand Down Expand Up @@ -81,9 +87,10 @@ public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders(string co
DatabaseHelper.InsertCustomerData(sqlConn, tableName, customer);

// Test INPUT parameter on an encrypted parameter
using (SqlCommand sqlCommand = new SqlCommand(string.Format(@"SELECT CustomerId, FirstName, LastName FROM [{0}] WHERE FirstName = @firstName", tableName),
using (SqlCommand sqlCommand = new SqlCommand(@"SELECT CustomerId, FirstName, LastName FROM [@tableName] WHERE FirstName = @firstName",
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled))
{
sqlCommand.Parameters.AddWithValue(@"tableName", tableName);
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
customerFirstParam.Direction = System.Data.ParameterDirection.Input;

Expand Down Expand Up @@ -173,9 +180,10 @@ public void TestEncryptDecryptWithCSP(string connectionString)
DatabaseHelper.InsertCustomerData(sqlConn, tableName, customer);

// Test INPUT parameter on an encrypted parameter
using (SqlCommand sqlCommand = new SqlCommand(string.Format(@"SELECT CustomerId, FirstName, LastName FROM [{0}] WHERE FirstName = @firstName", tableName),
using (SqlCommand sqlCommand = new SqlCommand(@"SELECT CustomerId, FirstName, LastName FROM [@tableName] WHERE FirstName = @firstName",
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled))
{
sqlCommand.Parameters.AddWithValue(@"tableName", tableName);
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
customerFirstParam.Direction = System.Data.ParameterDirection.Input;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,22 @@ public PlatformSpecificTestContext()
{
certStoreFixture = new SQLSetupStrategyCertStoreProvider();
}
#if !NET46
else
{
akvFixture = new SQLSetupStrategyAzureKeyVault();
}
#endif
}

public void Dispose()
{
Fixture.Dispose();
try
{
akvFixture?.Dispose();
}
finally
{
certStoreFixture?.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
#if !NET46
using Azure;
using Azure.Identity;
using Azure.Security.KeyVault.Keys;
#endif
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
class CertificateUtility
Expand Down Expand Up @@ -133,10 +131,6 @@ internal static X509Certificate2 CreateCertificate()
}
}

#if NET46
return certificate;
}
#else
if (DataTestUtility.IsAKVSetupAvailable())
{
SetupAKVKeysAsync().Wait();
Expand Down Expand Up @@ -179,7 +173,6 @@ private static async Task SetupAKVKeysAsync()
keyClient.CreateRsaKey(rsaKeyOptions);
}
}
#endif

/// <summary>
/// Removes a certificate from the local certificate store (useful for test cleanup).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Xunit;
#if NET50_OR_LATER
using System.Runtime.Versioning;
#endif

namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
#if NET50_OR_LATER
[SupportedOSPlatform("windows")]
#endif
[PlatformSpecific(TestPlatforms.Windows)]
class CertificateUtilityWin
{
Expand Down Expand Up @@ -165,7 +171,6 @@ internal static X509Certificate2 GetCertificate(string certificateName, StoreLoc
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindBySubjectName, certificateName, validOnly: false);
Debug.Assert(certCollection != null && certCollection.Count > 0);

return certCollection[0];
}
finally
Expand Down
Loading