Add login management handlers (#1868)

* update contracts

* finish creating/loading login for SQL Server

* support role read for azure and add more handlers

* fix advanced option flags

---------

Co-authored-by: Karl Burtram <karlb@microsoft.com>
This commit is contained in:
Hai Cao
2023-02-17 09:56:03 -08:00
committed by GitHub
parent 86a8861e78
commit 7ffc85d7fc
8 changed files with 489 additions and 89 deletions

View File

@@ -11,7 +11,7 @@ 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 Microsoft.SqlTools.ServiceLayer.Utility;
using Moq;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
@@ -31,40 +31,46 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
{
// setup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var contextId = System.Guid.NewGuid().ToString();
var initializeLoginViewRequestParams = new InitializeLoginViewRequestParams
{
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
ContextId = contextId,
IsNewObject = true
};
var loginParams = new CreateLoginParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
ContextId = contextId,
Login = SecurityTestUtils.GetTestLoginInfo()
};
var createContext = new Mock<RequestContext<CreateLoginResult>>();
createContext.Setup(x => x.SendResult(It.IsAny<CreateLoginResult>()))
var createLoginContext = new Mock<RequestContext<object>>();
createLoginContext.Setup(x => x.SendResult(It.IsAny<object>()))
.Returns(Task.FromResult(new object()));
var initializeLoginViewContext = new Mock<RequestContext<LoginViewInfo>>();
initializeLoginViewContext.Setup(x => x.SendResult(It.IsAny<LoginViewInfo>()))
.Returns(Task.FromResult(new LoginViewInfo()));
// call the create login method
SecurityService service = new SecurityService();
await service.HandleCreateLoginRequest(loginParams, createContext.Object);
// verify the result
createContext.Verify(x => x.SendResult(It.Is<CreateLoginResult>
(p => p.Success && p.Login.LoginName != string.Empty)));
await service.HandleInitializeLoginViewRequest(initializeLoginViewRequestParams, initializeLoginViewContext.Object);
await service.HandleCreateLoginRequest(loginParams, createLoginContext.Object);
// cleanup created login
var deleteParams = new DeleteLoginParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
LoginName = loginParams.Login.LoginName
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
Name = loginParams.Login.Name
};
var deleteContext = new Mock<RequestContext<ResultStatus>>();
deleteContext.Setup(x => x.SendResult(It.IsAny<ResultStatus>()))
var deleteContext = new Mock<RequestContext<object>>();
deleteContext.Setup(x => x.SendResult(It.IsAny<object>()))
.Returns(Task.FromResult(new object()));
// call the create login method
await service.HandleDeleteLoginRequest(deleteParams, deleteContext.Object);
// verify the result
deleteContext.Verify(x => x.SendResult(It.Is<ResultStatus>(p => p.Success)));
}
}
}

View File

@@ -29,17 +29,14 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
{
return new LoginInfo()
{
LoginName = "TestLoginName_" + new Random().NextInt64(10000000,90000000).ToString(),
LoginType= LoginType.Sql,
CertificateName = "Test Cert",
AsymmetricKeyName = "Asymmetric Test Cert",
Name = "TestLoginName_" + new Random().NextInt64(10000000,90000000).ToString(),
AuthenticationType= LoginAuthenticationType.Sql,
WindowsGrantAccess = true,
MustChange = false,
IsDisabled = false,
MustChangePassword = false,
IsEnabled = false,
IsLockedOut = false,
EnforcePolicy = false,
EnforceExpiration = false,
WindowsAuthSupported = false,
EnforcePasswordPolicy = false,
EnforcePasswordExpiration = false,
Password = "placeholder",
OldPassword = "placeholder",
DefaultLanguage = "us_english",

View File

@@ -28,29 +28,37 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
{
// setup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var contextId = System.Guid.NewGuid().ToString();
var initializeLoginViewRequestParams = new InitializeLoginViewRequestParams
{
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
ContextId = contextId,
IsNewObject = true
};
var loginParams = new CreateLoginParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
ContextId = contextId,
Login = SecurityTestUtils.GetTestLoginInfo()
};
var createLoginContext = new Mock<RequestContext<CreateLoginResult>>();
createLoginContext.Setup(x => x.SendResult(It.IsAny<CreateLoginResult>()))
var createLoginContext = new Mock<RequestContext<object>>();
createLoginContext.Setup(x => x.SendResult(It.IsAny<object>()))
.Returns(Task.FromResult(new object()));
var initializeLoginViewContext = new Mock<RequestContext<LoginViewInfo>>();
initializeLoginViewContext.Setup(x => x.SendResult(It.IsAny<LoginViewInfo>()))
.Returns(Task.FromResult(new LoginViewInfo()));
// call the create login method
SecurityService service = new SecurityService();
await service.HandleInitializeLoginViewRequest(initializeLoginViewRequestParams, initializeLoginViewContext.Object);
await service.HandleCreateLoginRequest(loginParams, createLoginContext.Object);
// verify the result
createLoginContext.Verify(x => x.SendResult(It.Is<CreateLoginResult>
(p => p.Success && p.Login.LoginName != string.Empty)));
var userParams = new CreateUserParams
{
ContextId = connectionResult.ConnectionInfo.OwnerUri,
User = SecurityTestUtils.GetTestUserInfo(loginParams.Login.LoginName)
User = SecurityTestUtils.GetTestUserInfo(loginParams.Login.Name)
};
var createUserContext = new Mock<RequestContext<CreateUserResult>>();