Implement ResetPassword and Unlock for PersonUser accounts.

This commit is contained in:
dmilov
2020-09-29 17:16:47 +03:00
parent 5fb63bb345
commit b8030e4272
6 changed files with 160 additions and 2 deletions

View File

@@ -115,6 +115,30 @@ namespace VMware.vSphere.SsoAdminClient.Tests
Assert.IsTrue(addActual);
Assert.IsTrue(removeActual);
// Cleanup
ssoAdminClient.DeleteLocalUser(
newUser);
}
[Test]
public void ResetUserPassword() {
// Arrange
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
var expectedUserName = "test-user6";
var expectedPassword = "te$tPa$sW0rd";
var updatePassword = "TE$tPa$sW0rd";
var newUser = ssoAdminClient.CreateLocalUser(
expectedUserName,
expectedPassword);
// Act
// Assert
Assert.DoesNotThrow(() => {
ssoAdminClient.ResetPersonUserPassword(newUser, updatePassword);
});
// Cleanup
ssoAdminClient.DeleteLocalUser(
newUser);

View File

@@ -302,6 +302,42 @@ namespace VMware.vSphere.SsoAdminClient
},
group.Name)).Result;
}
public void ResetPersonUserPassword(PersonUser user, string newPassword) {
// Create Authorization Invocation Context
var authorizedInvocationContext =
CreateAuthorizedInvocationContext();
// Invoke SSO Admin ResetLocalPersonUserPasswordAsync operation
authorizedInvocationContext.
InvokeOperation(() =>
_ssoAdminBindingClient.ResetLocalPersonUserPasswordAsync(
new ManagedObjectReference {
type = "SsoAdminPrincipalManagementService",
Value = "principalManagementService"
},
user.Name,
newPassword)).Wait();
}
public bool UnlockPersonUser(PersonUser user) {
// Create Authorization Invocation Context
var authorizedInvocationContext =
CreateAuthorizedInvocationContext();
// Invoke SSO Admin UnlockUserAccountAsync operation
return authorizedInvocationContext.
InvokeOperation(() =>
_ssoAdminBindingClient.UnlockUserAccountAsync(
new ManagedObjectReference {
type = "SsoAdminPrincipalManagementService",
Value = "principalManagementService"
},
new SsoPrincipalId {
name = user.Name,
domain = user.Domain
})).Result;
}
#endregion
}
}

View File

@@ -262,7 +262,7 @@ Describe "PersonUser Tests" {
}
}
Context "Set-PersonUser Add/Remove Group" {
Context "Set-PersonUser" {
It 'Adds person user to group' {
# Arrange
$userName = "TestAddGroupPersonUserName"
@@ -334,6 +334,61 @@ Describe "PersonUser Tests" {
# Assert
$actual | Should Not Be $null
}
It 'Resets person user password' {
# Arrange
$userName = "TestResetPassPersonUserName"
$userPassword = '$tr0NG_TestPa$$w0rd'
$newPassword = 'Update_TestPa$$w0rd'
$connection = Connect-SsoAdminServer `
-Server $VcAddress `
-User $User `
-Password $Password `
-SkipCertificateCheck
$personUserToUpdate = New-PersonUser `
-UserName $userName `
-Password $userPassword `
-Server $connection
$script:usersToCleanup += $personUserToUpdate
# Act
$actual = Set-PersonUser `
-User $personUserToUpdate `
-NewPassword $newPassword `
-Server $connection
# Assert
$actual | Should Not Be $null
}
It 'Unlocks not locked person user' {
# Arrange
$userName = "TestResetPassPersonUserName"
$userPassword = '$tr0NG_TestPa$$w0rd'
$connection = Connect-SsoAdminServer `
-Server $VcAddress `
-User $User `
-Password $Password `
-SkipCertificateCheck
$personUserToUpdate = New-PersonUser `
-UserName $userName `
-Password $userPassword `
-Server $connection
$script:usersToCleanup += $personUserToUpdate
# Act
$actual = Set-PersonUser `
-User $personUserToUpdate `
-Unlock `
-Server $connection
# Assert
$actual | Should Be $null
}
}
Context "Remove-PersonUser" {