Agent Proxy and Credential request handlers (#637)

* Agent Proxy account WIP

* Fixup Credential create\update\delete handlers

* Use current user for test credential

* Cleanup and delete code

* Convert tabs to spaces
This commit is contained in:
Karl Burtram
2018-06-14 11:55:38 -07:00
committed by GitHub
parent f53e532225
commit d2cc376b87
41 changed files with 1067 additions and 1312 deletions

View File

@@ -7,74 +7,89 @@ using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Agent;
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Security;
using Microsoft.SqlTools.ServiceLayer.Security.Contracts;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
using Xunit;
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
{
public class AgentProxyTests
{
/// <summary>
/// TestHandleCreateAgentProxyRequest
/// </summary>
[Fact]
public async Task TestHandleCreateAgentProxyRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// setup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var credential = await SecurityTestUtils.SetupCredential(connectionResult);
var service = new AgentService();
var proxy = AgentTestUtils.GetTestProxyInfo();
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
// test
await AgentTestUtils.CreateAgentProxy(service, connectionResult, proxy);
// cleanup
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
await SecurityTestUtils.CleanupCredential(connectionResult, credential);
}
}
/// <summary>
/// Verify the default "update agent alert" request handler with valid parameters
/// </summary>
//[Fact]
[Fact]
public async Task TestHandleUpdateAgentProxyRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var createContext = new Mock<RequestContext<CreateAgentProxyResult>>();
var updateContext = new Mock<RequestContext<UpdateAgentProxyResult>>();
var deleteContext = new Mock<RequestContext<ResultStatus>>();
var service = new AgentService();
var proxy = new AgentProxyInfo()
{
Id = 10,
AccountName = "Test Proxy 2",
CredentialName = "User",
Description = "",
IsEnabled = true
};
// cleanup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Proxy = proxy
}, deleteContext.Object);
deleteContext.VerifyAll();
await service.HandleCreateAgentProxyRequest(new CreateAgentProxyParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Proxy = proxy
}, createContext.Object);
createContext.VerifyAll();
var credential = await SecurityTestUtils.SetupCredential(connectionResult);
var service = new AgentService();
var proxy = AgentTestUtils.GetTestProxyInfo();
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
await AgentTestUtils.CreateAgentProxy(service, connectionResult, proxy);
// test
string originalProxyName = proxy.AccountName;
proxy.AccountName = proxy.AccountName + " Updated";
await service.HandleUpdateAgentProxyRequest(new UpdateAgentProxyParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
OriginalProxyName = originalProxyName,
Proxy = proxy
}, updateContext.Object);
await AgentTestUtils.UpdateAgentProxy(service, connectionResult, originalProxyName, proxy);
updateContext.VerifyAll();
await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Proxy = proxy
}, deleteContext.Object);
deleteContext.VerifyAll();
// cleanup
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
await SecurityTestUtils.CleanupCredential(connectionResult, credential);
}
}
}
/// <summary>
/// TestHandleDeleteAgentProxyRequest
/// </summary>
[Fact]
public async Task TestHandleDeleteAgentProxyRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// cleanup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var credential = await SecurityTestUtils.SetupCredential(connectionResult);
var service = new AgentService();
var proxy = AgentTestUtils.GetTestProxyInfo();
// test
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
await SecurityTestUtils.CleanupCredential(connectionResult, credential);
}
}
}
}

View File

@@ -9,6 +9,7 @@ using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Agent;
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
@@ -67,6 +68,17 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
Name = "Joe DBA",
EmailAddress = "test@aol.com"
};
}
internal static AgentProxyInfo GetTestProxyInfo()
{
return new AgentProxyInfo()
{
AccountName = "Test Proxy",
CredentialName = SecurityTestUtils.TestCredentialName,
Description = "Test proxy description",
IsEnabled = true
};
}
internal static async Task CreateAgentJob(
@@ -185,7 +197,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
Operator = operatorInfo
}, context.Object);
context.VerifyAll();
}
}
internal static async Task DeleteAgentOperator(
AgentService service,
@@ -199,7 +211,51 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
Operator = operatorInfo
}, context.Object);
context.VerifyAll();
}
}
internal static async Task CreateAgentProxy(
AgentService service,
TestConnectionResult connectionResult,
AgentProxyInfo proxy)
{
var context = new Mock<RequestContext<AgentProxyResult>>();
await service.HandleCreateAgentProxyRequest(new CreateAgentProxyParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Proxy = proxy
}, context.Object);
context.VerifyAll();
}
internal static async Task UpdateAgentProxy(
AgentService service,
TestConnectionResult connectionResult,
string originalProxyName,
AgentProxyInfo proxy)
{
var context = new Mock<RequestContext<AgentProxyResult>>();
await service.HandleUpdateAgentProxyRequest(new UpdateAgentProxyParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
OriginalProxyName = originalProxyName,
Proxy = proxy
}, context.Object);
context.VerifyAll();
}
internal static async Task DeleteAgentProxy(
AgentService service,
TestConnectionResult connectionResult,
AgentProxyInfo proxy)
{
var context = new Mock<RequestContext<ResultStatus>>();
await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
Proxy = proxy
}, context.Object);
context.VerifyAll();
}
internal static async Task<AgentAlertInfo[]> GetAgentAlerts(string connectionUri)
{