Update Microsoft.Data.SqlClient to v5.0.1 (#1708)

This commit is contained in:
Cheena Malhotra
2022-10-24 20:10:04 -07:00
committed by GitHub
parent 3be806ddce
commit c0f8482e26
30 changed files with 416 additions and 313 deletions

View File

@@ -25,6 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
var expectedForStrings = default(string);
var expectedForInt = default(int?);
var expectedForBoolean = default(bool?);
var expectedEncryptOption = default(string?);
Assert.AreEqual(details.ApplicationIntent, expectedForStrings);
Assert.AreEqual(details.ApplicationName, expectedForStrings);
@@ -48,13 +49,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.AreEqual(details.ColumnEncryptionSetting, expectedForStrings);
Assert.AreEqual(details.EnclaveAttestationUrl, expectedForStrings);
Assert.AreEqual(details.EnclaveAttestationProtocol, expectedForStrings);
Assert.AreEqual(details.Encrypt, expectedForBoolean);
Assert.AreEqual(details.Encrypt, expectedEncryptOption);
Assert.AreEqual(details.MultipleActiveResultSets, expectedForBoolean);
Assert.AreEqual(details.MultiSubnetFailover, expectedForBoolean);
Assert.AreEqual(details.PersistSecurityInfo, expectedForBoolean);
Assert.AreEqual(details.Pooling, expectedForBoolean);
Assert.AreEqual(details.Replication, expectedForBoolean);
Assert.AreEqual(details.TrustServerCertificate, expectedForBoolean);
Assert.AreEqual(details.HostNameInCertificate, expectedForStrings);
Assert.AreEqual(details.Port, expectedForInt);
}
@@ -88,13 +90,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
details.ColumnEncryptionSetting = expectedForStrings + index++;
details.EnclaveAttestationProtocol = expectedForStrings + index++;
details.EnclaveAttestationUrl = expectedForStrings + index++;
details.Encrypt = (index++ % 2 == 0);
details.Encrypt = expectedForStrings + index++;
details.MultipleActiveResultSets = (index++ % 2 == 0);
details.MultiSubnetFailover = (index++ % 2 == 0);
details.PersistSecurityInfo = (index++ % 2 == 0);
details.Pooling = (index++ % 2 == 0);
details.Replication = (index++ % 2 == 0);
details.TrustServerCertificate = (index++ % 2 == 0);
details.HostNameInCertificate = expectedForStrings + index++;
details.Port = expectedForInt + index++;
index = 0;
@@ -120,13 +123,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.AreEqual(details.ColumnEncryptionSetting, expectedForStrings + index++);
Assert.AreEqual(details.EnclaveAttestationProtocol, expectedForStrings + index++);
Assert.AreEqual(details.EnclaveAttestationUrl, expectedForStrings + index++);
Assert.AreEqual(details.Encrypt, (index++ % 2 == 0));
Assert.AreEqual(details.Encrypt, expectedForStrings + index++);
Assert.AreEqual(details.MultipleActiveResultSets, (index++ % 2 == 0));
Assert.AreEqual(details.MultiSubnetFailover, (index++ % 2 == 0));
Assert.AreEqual(details.PersistSecurityInfo, (index++ % 2 == 0));
Assert.AreEqual(details.Pooling, (index++ % 2 == 0));
Assert.AreEqual(details.Replication, (index++ % 2 == 0));
Assert.AreEqual(details.TrustServerCertificate, (index++ % 2 == 0));
Assert.AreEqual(details.HostNameInCertificate, expectedForStrings + index++);
Assert.AreEqual(details.Port, (expectedForInt + index++));
}
@@ -161,16 +165,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
details.ColumnEncryptionSetting = expectedForStrings + index++;
details.EnclaveAttestationProtocol = expectedForStrings + index++;
details.EnclaveAttestationUrl = expectedForStrings + index++;
details.Encrypt = (index++ % 2 == 0);
details.Encrypt = expectedForStrings + index++;
details.MultipleActiveResultSets = (index++ % 2 == 0);
details.MultiSubnetFailover = (index++ % 2 == 0);
details.PersistSecurityInfo = (index++ % 2 == 0);
details.Pooling = (index++ % 2 == 0);
details.Replication = (index++ % 2 == 0);
details.TrustServerCertificate = (index++ % 2 == 0);
details.HostNameInCertificate = expectedForStrings + index++;
details.Port = expectedForInt + index++;
if(optionMetadata.Options.Count() != details.Options.Count)
if (optionMetadata.Options.Count() != details.Options.Count)
{
var optionsNotInMetadata = details.Options.Where(o => !optionMetadata.Options.Any(m => m.Name == o.Key));
var optionNames = optionsNotInMetadata.Any() ? optionsNotInMetadata.Select(s => s.Key).Aggregate((i, j) => i + "," + j) : null;
@@ -180,7 +185,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
{
var metadata = optionMetadata.Options.FirstOrDefault(x => x.Name == option.Key);
Assert.NotNull(metadata);
if(metadata.ValueType == ConnectionOption.ValueTypeString)
if (metadata.ValueType == ConnectionOption.ValueTypeString)
{
Assert.True(option.Value is string);
}
@@ -200,7 +205,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
public void SettingConnectiomTimeoutToLongShouldStillReturnInt()
{
ConnectionDetails details = new ConnectionDetails();
long timeout = 30;
int? expectedValue = 30;
details.Options["connectTimeout"] = timeout;
@@ -226,44 +231,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public void SettingEncryptToStringShouldStillReturnBoolean()
public void SettingEncrypShouldReturnExpectedEncryptOption()
{
ConnectionDetails details = new ConnectionDetails();
details.Options["Encrypt"] = true.ToString();
Assert.That(details.Encrypt, Is.EqualTo(true.ToString()), "Encrypt should be Mandatory.");
string encrypt = "True";
bool? expectedValue = true;
details.Options["encrypt"] = encrypt;
Assert.AreEqual(details.Encrypt, expectedValue);
details.Options["Encrypt"] = "Strict";
Assert.That(details.Encrypt, Is.EqualTo("Strict"), "Encrypt should be Strict.");
}
[Test]
public void SettingEncryptToLowecaseStringShouldStillReturnBoolean()
public void EncryptShouldReturnMandatoryIfNotSet()
{
ConnectionDetails details = new ConnectionDetails();
string encrypt = "true";
bool? expectedValue = true;
details.Options["encrypt"] = encrypt;
Assert.AreEqual(details.Encrypt, expectedValue);
}
[Test]
public void EncryptShouldReturnNullIfNotSet()
{
ConnectionDetails details = new ConnectionDetails();
bool? expectedValue = null;
Assert.AreEqual(details.Encrypt, expectedValue);
}
[Test]
public void EncryptShouldReturnNullIfSetToNull()
{
ConnectionDetails details = new ConnectionDetails();
details.Options["encrypt"] = null;
int? expectedValue = null;
Assert.AreEqual(details.ConnectTimeout, expectedValue);
Assert.That(details.Encrypt, Is.Null, "Encrypt should be null when set to null");
}
[Test]
@@ -273,11 +255,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
long timeout = long.MaxValue;
int? expectedValue = null;
string? expectedEncryptValue = "Mandatory";
details.Options["connectTimeout"] = timeout;
details.Options["encrypt"] = true;
details.Options["encrypt"] = expectedEncryptValue;
Assert.AreEqual(details.ConnectTimeout, expectedValue);
Assert.AreEqual(true, details.Encrypt);
Assert.That(details.ConnectTimeout, Is.EqualTo(expectedValue), "Connect Timeout not as expected");
Assert.That(details.Encrypt, Is.EqualTo("Mandatory"), "Encrypt should be mandatory.");
}
}
}

