mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Add change password function and handling (#1771)
* added ChangePassword to connectionService * added changepasswordparams * added more code * added more changes to connectionservice * added more changes * added small test * added changepasswordrequest * added different ServerConnection constructor * consolidated changepassword * added exception catch * added passwordChangeFail params * added changePassword to it's own function * simplified changePassword * made fixes to test * added new test * added one additional connection test * added response callback * removed unnecessary SendError * added localized empty password error * added updated error messages * added small fix to check * added changes based on feedback * added minor change * fix tests * renamed messages to errorDetails * simplified error message * small change to connectionservice message * error message change * added environment newline * added error retry messages to STS * added regex * added newline handling
This commit is contained in:
@@ -1763,5 +1763,72 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.IsFalse(ConnectionService.IsDbPool("db"));
|
||||
Assert.IsFalse(ConnectionService.IsDbPool(null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that providing an empty password to change password will fire an error.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ConnectionEmptyPasswordChange()
|
||||
{
|
||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
||||
|
||||
var connectionService = ConnectionService.Instance;
|
||||
connectionService.ServiceHost = serviceHostMock.Object;
|
||||
|
||||
// Set up an initial connection
|
||||
const string ownerUri = "file://my/sample/file.sql";
|
||||
ChangePasswordParams testConnectionParams = new ChangePasswordParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetTestConnectionDetails(),
|
||||
NewPassword = ""
|
||||
};
|
||||
Assert.Throws<Exception>(() => connectionService.ChangePassword(testConnectionParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that providing an invalid connection parameter value to change password will fire an error.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ConnectionInvalidParamPasswordChange()
|
||||
{
|
||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
||||
|
||||
var connectionService = ConnectionService.Instance;
|
||||
connectionService.ServiceHost = serviceHostMock.Object;
|
||||
|
||||
// Set up an initial connection
|
||||
const string ownerUri = "file://my/sample/file.sql";
|
||||
ChangePasswordParams testConnectionParams = new ChangePasswordParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = { },
|
||||
NewPassword = "TestPassword"
|
||||
};
|
||||
Assert.Throws<Exception>(() => connectionService.ChangePassword(testConnectionParams));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that providing a non actual connection and a fake password to change password will throw an error.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task InvalidConnectionPasswordChange()
|
||||
{
|
||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
||||
|
||||
var connectionService = ConnectionService.Instance;
|
||||
connectionService.ServiceHost = serviceHostMock.Object;
|
||||
|
||||
// Set up an initial connection
|
||||
const string ownerUri = "file://my/sample/file.sql";
|
||||
ChangePasswordParams testConnectionParams = new ChangePasswordParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetTestConnectionDetails(),
|
||||
NewPassword = "TestPassword"
|
||||
};
|
||||
Assert.Throws<Microsoft.SqlServer.Management.Common.ChangePasswordFailureException>(
|
||||
() => connectionService.ChangePassword(testConnectionParams));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user