mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Handle null passwords when creating SecureStrings in AdminService (#457)
This commit is contained in:
@@ -180,10 +180,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
// check if the connection is using SQL Auth or Integrated Auth
|
// check if the connection is using SQL Auth or Integrated Auth
|
||||||
if (string.Equals(connInfo.ConnectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(connInfo.ConnectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var passwordSecureString = new System.Security.SecureString();
|
var passwordSecureString = BuildSecureStringFromPassword(connInfo.ConnectionDetails.Password);
|
||||||
foreach (char c in connInfo.ConnectionDetails.Password) {
|
|
||||||
passwordSecureString.AppendChar(c);
|
|
||||||
}
|
|
||||||
dataContainer = new CDataContainer(
|
dataContainer = new CDataContainer(
|
||||||
CDataContainer.ServerType.SQL,
|
CDataContainer.ServerType.SQL,
|
||||||
connInfo.ConnectionDetails.ServerName,
|
connInfo.ConnectionDetails.ServerName,
|
||||||
@@ -207,6 +204,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
return taskHelper;
|
return taskHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static System.Security.SecureString BuildSecureStringFromPassword(string password) {
|
||||||
|
var passwordSecureString = new System.Security.SecureString();
|
||||||
|
if (password != null) {
|
||||||
|
foreach (char c in password) {
|
||||||
|
passwordSecureString.AppendChar(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return passwordSecureString;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create data container document
|
/// Create data container document
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System.Security;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Admin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for AdminService Class
|
||||||
|
/// </summary>
|
||||||
|
public class AdminServiceTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void TestBuildingSecureStringFromPassword()
|
||||||
|
{
|
||||||
|
string password = "test_password";
|
||||||
|
var secureString = AdminService.BuildSecureStringFromPassword(password);
|
||||||
|
Assert.Equal(password.Length, secureString.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestBuildingSecureStringFromNullPassword()
|
||||||
|
{
|
||||||
|
string password = null;
|
||||||
|
var secureString = AdminService.BuildSecureStringFromPassword(password);
|
||||||
|
Assert.Equal(0, secureString.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user