View File

@@ -273,7 +273,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// provided as a parameter.
/// </summary>
[Test]
public async Task CanConnectWithEmptyDatabaseName([Values(null, "")]string databaseName)
public async Task CanConnectWithEmptyDatabaseName([Values(null, "")] string databaseName)
{
// Connect
var connectionDetails = TestObjects.GetTestConnectionDetails();
@@ -294,7 +294,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// provided as a parameter.
/// </summary>
[Test]
public async Task ConnectToDefaultDatabaseRespondsWithActualDbName([Values("master", "nonMasterDb")]string expectedDbName)
public async Task ConnectToDefaultDatabaseRespondsWithActualDbName([Values("master", "nonMasterDb")] string expectedDbName)
{
// Given connecting with empty database name will return the expected DB name
var connectionMock = new Mock<DbConnection> { CallBase = true };
@@ -440,11 +440,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
new object[] {"Integrated", "file://my/sample/file.sql", null, "test", "sa", "123456"},
new object[] {"Integrated", "", "my-server", "test", "sa", "123456"},
new object[] {"Integrated", "file://my/sample/file.sql", "", "test", "sa", "123456"}
};
};
/// <summary>
/// Verify that when connecting with invalid parameters, an error is thrown.
/// </summary>
[Test, TestCaseSource(nameof(invalidParameters))]
[Test, TestCaseSource(nameof(invalidParameters))]
public async Task ConnectingWithInvalidParametersYieldsErrorMessage(string authType, string ownerUri, string server, string database, string userName, string password)
{
// Connect with invalid parameters
@@ -521,8 +521,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
{
new object[] {"AuthenticationType", "Integrated", "Integrated Security" },
new object[] {"AuthenticationType", "SqlLogin", ""},
new object[] {"Encrypt", true, "Encrypt"},
new object[] {"Encrypt", false, "Encrypt"},
new object[] {"Encrypt", "Mandatory", "Encrypt"},
new object[] {"Encrypt", "Optional", "Encrypt"},
new object[] {"Encrypt", "Strict", "Encrypt"},
new object[] {"ColumnEncryptionSetting", "Enabled", "Column Encryption Setting=Enabled"},
new object[] {"ColumnEncryptionSetting", "Disabled", "Column Encryption Setting=Disabled"},
new object[] {"ColumnEncryptionSetting", "enabled", "Column Encryption Setting=Enabled"},
@@ -533,6 +534,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
new object[] {"ColumnEncryptionSetting", "DiSaBlEd", "Column Encryption Setting=Disabled"},
new object[] {"TrustServerCertificate", true, "Trust Server Certificate"},
new object[] {"TrustServerCertificate", false, "Trust Server Certificate"},
new object[] {"HostNameInCertificate", "hostname", "Host Name In Certificate"},
new object[] {"PersistSecurityInfo", true, "Persist Security Info"},
new object[] {"PersistSecurityInfo", false, "Persist Security Info"},
new object[] {"ConnectTimeout", 15, "Connect Timeout"},
@@ -603,7 +605,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
.SetValue(details, propertyValue);
// Test that a connection string can be created without exceptions
string connectionString = ConnectionService.BuildConnectionString(details);
string connectionString = ConnectionService.BuildConnectionString(details);
Assert.That(connectionString, Contains.Substring(connectionStringMarker), "Verify that the parameter is in the connection string");
}
@@ -613,6 +615,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
new object[] {"ColumnEncryptionSetting", "NotAValidColumnEncryptionSetting" },
new object[] {"EnclaveAttestationProtocol", "NotAValidEnclaveAttestationProtocol" },
};
/// <summary>
/// Build connection string with an invalid property type
/// </summary>
@@ -625,7 +628,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.Throws<ArgumentException>(() => ConnectionService.BuildConnectionString(details));
}
private static readonly Tuple<string,object>[][] optionCombos =
private static readonly Tuple<string, object>[][] optionCombos =
{
new []
{
@@ -647,6 +650,29 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
};
private static readonly object[] EncryptionCombinations =
{
new object[] { SqlConnectionEncryptOption.Optional, SqlConnectionEncryptOption.Optional },
new object[] { SqlConnectionEncryptOption.Mandatory, SqlConnectionEncryptOption.Mandatory },
new object[] { SqlConnectionEncryptOption.Strict, SqlConnectionEncryptOption.Strict },
};
/// <summary>
/// Verify that Strict Encryption parameters can be built into a connection string for connecting.
/// </summary>
[Test, TestCaseSource(nameof(EncryptionCombinations))]
public void ConnectingWithStrictEncryptionBuildsConnectionString(SqlConnectionEncryptOption encryptValue, SqlConnectionEncryptOption expected)
{
// Create a test connection details object and set the property to a specific value
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
details.Encrypt = encryptValue.ToString();
// Test that a connection string can be created without exceptions
string connectionString = ConnectionService.BuildConnectionString(details);
Assert.That(connectionString, Contains.Substring("Encrypt=" + expected.ToString()), "Encrypt not as expected.");
}
/// <summary>
/// Build connection string with an invalid property combinations
/// </summary>
@@ -1137,10 +1163,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// Test that the connection summary comparer creates a hash code correctly
/// </summary>
[Test]
public void TestConnectionSummaryComparerHashCode([Values]bool objectNull,
[Values(null, "server")]string serverName,
[Values(null, "test")]string databaseName,
[Values(null, "sa")]string userName)
public void TestConnectionSummaryComparerHashCode([Values] bool objectNull,
[Values(null, "server")] string serverName,
[Values(null, "test")] string databaseName,
[Values(null, "sa")] string userName)
{
// Given a connection summary and comparer object
ConnectionSummary summary = null;
@@ -1341,13 +1367,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenNullOwnerUri([Values(null, "")]string ownerUri)
public async Task GetOrOpenNullOwnerUri([Values(null, "")] string ownerUri)
{
// If: I have a connection service and I ask for a connection with an invalid ownerUri
// Then: An exception should be thrown
var service = TestObjects.GetTestConnectionService();
Assert.ThrowsAsync<ArgumentException>(
() => service.GetOrOpenConnection(ownerUri, ConnectionType.Default));
Assert.ThrowsAsync<ArgumentException>(
() => service.GetOrOpenConnection(ownerUri, ConnectionType.Default));
}
[Test]
@@ -1643,19 +1669,43 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
// If we make a connection to a live database
ConnectionService service = ConnectionService.Instance;
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;HostNameInCertificate={servername}";
var details = service.ParseConnectionString(connectionString);
Assert.That(details.ServerName, Is.EqualTo("tcp:{servername},1433"), "Unexpected server name");
Assert.That(details.DatabaseName, Is.EqualTo("{databasename}"), "Unexpected database name");
Assert.That(details.UserName, Is.EqualTo("{your_username}"), "Unexpected username");
Assert.That(details.Password, Is.EqualTo("{your_password}"), "Unexpected password");
Assert.That(details.PersistSecurityInfo, Is.False, "Unexpected Persist Security Info");
Assert.That(details.MultipleActiveResultSets, Is.False, "Unexpected Multiple Active Result Sets value");
Assert.That(details.Encrypt, Is.EqualTo("True"), "Unexpected Encrypt value");
Assert.That(details.TrustServerCertificate, Is.False, "Unexpected database name value");
Assert.That(details.HostNameInCertificate, Is.EqualTo("{servername}"), "Unexpected Host Name in Certificate value");
Assert.That(details.ConnectTimeout, Is.EqualTo(30), "Unexpected Connect Timeout value");
}
Assert.AreEqual("tcp:{servername},1433", details.ServerName);
Assert.AreEqual("{databasename}", details.DatabaseName);
Assert.AreEqual("{your_username}", details.UserName);
Assert.AreEqual("{your_password}", details.Password);
Assert.AreEqual(false, details.PersistSecurityInfo);
Assert.AreEqual(false, details.MultipleActiveResultSets);
Assert.AreEqual(true, details.Encrypt);
Assert.AreEqual(false, details.TrustServerCertificate);
Assert.AreEqual(30, details.ConnectTimeout);
/// <summary>
/// Test ParseConnectionString
/// </summary>
[Test]
public void ParseConnectionStringTest_StrictEncryption()
{
// If we make a connection to a live database
ConnectionService service = ConnectionService.Instance;
var connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=Strict;TrustServerCertificate=False;Connection Timeout=30;HostNameInCertificate={servername}";
var details = service.ParseConnectionString(connectionString);
Assert.That(details.ServerName, Is.EqualTo("tcp:{servername},1433"), "Unexpected server name");
Assert.That(details.DatabaseName, Is.EqualTo("{databasename}"), "Unexpected database name");
Assert.That(details.UserName, Is.EqualTo("{your_username}"), "Unexpected username");
Assert.That(details.Password, Is.EqualTo("{your_password}"), "Unexpected password");
Assert.That(details.PersistSecurityInfo, Is.False, "Unexpected Persist Security Info");
Assert.That(details.MultipleActiveResultSets, Is.False, "Unexpected Multiple Active Result Sets value");
Assert.That(details.Encrypt, Is.EqualTo(SqlConnectionEncryptOption.Strict.ToString()), "Unexpected Encrypt value");
Assert.That(details.TrustServerCertificate, Is.False, "Unexpected database name value");
Assert.That(details.HostNameInCertificate, Is.EqualTo("{servername}"), "Unexpected Host Name in Certificate value");
Assert.That(details.ConnectTimeout, Is.EqualTo(30), "Unexpected Connect Timeout value");
}
[Test]

View File

@@ -169,7 +169,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
// connectionStringBuilder.ConnectTimeout = 123;
// connectionStringBuilder.Encrypt = true;
// connectionStringBuilder.ApplicationIntent = ApplicationIntent.ReadWrite;
// connectionStringBuilder.AsynchronousProcessing = true;
// connectionStringBuilder.MaxPoolSize = 45;
// connectionStringBuilder.MinPoolSize = 3;
// connectionStringBuilder.PacketSize = 600;