mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Do not update the DB name when connecting to DB pool (#1186)
* Do not update the DB name when connecting to DB pool * Fix typo in the connection service
This commit is contained in:
@@ -21,7 +21,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
{
|
||||
[TestFixture]
|
||||
@@ -297,11 +297,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Connection = connectionDetails
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(connectionResult.ConnectionId, Is.Not.Empty, "ConnectionId");
|
||||
Assert.NotNull(connectionResult.ConnectionSummary, "ConnectionSummary");
|
||||
Assert.AreEqual(expectedDbName, connectionResult.ConnectionSummary.DatabaseName, "I expect connection to succeed and the Summary to include the correct DB name");
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(connectionResult.ConnectionId, Is.Not.Empty, "ConnectionId");
|
||||
Assert.NotNull(connectionResult.ConnectionSummary, "ConnectionSummary");
|
||||
Assert.AreEqual(expectedDbName, connectionResult.ConnectionSummary.DatabaseName, "I expect connection to succeed and the Summary to include the correct DB name");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -405,10 +405,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.That(connectionResult.Messages, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
}
|
||||
|
||||
static readonly object[] invalidParameters =
|
||||
{
|
||||
new object[] { "SqlLogin", null, "my-server", "test", "sa", "123456" },
|
||||
new object[] { "SqlLogin", "file://my/sample/file.sql", null, "test", "sa", "123456" },
|
||||
static readonly object[] invalidParameters =
|
||||
{
|
||||
new object[] { "SqlLogin", null, "my-server", "test", "sa", "123456" },
|
||||
new object[] { "SqlLogin", "file://my/sample/file.sql", null, "test", "sa", "123456" },
|
||||
new object[] {"SqlLogin", "file://my/sample/file.sql", "my-server", "test", null, "123456"},
|
||||
new object[] {"SqlLogin", "file://my/sample/file.sql", "my-server", "test", "sa", null},
|
||||
new object[] {"SqlLogin", "", "my-server", "test", "sa", "123456" },
|
||||
@@ -418,7 +418,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
new object[] {"Integrated", null, "my-server", "test", "sa", "123456"},
|
||||
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"}
|
||||
new object[] {"Integrated", "file://my/sample/file.sql", "", "test", "sa", "123456"}
|
||||
};
|
||||
/// <summary>
|
||||
/// Verify that when connecting with invalid parameters, an error is thrown.
|
||||
@@ -445,16 +445,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.That(connectionResult.Messages, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
}
|
||||
|
||||
static readonly object[] noUserNameOrPassword =
|
||||
{
|
||||
new object[] {null, null},
|
||||
new object[] {null, ""},
|
||||
new object[] {"", null},
|
||||
new object[] {"", ""},
|
||||
new object[] {"sa", null},
|
||||
new object[] {"sa", ""},
|
||||
new object[] {null, "12345678"},
|
||||
new object[] {"", "12345678"},
|
||||
static readonly object[] noUserNameOrPassword =
|
||||
{
|
||||
new object[] {null, null},
|
||||
new object[] {null, ""},
|
||||
new object[] {"", null},
|
||||
new object[] {"", ""},
|
||||
new object[] {"sa", null},
|
||||
new object[] {"sa", ""},
|
||||
new object[] {null, "12345678"},
|
||||
new object[] {"", "12345678"},
|
||||
};
|
||||
/// <summary>
|
||||
/// Verify that when using integrated authentication, the username and/or password can be empty.
|
||||
@@ -496,8 +496,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
}
|
||||
|
||||
|
||||
private static readonly object[] optionalParameters =
|
||||
{
|
||||
private static readonly object[] optionalParameters =
|
||||
{
|
||||
new object[] {"AuthenticationType", "Integrated", "Integrated Security" },
|
||||
new object[] {"AuthenticationType", "SqlLogin", ""},
|
||||
new object[] {"Encrypt", true, "Encrypt"},
|
||||
@@ -536,13 +536,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
new object[] {"MultipleActiveResultSets", false, "Multiple Active Result Sets"},
|
||||
new object[] {"MultipleActiveResultSets", true, "Multiple Active Result Sets"},
|
||||
new object[] {"PacketSize", 8192, "Packet Size"},
|
||||
new object[] {"TypeSystemVersion", "Latest", "Type System Version"},
|
||||
};
|
||||
|
||||
new object[] {"TypeSystemVersion", "Latest", "Type System Version"},
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Verify that optional parameters can be built into a connection string for connecting.
|
||||
/// </summary>
|
||||
[Test, TestCaseSource(nameof(optionalParameters))]
|
||||
[Test, TestCaseSource(nameof(optionalParameters))]
|
||||
public void ConnectingWithOptionalParametersBuildsConnectionString(string propertyName, object propertyValue, string connectionStringMarker)
|
||||
{
|
||||
// Create a test connection details object and set the property to a specific value
|
||||
@@ -556,15 +556,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.That(connectionString, Contains.Substring(connectionStringMarker), "Verify that the parameter is in the connection string");
|
||||
}
|
||||
|
||||
private static readonly object[] optionalEnclaveParameters =
|
||||
{
|
||||
private static readonly object[] optionalEnclaveParameters =
|
||||
{
|
||||
new object[] {"EnclaveAttestationProtocol", "AAS", "Attestation Protocol=AAS"},
|
||||
new object[] {"EnclaveAttestationProtocol", "HGS", "Attestation Protocol=HGS"},
|
||||
new object[] {"EnclaveAttestationProtocol", "aas", "Attestation Protocol=AAS"},
|
||||
new object[] {"EnclaveAttestationProtocol", "hgs", "Attestation Protocol=HGS"},
|
||||
new object[] {"EnclaveAttestationProtocol", "AaS", "Attestation Protocol=AAS"},
|
||||
new object[] {"EnclaveAttestationProtocol", "hGs", "Attestation Protocol=HGS"},
|
||||
new object[] {"EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave", "Enclave Attestation Url=https://attestation.us.attest.azure.net/attest/SgxEnclave" },
|
||||
new object[] {"EnclaveAttestationUrl", "https://attestation.us.attest.azure.net/attest/SgxEnclave", "Enclave Attestation Url=https://attestation.us.attest.azure.net/attest/SgxEnclave" },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -586,11 +586,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.That(connectionString, Contains.Substring(connectionStringMarker), "Verify that the parameter is in the connection string");
|
||||
}
|
||||
|
||||
private static readonly object[] invalidOptions =
|
||||
{
|
||||
private static readonly object[] invalidOptions =
|
||||
{
|
||||
new object[] {"AuthenticationType", "NotAValidAuthType" },
|
||||
new object[] {"ColumnEncryptionSetting", "NotAValidColumnEncryptionSetting" },
|
||||
new object[] {"EnclaveAttestationProtocol", "NotAValidEnclaveAttestationProtocol" },
|
||||
new object[] {"EnclaveAttestationProtocol", "NotAValidEnclaveAttestationProtocol" },
|
||||
};
|
||||
/// <summary>
|
||||
/// Build connection string with an invalid property type
|
||||
@@ -604,8 +604,8 @@ 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 []
|
||||
{
|
||||
Tuple.Create<string, object>("ColumnEncryptionSetting", null),
|
||||
@@ -623,7 +623,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
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>
|
||||
@@ -633,14 +633,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
public void ConnStrWithInvalidOptions()
|
||||
{
|
||||
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
|
||||
foreach (var options in optionCombos)
|
||||
{
|
||||
options.ToList().ForEach(tuple =>
|
||||
{
|
||||
PropertyInfo info = details.GetType().GetProperty(tuple.Item1);
|
||||
info.SetValue(details, tuple.Item2);
|
||||
});
|
||||
Assert.Throws<ArgumentException>(() => ConnectionService.BuildConnectionString(details));
|
||||
foreach (var options in optionCombos)
|
||||
{
|
||||
options.ToList().ForEach(tuple =>
|
||||
{
|
||||
PropertyInfo info = details.GetType().GetProperty(tuple.Item1);
|
||||
info.SetValue(details, tuple.Item2);
|
||||
});
|
||||
Assert.Throws<ArgumentException>(() => ConnectionService.BuildConnectionString(details));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1663,5 +1663,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
// Then the connection factory got called with details including an account token
|
||||
mockFactory.Verify(factory => factory.CreateSqlConnection(It.IsAny<string>(), It.Is<string>(accountToken => accountToken == azureAccountToken)), Times.Once());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test is IsDbPool method correctly works for various database names
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CheckIsDbPool()
|
||||
{
|
||||
Assert.IsTrue(ConnectionService.IsDbPool("db@pool"));
|
||||
Assert.IsFalse(ConnectionService.IsDbPool("db"));
|
||||
Assert.IsFalse(ConnectionService.IsDbPool(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user