52 lines
3.1 KiB
PowerShell
52 lines
3.1 KiB
PowerShell
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|
|
|
$importPasswordTest = "PASSWORD_GOES_HERE"
|
|
$pathToCertificateIsADirectory = "C:\Temp\Personal"
|
|
$pathToCertificateIsNotAPfxFile = "C:\Temp\Personal\Certificate.crt"
|
|
$pathToCertificateIsNotAccessible = "C:\Temp\Personal\CertificateThatShouldNotBeAccessibleUnlessYouMakeThisFileToSpiteMe.pfx"
|
|
$pathToCertificatePfxFile = "C:\Temp\Personal\Certificate.pfx"
|
|
|
|
$WriteErrorIncorrectPfxArgument = "This function is expecting a certificate with a .pfx extension as the value for"
|
|
$WriteErrorInaccessiblePfxFile = "Unable to reach the specified file from this server"
|
|
|
|
Describe "Import-PfxCertificateWithPermissions" {
|
|
|
|
Mock -CommandName Copy-Item -ModuleName Alkami.DevOps.Certificates -MockWith { }
|
|
Mock -CommandName Import-Certificates -ModuleName Alkami.DevOps.Certificates -MockWith { }
|
|
Mock -CommandName Write-Error -ModuleName Alkami.DevOps.Certificates -MockWith { }
|
|
|
|
Context "When there are bad inputs when calling Import-PfxCertificateWithPermissions" {
|
|
|
|
Mock -CommandName Test-Path -ModuleName Alkami.DevOps.Certificates -MockWith { return $false }
|
|
|
|
It "Writes Error if path argument has a folder path and does not point to a PFX file" {
|
|
Import-PfxCertificateWithPermissions -ImportPassword $importPasswordTest -PathToPfxCertificate $pathToCertificateIsADirectory
|
|
Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It -ModuleName Alkami.DevOps.Certificates -ParameterFilter { $Message -match $WriteErrorIncorrectPfxArgument }
|
|
}
|
|
|
|
It "Writes Error if path argument has a file path but does not point to a PFX file" {
|
|
Import-PfxCertificateWithPermissions -ImportPassword $importPasswordTest -PathToPfxCertificate $pathToCertificateIsNotAPfxFile
|
|
Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It -ModuleName Alkami.DevOps.Certificates -ParameterFilter { $Message -match $WriteErrorIncorrectPfxArgument }
|
|
}
|
|
|
|
It "Writes Error if path argument does not point to an accessible PFX file" {
|
|
Import-PfxCertificateWithPermissions -ImportPassword $importPasswordTest -PathToPfxCertificate $pathToCertificateIsNotAccessible
|
|
Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It -ModuleName Alkami.DevOps.Certificates -ParameterFilter { $Message -match $WriteErrorInaccessiblePfxFile }
|
|
}
|
|
}
|
|
|
|
Context "When Inputs are correct" {
|
|
|
|
Mock -CommandName Test-Path -ModuleName Alkami.DevOps.Certificates -MockWith { return $true }
|
|
|
|
It "Assert reaches Import-Certificates " {
|
|
Import-PfxCertificateWithPermissions -ImportPassword $importPasswordTest -PathToPfxCertificate $pathToCertificatePfxFile
|
|
Assert-MockCalled -ModuleName Alkami.DevOps.Certificates Import-Certificates -Times 1 -Exactly -Scope It
|
|
}
|
|
|
|
It "Assert randomly created folder doesn't exist after function completion " {
|
|
$folder = Import-PfxCertificateWithPermissions -ImportPassword $importPasswordTest -PathToPfxCertificate $pathToCertificatePfxFile
|
|
$folder | Should -Not -Exist
|
|
}
|
|
}
|
|
} |