mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Update Microsoft.Data.SqlClient to v5.0.1 (#1708)
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user