Enable Always Encrypted enclave connection parameters (#919)

* Enable the enclave connection parameters.

* Update the switch statement to use the enum constants for EnclaveAttestationProtocol

* Update verbiage for Always Encrypted connection options

* Update the argument exception to chose one specific to this connection option

* Add resource logic to resource files.

* Add error checking for when enclave parameters are added and Always Encrypted is set to disabled.

* Add/Update unit tests
This commit is contained in:
Jeff Trimmer
2020-02-18 15:33:12 -08:00
committed by GitHub
parent 7b102df5a7
commit 927b0d73ca
9 changed files with 1875 additions and 1667 deletions

View File

@@ -19,6 +19,7 @@ using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Moq;
using Moq.Protected;
using Xunit;
using System.Linq;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
{
@@ -552,12 +553,45 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.True(connectionString.Contains(connectionStringMarker));
}
/// <summary>
/// Verify that optional parameters which require ColumnEncryptionSetting to be enabled
/// can be built into a connection string for connecting.
/// </summary>
[Theory]
[InlineData("EnclaveAttestationProtocol", "AAS", "Attestation Protocol=AAS")]
[InlineData("EnclaveAttestationProtocol", "HGS", "Attestation Protocol=HGS")]
[InlineData("EnclaveAttestationProtocol", "aas", "Attestation Protocol=AAS")]
[InlineData("EnclaveAttestationProtocol", "hgs", "Attestation Protocol=HGS")]
[InlineData("EnclaveAttestationProtocol", "AaS", "Attestation Protocol=AAS")]
[InlineData("EnclaveAttestationProtocol", "hGs", "Attestation Protocol=HGS")]
[InlineData("EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave", "Enclave Attestation Url=https://attestation.us.attest.azure.net/attest/SgxEnclave")]
public void ConnectingWithOptionalEnclaveParametersBuildsConnectionString(string propertyName, object propertyValue, string connectionStringMarker)
{
// Create a test connection details object and set the property to a specific value
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
details.GetType()
.GetProperty("ColumnEncryptionSetting")
.SetValue(details, "Enabled");
details.GetType()
.GetProperty(propertyName)
.SetValue(details, propertyValue);
// Test that a connection string can be created without exceptions
string connectionString = ConnectionService.BuildConnectionString(details);
Assert.NotNull(connectionString);
Assert.NotEmpty(connectionString);
// Verify that the parameter is in the connection string
Assert.True(connectionString.Contains(connectionStringMarker));
}
/// <summary>
/// Build connection string with an invalid property type
/// </summary>
[Theory]
[InlineData("AuthenticationType", "NotAValidAuthType")]
[InlineData("ColumnEncryptionSetting", "NotAValidColumnEncryptionSetting")]
[InlineData("EnclaveAttestationProtocol", "NotAValidEnclaveAttestationProtocol")]
public void BuildConnectionStringWithInvalidOptions(string propertyName, object propertyValue)
{
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
@@ -566,6 +600,59 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.Throws<ArgumentException>(() => ConnectionService.BuildConnectionString(details));
}
/// <summary>
/// Parameters used for test: BuildConnectionStringWithInvalidOptionCombinations
/// </summary>
public static readonly object[][] ConnectionStringWithInvalidOptionCombinations =
{
new object[]
{
typeof(ArgumentException),
new []
{
Tuple.Create<string, object>("ColumnEncryptionSetting", null),
Tuple.Create<string, object>("EnclaveAttestationProtocol", "AAS"),
Tuple.Create<string, object>("EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave")
}
},
new object[]
{
typeof(ArgumentException),
new []
{
Tuple.Create<string, object>("ColumnEncryptionSetting", "Disabled"),
Tuple.Create<string, object>("EnclaveAttestationProtocol", "AAS"),
Tuple.Create<string, object>("EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave")
}
},
new object[]
{
typeof(ArgumentException),
new []
{
Tuple.Create<string, object>("ColumnEncryptionSetting", ""),
Tuple.Create<string, object>("EnclaveAttestationProtocol", "AAS"),
Tuple.Create<string, object>("EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave")
}
}
};
/// <summary>
/// Build connection string with an invalid property combinations
/// </summary>
[Theory]
[MemberData(nameof(ConnectionStringWithInvalidOptionCombinations))]
public void BuildConnectionStringWithInvalidOptionCombinations(Type exceptionType, Tuple<string, object>[] propertyNameValuePairs)
{
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
propertyNameValuePairs.ToList().ForEach(tuple =>
{
PropertyInfo info = details.GetType().GetProperty(tuple.Item1);
info.SetValue(details, tuple.Item2);
});
Assert.Throws(exceptionType, () => ConnectionService.BuildConnectionString(details));
}
/// <summary>
/// Verify that a connection changed event is fired when the database context changes.
/// </summary>