Implement Get/Set-TokenLifetime

This commit is contained in:
dmilov
2020-09-30 14:26:31 +03:00
parent 5abdbe9702
commit 14e81f78af
7 changed files with 280 additions and 1 deletions

View File

@@ -0,0 +1,75 @@
#**************************************************************************
# 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 "TokenLifetime 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-TokenLifetime" {
It 'Gets token lifetime settings' {
# Act
$actual = Get-TokenLifetime
# Assert
$actual | Should Not Be $null
$actual.MaxHoKTokenLifetime | Should BeGreaterThan 0
$actual.MaxBearerTokenLifetime | Should BeGreaterThan 0
}
}
Context "Set-TokenLifetime" {
It 'Updates MaxHoKTokenLifetime and MaxBearerTokenLifetime' {
# Arrange
$tokenLifetimeToUpdate = Get-TokenLifetime
$expectedMaxHoKTokenLifetime = 60
$expectedMaxBearerTokenLifetime = 30
# Act
$actual = Set-TokenLifetime `
-TokenLifetime $tokenLifetimeToUpdate `
-MaxHoKTokenLifetime $expectedMaxHoKTokenLifetime `
-MaxBearerTokenLifetime $expectedMaxBearerTokenLifetime
# Assert
$actual | Should Not Be $null
$actual.MaxHoKTokenLifetime | Should Be $expectedMaxHoKTokenLifetime
$actual.MaxBearerTokenLifetime | Should Be $expectedMaxBearerTokenLifetime
# Cleanup
$tokenLifetimeToUpdate | Set-TokenLifetime `
-MaxHoKTokenLifetime $tokenLifetimeToUpdate.MaxHoKTokenLifetime `
-MaxBearerTokenLifetime $tokenLifetimeToUpdate.MaxBearerTokenLifetime
}
}
}