From f50f30b49365a7cc4a7de6d913a7beb0cf25c961 Mon Sep 17 00:00:00 2001 From: Henry Phan Date: Tue, 2 May 2017 10:17:44 -0700 Subject: [PATCH] Changes to sqltoolsservice to allow empty password for SqlLogin (#333) * Initial changes to allow empty passwords * Added in empty password test * Modifying test to work after my changes. --- .../Credentials/Contracts/Credential.cs | 2 +- .../Connection/Contracts/ConnectParamsExtensions.cs | 6 +----- .../Credentials/CredentialServiceTests.cs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.SqlTools.Credentials/Credentials/Contracts/Credential.cs b/src/Microsoft.SqlTools.Credentials/Credentials/Contracts/Credential.cs index b34d9453..6403f8ad 100644 --- a/src/Microsoft.SqlTools.Credentials/Credentials/Contracts/Credential.cs +++ b/src/Microsoft.SqlTools.Credentials/Credentials/Contracts/Credential.cs @@ -78,7 +78,7 @@ namespace Microsoft.SqlTools.Credentials.Contracts public static void ValidateForSave(Credential credential) { ValidateForLookup(credential); - Validate.IsNotNullOrEmptyString("credential.Password", credential.Password); + Validate.IsNotNull("credential.Password", credential.Password); } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs index 6b191dde..c1f162d9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs @@ -35,15 +35,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts } else if (string.IsNullOrEmpty(parameters.Connection.AuthenticationType) || parameters.Connection.AuthenticationType == "SqlLogin") { - // For SqlLogin, username/password cannot be empty + // For SqlLogin, username cannot be empty if (string.IsNullOrEmpty(parameters.Connection.UserName)) { errorMessage = SR.ConnectionParamsValidateNullSqlAuth("UserName"); } - else if( string.IsNullOrEmpty(parameters.Connection.Password)) - { - errorMessage = SR.ConnectionParamsValidateNullSqlAuth("Password"); - } } return string.IsNullOrEmpty(errorMessage); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Credentials/CredentialServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Credentials/CredentialServiceTests.cs index d91f64b2..caa8ef1f 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Credentials/CredentialServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Credentials/CredentialServiceTests.cs @@ -91,9 +91,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials await service.HandleSaveCredentialRequest(new Credential(CredentialId), contextMock.Object); TestUtils.VerifyErrorSent(contextMock); - Assert.Contains("ArgumentException", errorResponse); + Assert.True(errorResponse.Contains("ArgumentException") || errorResponse.Contains("ArgumentNullException")); } - + [Fact] public async Task SaveCredentialWorksForSingleCredential() { @@ -102,6 +102,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials verify: Assert.True); } + [Fact] + public async Task SaveCredentialWorksForEmptyPassword() + { + await TestUtils.RunAndVerify( + test: (requestContext) => service.HandleSaveCredentialRequest(new Credential(CredentialId, ""), requestContext), + verify: Assert.True); + } + [Fact] public async Task SaveCredentialSupportsSavingCredentialMultipleTimes() {