93 lines
3.3 KiB
PowerShell
93 lines
3.3 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 = ""
|
||
|
|
||
|
#region Disable-Nag
|
||
|
|
||
|
Describe "Disable-Nag" {
|
||
|
|
||
|
# Temp file to write content to
|
||
|
$tempFile = [System.IO.Path]::GetTempFileName()
|
||
|
$tempPath = $tempFile.Split(".") | Select-Object -First 1
|
||
|
|
||
|
New-Item -ItemType Directory $tempPath -ErrorAction SilentlyContinue | Out-Null
|
||
|
Write-Warning ("Using temp path: $tempPath for tests")
|
||
|
|
||
|
$tempConfig = (Join-Path $tempPath "Alkami.App.Nag.Host.Service.exe.config")
|
||
|
|
||
|
Context "Output File Validation" {
|
||
|
|
||
|
Mock Get-Service { return $null }
|
||
|
|
||
|
It "Updates the Nag Configuration With Fake Tenant and Job Whitelist Values" {
|
||
|
#Arrange
|
||
|
@"
|
||
|
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<configuration>
|
||
|
<appSettings>
|
||
|
<add key="TenantFIWhitelistRegex" value="" />
|
||
|
<add key="JobNameWhitelistRegex" value="" />
|
||
|
</appSettings>
|
||
|
</configuration>
|
||
|
"@ | Out-File $tempConfig -Force
|
||
|
#Act
|
||
|
{ Disable-Nag $tempPath } | Should -Not -Throw
|
||
|
#Assert
|
||
|
[xml]$outputXml = GC $tempConfig
|
||
|
$outputXml.SelectSingleNode("//appSettings/add[@key='TenantFIWhitelistRegex']").Value | Should -Be "DISABLE ALL TENANTS"
|
||
|
$outputXml.SelectSingleNode("//appSettings/add[@key='JobNameWhitelistRegex']").Value | Should -Be "DISABLE ALL JOBS"
|
||
|
}
|
||
|
|
||
|
It "Retains Fake Tenant and Job Whitelist Values If They Exist" {
|
||
|
#Arrange
|
||
|
@"
|
||
|
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<configuration>
|
||
|
<appSettings>
|
||
|
<add key="TenantFIWhitelistRegex" value="DISABLE ALL TENANTS" />
|
||
|
<add key="JobNameWhitelistRegex" value="DISABLE ALL JOBS" />
|
||
|
</appSettings>
|
||
|
</configuration>
|
||
|
"@ | Out-File $tempConfig -Force
|
||
|
#Act
|
||
|
{ Disable-Nag $tempPath } | Should -Not -Throw
|
||
|
#Assert
|
||
|
[xml]$outputXml = GC $tempConfig
|
||
|
$outputXml.SelectSingleNode("//appSettings/add[@key='TenantFIWhitelistRegex']").Value | Should -Be "DISABLE ALL TENANTS"
|
||
|
$outputXml.SelectSingleNode("//appSettings/add[@key='JobNameWhitelistRegex']").Value | Should -Be "DISABLE ALL JOBS"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "Windows Service Validation" {
|
||
|
|
||
|
$testServiceName = "Alkami Nag Service"
|
||
|
|
||
|
It "Disables the Nag Service if It Is Installed" {
|
||
|
|
||
|
try {
|
||
|
#Arrange
|
||
|
New-Service -Name $testServiceName -BinaryPathName "FakePath"
|
||
|
$testSvc = Get-Service -Name $testServiceName
|
||
|
|
||
|
if ($testSvc.StartType -eq "Disabled") {
|
||
|
throw "Service Already Disabled -- Invalid Test Setup Performed"
|
||
|
}
|
||
|
|
||
|
#Act
|
||
|
{ Disable-Nag $tempPath } | Should -Not -Throw
|
||
|
#Assert
|
||
|
(Get-Service $testServiceName).StartType -eq "Disabled" | Should -Be $true
|
||
|
} finally {
|
||
|
if ($null -ne (Get-Service $testServiceName -ErrorAction SilentlyContinue)) {
|
||
|
(Get-CIMInstance Win32_Service -filter ("name='{0}'" -f $testServiceName)) | Invoke-CIMMethod -MethodName Delete
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion Disable-Nag
|