From faaec187a7e27584fa46de2b3ff30fecb9dfc005 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Thu, 27 Oct 2022 14:32:22 -0700 Subject: [PATCH] Support Boolean type for Encrypt option value (#1737) --- .../Connection/Contracts/ConnectionDetails.cs | 11 +++++++++-- .../Connection/ConnectionServiceTests.cs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs index 7694d16a..9a9ac0c9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs @@ -147,13 +147,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts } /// - /// Gets or sets a value that indicates encryption mode that SQL Server should use to perform SSL encryption for all the data sent between the client and server. Supported values are: Optional, Mandatory, Strict. + /// Gets or sets a value that indicates encryption mode that SQL Server should use to perform SSL encryption for all the data sent between the client and server. Supported values are: Optional, Mandatory, Strict, True, False, Yes and No. + /// Boolean 'true' and 'false' will also continue to be supported for backwards compatibility. /// public string Encrypt { get { - return GetOptionValue("encrypt"); + string value = GetOptionValue("encrypt"); + if(string.IsNullOrEmpty(value)) + { + // Accept boolean values for backwards compatibility. + value = GetOptionValue("encrypt").ToString(); + } + return value; } set diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs index d073c36c..ce8f4952 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs @@ -673,6 +673,24 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection Assert.That(connectionString, Contains.Substring("Encrypt=" + expected.ToString()), "Encrypt not as expected."); } + /// + /// Verify that Strict Encryption parameters can be built into a connection string for connecting. + /// + [Test] + [TestCase(true, "True")] + [TestCase(false, "False")] + public void ConnectingWithBoolEncryptBuildsConnectionString(bool encryptValue, string expected) + { + // Create a test connection details object and set the property to a specific value + ConnectionDetails details = TestObjects.GetTestConnectionDetails(); + details.Options["encrypt"] = encryptValue; + + // Test that a connection string can be created without exceptions + string connectionString = ConnectionService.BuildConnectionString(details); + + Assert.That(connectionString, Contains.Substring("Encrypt=" + expected), "Encrypt not as expected."); + } + /// /// Build connection string with an invalid property combinations ///