ps/Modules/Alkami.DevOps.SystemEngineering/Public/New-SecurePassword.tests.ps1
2023-05-30 22:51:22 -07:00

52 lines
2.1 KiB
PowerShell

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "New-SecurePassword" {
Mock -CommandName Get-AWSRegion -ModuleName $moduleForMock -MockWith { return @( @{ 'Region' = 'us-east-1' } ) }
Mock -CommandName Import-AWSModule -ModuleName $moduleForMock -MockWith {}
Mock -CommandName Get-SECRandomPassword -ModuleName $moduleForMock -MockWith { return "Ab1!" }
Context "Parameter Validation" {
It "Throws if Password Length Is Too Short" {
{ New-SecurePassword -PasswordLength 1 -ProfileName 'temp-prod' -Region 'us-east-1' } | Should -Throw
}
It "Throws if Password Length Is Too Long" {
{ New-SecurePassword -PasswordLength 129 -ProfileName 'temp-prod' -Region 'us-east-1'} | Should -Throw
}
It "Throws if Profile Name is Null" {
{ New-SecurePassword -ProfileName $null -Region 'us-east-1' } | Should -Throw
}
It "Throws if Profile Name is Empty" {
{ New-SecurePassword -ProfileName '' -Region 'us-east-1' } | Should -Throw
}
It "Throws if Region is Not in Supported List" {
{ New-SecurePassword -ProfileName 'temp-prod' -Region 'Test' } | Should -Throw
}
}
Context "Logic" {
It "Returns a String" {
(Get-Command New-SecurePassword).OutputType.Type.ToString() | Should -BeExactly "System.String"
}
It "Proxies Input Parameters to AWS Call" {
New-SecurePassword -PasswordLength 20 -ExcludeCharacter "1" -ProfileName 'temp-prod' -Region 'us-east-1' | Out-Null
Assert-MockCalled -ModuleName $moduleForMock -CommandName Get-SECRandomPassword -Times 1 -Exactly -Scope It `
-ParameterFilter { (( $ProfileName -eq 'temp-prod' ) -and ( $Region -eq 'us-east-1' ) -and ( $PasswordLength -eq 20 ) -and ($ExcludeCharacter -eq '1')) }
}
}
}