mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Add IncludePassword parameter to Get Connection String request (#670)
* Add IncludePassword flag to get connection string method * Override connection application name * Fix typo * Fix test break * Use ****** as password placeholder
This commit is contained in:
@@ -28,8 +28,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
/// Main class for the Connection Management services
|
/// Main class for the Connection Management services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConnectionService
|
public class ConnectionService
|
||||||
{
|
{
|
||||||
public const string AdminConnectionPrefix = "ADMIN:";
|
public const string AdminConnectionPrefix = "ADMIN:";
|
||||||
|
internal const string PasswordPlaceholder = "******";
|
||||||
private const string SqlAzureEdition = "SQL Azure";
|
private const string SqlAzureEdition = "SQL Azure";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1268,6 +1269,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!connStringParams.IncludePassword)
|
||||||
|
{
|
||||||
|
info.ConnectionDetails.Password = ConnectionService.PasswordPlaceholder;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.ConnectionDetails.ApplicationName = "sqlops-connection-string";
|
||||||
|
|
||||||
connectionString = BuildConnectionString(info.ConnectionDetails);
|
connectionString = BuildConnectionString(info.ConnectionDetails);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -14,5 +14,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
|||||||
/// URI of the owner of the connection
|
/// URI of the owner of the connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OwnerUri { get; set; }
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the password should be return in the connection string
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludePassword { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
@@ -115,9 +116,14 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
ConnectionService service = ConnectionService.Instance;
|
ConnectionService service = ConnectionService.Instance;
|
||||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<string>>();
|
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<string>>();
|
||||||
|
|
||||||
|
requestContext.Setup(x => x.SendResult(It.Is<string>((connectionString) => connectionString.Contains("Password=" + ConnectionService.PasswordPlaceholder))))
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
var requestParams = new GetConnectionStringParams()
|
var requestParams = new GetConnectionStringParams()
|
||||||
{
|
{
|
||||||
OwnerUri = result.ConnectionInfo.OwnerUri
|
OwnerUri = result.ConnectionInfo.OwnerUri,
|
||||||
|
IncludePassword = false
|
||||||
};
|
};
|
||||||
|
|
||||||
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
|
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
|
||||||
|
|||||||
Reference in New Issue
Block a user