61 lines
2.2 KiB
PowerShell
61 lines
2.2 KiB
PowerShell
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|
$global:functionPath = Join-Path -Path $here -ChildPath $sut
|
|
Write-Host "Overriding SUT: $functionPath"
|
|
#Import-Module $functionPath -Force
|
|
$moduleForMock = ""
|
|
|
|
InModuleScope -ModuleName Alkami.DevOps.Certificates -ScriptBlock {
|
|
Write-Host "InModuleScope - Overriding SUT: $($global:functionPath)"
|
|
Import-Module $global:functionPath -Force
|
|
$moduleForMock = ""
|
|
$inScopeModuleForAssert = "Alkami.DevOps.Certificates"
|
|
|
|
Describe "SecretServerConnection" {
|
|
Context "When Calling GetSecretByName" {
|
|
|
|
Mock Invoke-RestMethod {
|
|
#Write-Warning "Mocked Invoke-RestMethod"
|
|
if ($uri -like "*CertName*123*") {
|
|
return New-Object psobject -Property @{
|
|
Name = "I'm a fake Secret"
|
|
}
|
|
} else {
|
|
return $null
|
|
}
|
|
} -ModuleName $moduleForMock
|
|
|
|
It "Returns Secrets Which Match The Supplied Name And FolderId" {
|
|
|
|
$connection = [SecretServerConnection]::new()
|
|
$result = $connection.GetSecretByName("CertName", 123)
|
|
|
|
Assert-MockCalled -ModuleName $inScopeModuleForAssert -CommandName Invoke-RestMethod
|
|
|
|
$result.Name | should -BeLike "I'm a fake Secret"
|
|
}
|
|
|
|
It "Does Not Return Secrets Which Do Not Match The Supplied Name" {
|
|
|
|
$connection = [SecretServerConnection]::new()
|
|
$result = $connection.GetSecretByName("BadName", 123)
|
|
|
|
Assert-MockCalled -ModuleName $inScopeModuleForAssert -CommandName Invoke-RestMethod
|
|
|
|
$result | should -BeNullOrEmpty
|
|
}
|
|
|
|
|
|
It "Does Not Return Secrets Which Do Match The Supplied Name But Not the Folder Id" {
|
|
|
|
$connection = [SecretServerConnection]::new()
|
|
$result = $connection.GetSecretByName("CertName", 456)
|
|
|
|
Assert-MockCalled -ModuleName $inScopeModuleForAssert -CommandName Invoke-RestMethod
|
|
|
|
$result | should -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|
|
} |