Optional application name parameter for connection string (#1380)

* optional application name parameter for connection string
This commit is contained in:
Vasu Bhog
2022-02-03 16:00:08 -08:00
committed by GitHub
parent c092b194da
commit 8e5a23f755
4 changed files with 46 additions and 5 deletions

View File

@@ -533,9 +533,14 @@ Get a connection string for the provided connection.
public string OwnerUri { get; set; }
/// <summary>
/// Indicates whether the password should be return in the connection string
/// Indicates whether the password should be return in the connection string. Default is false.
/// </summary>
public bool IncludePassword { get; set; }
/// <summary>
/// Indicates whether the application name should be return in the connection string. Default is true.
/// </summary>
public bool? IncludeApplicationName { get; set;}
}
```
#### Response

View File

@@ -1327,9 +1327,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
}
connStringBuilder.ApplicationName = "sqlops-connection-string";
// default connection string application name to always be included unless set to false
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
{
connStringBuilder.ApplicationName = "sqlops-connection-string";
}
connectionString = connStringBuilder.ConnectionString;
}
catch (Exception e)

View File

@@ -17,7 +17,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
/// <summary>
/// Indicates whether the password should be return in the connection string
/// default is set to false
/// </summary>
public bool IncludePassword { get; set; }
/// <summary>
/// Indicates whether the application name should be return in the connection string
/// default is set to true
/// </summary>
public bool? IncludeApplicationName { get; set;}
}
}

View File

@@ -124,7 +124,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
var requestParams = new GetConnectionStringParams()
{
OwnerUri = result.ConnectionInfo.OwnerUri,
IncludePassword = false
IncludePassword = false,
IncludeApplicationName = true
};
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
@@ -139,5 +140,31 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
requestContext.VerifyAll();
}
/// <summary>
/// Test HandleGetConnectionStringRequest
/// When IncludeApplicationName is set to false the connection string should not contain the application name
/// </summary>
[Test]
public async Task GetCurrentConnectionStringTestwithoutApplicationName()
{
// If we make a connection to a live database
ConnectionService service = ConnectionService.Instance;
var result = LiveConnectionHelper.InitLiveConnectionInfo();
var resultApplicationName = result.ConnectionInfo.ConnectionDetails.ApplicationName;
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<string>>();
requestContext.Setup(x => x.SendResult(It.Is<string>((connectionString) => !connectionString.Contains("Application Name="+ resultApplicationName))))
.Returns(Task.FromResult(new object()));
var requestParams = new GetConnectionStringParams()
{
OwnerUri = result.ConnectionInfo.OwnerUri,
IncludePassword = false,
IncludeApplicationName = false
};
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
requestContext.VerifyAll();
}
}
}