Enable empty passwords (#2021)

This commit is contained in:
Simon Sabin
2023-04-20 16:49:47 +01:00
committed by GitHub
parent 051fad128d
commit 96c5ec81e2
2 changed files with 32 additions and 3 deletions

View File

@@ -1377,7 +1377,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
break; break;
case SqlLogin: case SqlLogin:
connectionBuilder.UserID = connectionDetails.UserName; connectionBuilder.UserID = connectionDetails.UserName;
connectionBuilder.Password = connectionDetails.Password; if (!string.IsNullOrEmpty(connectionDetails.Password))
{
connectionBuilder.Password = connectionDetails.Password;
}
connectionBuilder.Authentication = SqlAuthenticationMethod.SqlPassword; connectionBuilder.Authentication = SqlAuthenticationMethod.SqlPassword;
break; break;
case AzureMFA: case AzureMFA:

View File

@@ -469,8 +469,35 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
Assert.That(connectionResult.ErrorMessage, Is.Not.Null.Or.Empty, "check that an error was caught"); Assert.That(connectionResult.ErrorMessage, Is.Not.Null.Or.Empty, "check that an error was caught");
} }
static readonly object[] noUserNameOrPassword = static readonly object[] noPassword =
{ {
new object[] {"sa", null},
new object[] {"sa", ""},
};
/// <summary>
/// Verify that when using sql logins, the password can be empty.
/// </summary>
[Test, TestCaseSource(nameof(noPassword))]
public void ConnectingWithNoPasswordWorksForSqlLogin(string userName, string password)
{
// Connect
var connectionResult =
ConnectionService.CreateConnectionStringBuilder(new ConnectionDetails()
{
ServerName = "my-server",
DatabaseName = "test",
UserName = userName,
Password = password,
AuthenticationType = SqlLogin
});
Assert.That(connectionResult, Is.Not.Null.Or.Empty, "check that the connection was successful");
}
static readonly object[] noUserNameOrPassword =
{
new object[] {null, null}, new object[] {null, null},
new object[] {null, ""}, new object[] {null, ""},
new object[] {"", null}, new object[] {"", null},
@@ -480,7 +507,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
new object[] {null, "12345678"}, new object[] {null, "12345678"},
new object[] {"", "12345678"}, new object[] {"", "12345678"},
}; };
/// <summary> /// <summary>
/// Verify that when using integrated authentication, the username and/or password can be empty. /// Verify that when using integrated authentication, the username and/or password can be empty.
/// </summary> /// </summary>