mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-02 09:35:38 -05:00
Initial WIP code for user management (#1838)
* Initial user management code * WIP * Fix whitespace * WIP user objects * WIP user objects * Cleanup ported code * WIP * WIP * Update the User contracts * Additional cleanups * Remove warning silencing which isn't intended for this PR * Fix some warnings as error in CI
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
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;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the Login management component
|
||||
/// </summary>
|
||||
public class LoginTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Test the basic Create Login method handler
|
||||
/// </summary>
|
||||
// [Test]
|
||||
public async Task TestHandleCreateLoginRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var loginParams = new CreateLoginParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Login = SecurityTestUtils.GetTestLoginInfo()
|
||||
};
|
||||
|
||||
var createContext = new Mock<RequestContext<CreateLoginResult>>();
|
||||
createContext.Setup(x => x.SendResult(It.IsAny<CreateLoginResult>()))
|
||||
.Returns(Task.FromResult(new object()));
|
||||
|
||||
// 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)));
|
||||
|
||||
// cleanup created login
|
||||
var deleteParams = new DeleteLoginParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
LoginName = loginParams.Login.LoginName
|
||||
};
|
||||
|
||||
var deleteContext = new Mock<RequestContext<ResultStatus>>();
|
||||
deleteContext.Setup(x => x.SendResult(It.IsAny<ResultStatus>()))
|
||||
.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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,28 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Security
|
||||
return string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName);
|
||||
}
|
||||
|
||||
internal static LoginInfo GetTestLoginInfo()
|
||||
{
|
||||
return new LoginInfo()
|
||||
{
|
||||
LoginName = "TestLoginName_" + new Random().NextInt64(10000000,90000000).ToString(),
|
||||
LoginType= LoginType.Sql,
|
||||
CertificateName = "Test Cert",
|
||||
AsymmetricKeyName = "Asymmetric Test Cert",
|
||||
WindowsGrantAccess = true,
|
||||
MustChange = false,
|
||||
IsDisabled = false,
|
||||
IsLockedOut = false,
|
||||
EnforcePolicy = false,
|
||||
EnforceExpiration = false,
|
||||
WindowsAuthSupported = false,
|
||||
Password = "!#!@#@#@dflksdjfksdlfjlksdFEEfjklsed9393",
|
||||
OldPassword = "{{OLD_TEST_PASSWORD_PLACEHOLDER}}",
|
||||
DefaultLanguage = "us_english",
|
||||
DefaultDatabase = "master"
|
||||
};
|
||||
}
|
||||
|
||||
internal static CredentialInfo GetTestCredentialInfo()
|
||||
{
|
||||
return new CredentialInfo()
|
||||
|
||||
Reference in New Issue
Block a user