Implement Get/Set-PasswordPolicy cmdlets
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
#**************************************************************************
|
||||
# Copyright (c) VMware, Inc. All rights reserved.
|
||||
#**************************************************************************
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$VcAddress,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$User,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$Password
|
||||
)
|
||||
|
||||
# Import Vmware.vSphere.SsoAdmin Module
|
||||
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
|
||||
Import-Module $modulePath
|
||||
|
||||
Describe "PasswordPolicy Tests" {
|
||||
BeforeEach {
|
||||
Connect-SsoAdminServer `
|
||||
-Server $VcAddress `
|
||||
-User $User `
|
||||
-Password $Password `
|
||||
-SkipCertificateCheck
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
$connectionsToCleanup = $global:DefaultSsoAdminServers.ToArray()
|
||||
foreach ($connection in $connectionsToCleanup) {
|
||||
Disconnect-SsoAdminServer -Server $connection
|
||||
}
|
||||
}
|
||||
|
||||
Context "Get-PasswordPolicy" {
|
||||
It 'Gets password policy' {
|
||||
# Act
|
||||
$actual = Get-PasswordPolicy
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
}
|
||||
}
|
||||
|
||||
Context "Set-PasswordPolicy" {
|
||||
It 'Updates password policy MaxLength and PasswordLifetimeDays' {
|
||||
# Arrange
|
||||
$passwordPolicyToUpdate = Get-PasswordPolicy
|
||||
$expectedMaxLength = 17
|
||||
$expectedPasswordLifetimeDays = 77
|
||||
|
||||
# Act
|
||||
$actual = Set-PasswordPolicy `
|
||||
-PasswordPolicy $passwordPolicyToUpdate `
|
||||
-MaxLength $expectedMaxLength `
|
||||
-PasswordLifetimeDays $expectedPasswordLifetimeDays
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
$actual.MaxLength | Should Be $expectedMaxLength
|
||||
$actual.PasswordLifetimeDays | Should Be $expectedPasswordLifetimeDays
|
||||
$actual.Description | Should Be $passwordPolicyToUpdate.Description
|
||||
$actual.ProhibitedPreviousPasswordsCount | Should Be $passwordPolicyToUpdate.ProhibitedPreviousPasswordsCount
|
||||
$actual.MinLength | Should Be $passwordPolicyToUpdate.MinLength
|
||||
$actual.MaxIdenticalAdjacentCharacters | Should Be $passwordPolicyToUpdate.MaxIdenticalAdjacentCharacters
|
||||
$actual.MinNumericCount | Should Be $passwordPolicyToUpdate.MinNumericCount
|
||||
$actual.MinSpecialCharCount | Should Be $passwordPolicyToUpdate.MinSpecialCharCount
|
||||
$actual.MinAlphabeticCount | Should Be $passwordPolicyToUpdate.MinAlphabeticCount
|
||||
$actual.MinUppercaseCount | Should Be $passwordPolicyToUpdate.MinUppercaseCount
|
||||
$actual.MinLowercaseCount | Should Be $passwordPolicyToUpdate.MinLowercaseCount
|
||||
|
||||
# Cleanup
|
||||
$passwordPolicyToUpdate | Set-PasswordPolicy
|
||||
}
|
||||
|
||||
It 'Updates password policy Description and MinUppercaseCount' {
|
||||
# Arrange
|
||||
$passwordPolicyToUpdate = Get-PasswordPolicy
|
||||
$expectedMinUppercaseCount = 0
|
||||
$expectedDescription = "Test Description"
|
||||
|
||||
# Act
|
||||
$actual = $passwordPolicyToUpdate | Set-PasswordPolicy `
|
||||
-Description $expectedDescription `
|
||||
-MinUppercaseCount $expectedMinUppercaseCount
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
$actual.Description | Should Be $expectedDescription
|
||||
$actual.MinUppercaseCount | Should Be $expectedMinUppercaseCount
|
||||
$actual.MaxLength | Should Be $passwordPolicyToUpdate.MaxLength
|
||||
$actual.PasswordLifetimeDays | Should Be $passwordPolicyToUpdate.PasswordLifetimeDays
|
||||
$actual.ProhibitedPreviousPasswordsCount | Should Be $passwordPolicyToUpdate.ProhibitedPreviousPasswordsCount
|
||||
$actual.MinLength | Should Be $passwordPolicyToUpdate.MinLength
|
||||
$actual.MaxIdenticalAdjacentCharacters | Should Be $passwordPolicyToUpdate.MaxIdenticalAdjacentCharacters
|
||||
$actual.MinNumericCount | Should Be $passwordPolicyToUpdate.MinNumericCount
|
||||
$actual.MinSpecialCharCount | Should Be $passwordPolicyToUpdate.MinSpecialCharCount
|
||||
$actual.MinAlphabeticCount | Should Be $passwordPolicyToUpdate.MinAlphabeticCount
|
||||
$actual.MinLowercaseCount | Should Be $passwordPolicyToUpdate.MinLowercaseCount
|
||||
|
||||
# Cleanup
|
||||
$passwordPolicyToUpdate | Set-PasswordPolicy
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,8 +289,7 @@ Describe "PersonUser Tests" {
|
||||
$actual = Set-PersonUser `
|
||||
-User $personUserToUpdate `
|
||||
-Group $groupUserToBeAddedTo `
|
||||
-Add `
|
||||
-Server $connection
|
||||
-Add
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
@@ -321,15 +320,13 @@ Describe "PersonUser Tests" {
|
||||
Set-PersonUser `
|
||||
-User $personUserToUpdate `
|
||||
-Group $groupToBeUsed `
|
||||
-Add `
|
||||
-Server $connection | Out-Null
|
||||
-Add
|
||||
|
||||
# Act
|
||||
$actual = Set-PersonUser `
|
||||
-User $personUserToUpdate `
|
||||
-Group $groupToBeUsed `
|
||||
-Remove `
|
||||
-Server $connection
|
||||
-Remove
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
@@ -356,8 +353,7 @@ Describe "PersonUser Tests" {
|
||||
# Act
|
||||
$actual = Set-PersonUser `
|
||||
-User $personUserToUpdate `
|
||||
-NewPassword $newPassword `
|
||||
-Server $connection
|
||||
-NewPassword $newPassword
|
||||
|
||||
# Assert
|
||||
$actual | Should Not Be $null
|
||||
@@ -383,8 +379,7 @@ Describe "PersonUser Tests" {
|
||||
# Act
|
||||
$actual = Set-PersonUser `
|
||||
-User $personUserToUpdate `
|
||||
-Unlock `
|
||||
-Server $connection
|
||||
-Unlock
|
||||
|
||||
# Assert
|
||||
$actual | Should Be $null
|
||||
@@ -409,7 +404,7 @@ Describe "PersonUser Tests" {
|
||||
-Server $connection
|
||||
|
||||
# Act
|
||||
Remove-PersonUser -User $personUserToRemove -Server $connection
|
||||
Remove-PersonUser -User $personUserToRemove
|
||||
|
||||
# Assert
|
||||
$personUserToRemove | Should Not Be $null
|
||||
|
||||
Reference in New Issue
Block a user