mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Enable user management tests (#1912)
* Enable user management tests * Fix update user test
This commit is contained in:
@@ -125,8 +125,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
await SecurityTestUtils.DeleteCredential(service, connectionResult, credential);
|
await SecurityTestUtils.DeleteCredential(service, connectionResult, credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task<LoginInfo> CreateLogin(SecurityService service, TestConnectionResult connectionResult, string contextId)
|
internal static async Task<LoginInfo> CreateLogin(SecurityService service, TestConnectionResult connectionResult)
|
||||||
{
|
{
|
||||||
|
string contextId = System.Guid.NewGuid().ToString();
|
||||||
var initializeLoginViewRequestParams = new InitializeLoginViewRequestParams
|
var initializeLoginViewRequestParams = new InitializeLoginViewRequestParams
|
||||||
{
|
{
|
||||||
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
|
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||||
@@ -174,9 +175,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
internal static async Task<UserInfo> CreateUser(
|
internal static async Task<UserInfo> CreateUser(
|
||||||
UserServiceHandlerImpl service,
|
UserServiceHandlerImpl service,
|
||||||
TestConnectionResult connectionResult,
|
TestConnectionResult connectionResult,
|
||||||
string contextId,
|
|
||||||
LoginInfo login)
|
LoginInfo login)
|
||||||
{
|
{
|
||||||
|
string contextId = System.Guid.NewGuid().ToString();
|
||||||
var initializeViewRequestParams = new InitializeUserViewParams
|
var initializeViewRequestParams = new InitializeUserViewParams
|
||||||
{
|
{
|
||||||
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
|
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||||
@@ -187,7 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
|
|
||||||
var initializeUserViewContext = new Mock<RequestContext<UserViewInfo>>();
|
var initializeUserViewContext = new Mock<RequestContext<UserViewInfo>>();
|
||||||
initializeUserViewContext.Setup(x => x.SendResult(It.IsAny<UserViewInfo>()))
|
initializeUserViewContext.Setup(x => x.SendResult(It.IsAny<UserViewInfo>()))
|
||||||
.Returns(Task.FromResult(new LoginViewInfo()));
|
.Returns(Task.FromResult(new UserViewInfo()));
|
||||||
|
|
||||||
await service.HandleInitializeUserViewRequest(initializeViewRequestParams, initializeUserViewContext.Object);
|
await service.HandleInitializeUserViewRequest(initializeViewRequestParams, initializeUserViewContext.Object);
|
||||||
|
|
||||||
@@ -208,17 +209,43 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
createUserContext.Verify(x => x.SendResult(It.Is<CreateUserResult>
|
createUserContext.Verify(x => x.SendResult(It.Is<CreateUserResult>
|
||||||
(p => p.Success && p.User.Name != string.Empty)));
|
(p => p.Success && p.User.Name != string.Empty)));
|
||||||
|
|
||||||
|
var disposeViewRequestParams = new DisposeUserViewRequestParams
|
||||||
|
{
|
||||||
|
ContextId = contextId
|
||||||
|
};
|
||||||
|
|
||||||
|
var disposeUserViewContext = new Mock<RequestContext<ResultStatus>>();
|
||||||
|
disposeUserViewContext.Setup(x => x.SendResult(It.IsAny<ResultStatus>()))
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
await service.HandleDisposeUserViewRequest(disposeViewRequestParams, disposeUserViewContext.Object);
|
||||||
|
|
||||||
return userParams.User;
|
return userParams.User;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task UpdateUser(
|
internal static async Task<UserInfo> UpdateUser(
|
||||||
UserServiceHandlerImpl service,
|
UserServiceHandlerImpl service,
|
||||||
TestConnectionResult connectionResult,
|
TestConnectionResult connectionResult,
|
||||||
string contextId,
|
|
||||||
UserInfo user)
|
UserInfo user)
|
||||||
{
|
{
|
||||||
|
string contextId = System.Guid.NewGuid().ToString();
|
||||||
|
var initializeViewRequestParams = new InitializeUserViewParams
|
||||||
|
{
|
||||||
|
ConnectionUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||||
|
ContextId = contextId,
|
||||||
|
IsNewObject = false,
|
||||||
|
Database = "master",
|
||||||
|
Name = user.Name
|
||||||
|
};
|
||||||
|
|
||||||
|
var initializeUserViewContext = new Mock<RequestContext<UserViewInfo>>();
|
||||||
|
initializeUserViewContext.Setup(x => x.SendResult(It.IsAny<UserViewInfo>()))
|
||||||
|
.Returns(Task.FromResult(new UserViewInfo()));
|
||||||
|
|
||||||
|
await service.HandleInitializeUserViewRequest(initializeViewRequestParams, initializeUserViewContext.Object);
|
||||||
|
|
||||||
// update the user
|
// update the user
|
||||||
user.OwnedSchemas = new string[] { "dbo" };
|
user.DatabaseRoles = new string[] { "db_datareader" };
|
||||||
var updateParams = new UpdateUserParams
|
var updateParams = new UpdateUserParams
|
||||||
{
|
{
|
||||||
ContextId = contextId,
|
ContextId = contextId,
|
||||||
@@ -229,6 +256,19 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
await service.HandleUpdateUserRequest(updateParams, updateUserContext.Object);
|
await service.HandleUpdateUserRequest(updateParams, updateUserContext.Object);
|
||||||
// verify the result
|
// verify the result
|
||||||
updateUserContext.Verify(x => x.SendResult(It.Is<ResultStatus>(p => p.Success)));
|
updateUserContext.Verify(x => x.SendResult(It.Is<ResultStatus>(p => p.Success)));
|
||||||
|
|
||||||
|
var disposeViewRequestParams = new DisposeUserViewRequestParams
|
||||||
|
{
|
||||||
|
ContextId = contextId
|
||||||
|
};
|
||||||
|
|
||||||
|
var disposeUserViewContext = new Mock<RequestContext<ResultStatus>>();
|
||||||
|
disposeUserViewContext.Setup(x => x.SendResult(It.IsAny<ResultStatus>()))
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
await service.HandleDisposeUserViewRequest(disposeViewRequestParams, disposeUserViewContext.Object);
|
||||||
|
|
||||||
|
return updateParams.User;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task DeleteUser(UserServiceHandlerImpl service, TestConnectionResult connectionResult, UserInfo user)
|
internal static async Task DeleteUser(UserServiceHandlerImpl service, TestConnectionResult connectionResult, UserInfo user)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Security;
|
using Microsoft.SqlTools.ServiceLayer.Security;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||||
{
|
{
|
||||||
@@ -18,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the basic Create User method handler
|
/// Test the basic Create User method handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
//[Test] - enable tests in separate change
|
[Test]
|
||||||
public async Task TestHandleCreateUserWithLoginRequest()
|
public async Task TestHandleCreateUserWithLoginRequest()
|
||||||
{
|
{
|
||||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||||
@@ -27,11 +28,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
SecurityService service = new SecurityService();
|
SecurityService service = new SecurityService();
|
||||||
UserServiceHandlerImpl userService = new UserServiceHandlerImpl();
|
UserServiceHandlerImpl userService = new UserServiceHandlerImpl();
|
||||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||||
var contextId = System.Guid.NewGuid().ToString();
|
|
||||||
|
|
||||||
var login = await SecurityTestUtils.CreateLogin(service, connectionResult, contextId);
|
var login = await SecurityTestUtils.CreateLogin(service, connectionResult);
|
||||||
|
|
||||||
var user = await SecurityTestUtils.CreateUser(userService, connectionResult, contextId, login);
|
var user = await SecurityTestUtils.CreateUser(userService, connectionResult, login);
|
||||||
|
|
||||||
await SecurityTestUtils.DeleteUser(userService, connectionResult, user);
|
await SecurityTestUtils.DeleteUser(userService, connectionResult, user);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the basic Update User method handler
|
/// Test the basic Update User method handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
//[Test] - enable tests in separate change
|
[Test]
|
||||||
public async Task TestHandleUpdateUserWithLoginRequest()
|
public async Task TestHandleUpdateUserWithLoginRequest()
|
||||||
{
|
{
|
||||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||||
@@ -51,13 +51,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
|||||||
SecurityService service = new SecurityService();
|
SecurityService service = new SecurityService();
|
||||||
UserServiceHandlerImpl userService = new UserServiceHandlerImpl();
|
UserServiceHandlerImpl userService = new UserServiceHandlerImpl();
|
||||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||||
var contextId = System.Guid.NewGuid().ToString();
|
|
||||||
|
|
||||||
var login = await SecurityTestUtils.CreateLogin(service, connectionResult, contextId);
|
var login = await SecurityTestUtils.CreateLogin(service, connectionResult);
|
||||||
|
|
||||||
var user = await SecurityTestUtils.CreateUser(userService, connectionResult, contextId, login);
|
var user = await SecurityTestUtils.CreateUser(userService, connectionResult, login);
|
||||||
|
|
||||||
await SecurityTestUtils.UpdateUser(userService, connectionResult, contextId, user);
|
await SecurityTestUtils.UpdateUser(userService, connectionResult, user);
|
||||||
|
|
||||||
await SecurityTestUtils.DeleteUser(userService, connectionResult, user);
|
await SecurityTestUtils.DeleteUser(userService, connectionResult, user);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user