mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Support scripting for Users (#2002)
* WIP 1 * WIP2 * Fix merge break * Support alter existing object
This commit is contained in:
@@ -165,7 +165,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||
DatabaseUserType userType,
|
||||
string userName = null,
|
||||
string loginName = null,
|
||||
string databaseName = "master")
|
||||
string databaseName = "master",
|
||||
bool scriptUser = false)
|
||||
{
|
||||
string contextId = System.Guid.NewGuid().ToString();
|
||||
var initializeViewRequestParams = new InitializeUserViewParams
|
||||
@@ -181,6 +182,25 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||
.Returns(Task.FromResult(new UserViewInfo()));
|
||||
|
||||
await service.HandleInitializeUserViewRequest(initializeViewRequestParams, initializeUserViewContext.Object);
|
||||
|
||||
if (scriptUser)
|
||||
{
|
||||
var scriptParams = new ScriptUserParams
|
||||
{
|
||||
ContextId = contextId,
|
||||
User = SecurityTestUtils.GetTestUserInfo(userType, userName, loginName)
|
||||
};
|
||||
|
||||
var scriptUserContext = new Mock<RequestContext<string>>();
|
||||
scriptUserContext.Setup(x => x.SendResult(It.IsAny<string>()))
|
||||
.Returns(Task.FromResult(new object()));
|
||||
|
||||
await service.HandleScriptUserRequest(scriptParams, scriptUserContext.Object);
|
||||
|
||||
// verify the result
|
||||
scriptUserContext.Verify(x => x.SendResult(It.Is<string>
|
||||
(p => p.Contains("CREATE USER"))));
|
||||
}
|
||||
|
||||
var userParams = new CreateUserParams
|
||||
{
|
||||
|
||||
@@ -112,5 +112,29 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||
await SecurityTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, SecurityTestUtils.GetLoginURN(login.Name));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the basic Create User method handler
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task TestScriptUserWithLogin()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
UserServiceHandlerImpl userService = new UserServiceHandlerImpl();
|
||||
LoginServiceHandlerImpl loginService = new LoginServiceHandlerImpl();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
|
||||
var login = await SecurityTestUtils.CreateLogin(loginService, connectionResult);
|
||||
|
||||
var user = await SecurityTestUtils.CreateUser(userService, connectionResult,
|
||||
DatabaseUserType.WithLogin, null, login.Name, scriptUser: true);
|
||||
|
||||
await SecurityTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, SecurityTestUtils.GetUserURN(connectionResult.ConnectionInfo.ConnectionDetails.DatabaseName, user.Name));
|
||||
|
||||
await SecurityTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, SecurityTestUtils.GetLoginURN(login.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user