Turning off Verbose and Warning stream in Pester tests and test only previous month #125

This commit is contained in:
Emin 2024-01-08 20:16:52 +01:00
Родитель 0ae02d8e59
Коммит 4cd1557fbe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F0E13C335CAF6476
1 изменённых файлов: 28 добавлений и 14 удалений

Просмотреть файл

@ -3,7 +3,7 @@
# Import-Module -Name MsrcSecurityUpdates -Force # Import-Module -Name MsrcSecurityUpdates -Force
$Error.Clear() $Error.Clear()
Get-Module -Name MsrcSecurityUpdates | Remove-Module -Force -Verbose:$false Get-Module -Name MsrcSecurityUpdates | Remove-Module -Force -Verbose:$false
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MsrcSecurityUpdates.psd1') -Verbose -Force Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MsrcSecurityUpdates.psd1') -Verbose:$false -Force
Describe 'API version after module loading' { Describe 'API version after module loading' {
It '$msrcApiUrl = https://api.msrc.microsoft.com/cvrf/v3.0' { It '$msrcApiUrl = https://api.msrc.microsoft.com/cvrf/v3.0' {
@ -20,8 +20,12 @@ Describe 'API version after module loading' {
$msrcApiVersion -eq 'api-version=2016-08-01' | Should Be $true $msrcApiVersion -eq 'api-version=2016-08-01' | Should Be $true
} }
} }
Set-MSRCApiKey -APIVersion 2.0
Describe 'Function: Get-MsrcSecurityUpdateMSRC (calls the /Updates API)' { '2.0','3.0' |
Foreach-Object {
$v = $_
Set-MSRCApiKey -APIVersion $_
Describe ('Function: Get-MsrcSecurityUpdate (calls the /Updates API version {0})' -f $v) {
It 'Get-MsrcSecurityUpdate - all' { It 'Get-MsrcSecurityUpdate - all' {
Get-MsrcSecurityUpdate | Get-MsrcSecurityUpdate |
@ -44,22 +48,25 @@ Describe 'Function: Get-MsrcSecurityUpdateMSRC (calls the /Updates API)' {
} }
It 'Get-MsrcSecurityUpdate - by date - before' { It 'Get-MsrcSecurityUpdate - by date - before' {
Get-MsrcSecurityUpdate -Before 2018-01-01 | { $w = $null
Should Not BeNullOrEmpty $w = Get-MsrcSecurityUpdate -Before 2018-01-01 -WarningVariable w -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$w.Message -eq 'No results returned from the /Update API' } | Should Be $true
} }
It 'Get-MsrcSecurityUpdate - by date - after' { It 'Get-MsrcSecurityUpdate - by date - after' {
Get-MsrcSecurityUpdate -After 2017-01-01 | { $w = $null
Should Not BeNullOrEmpty Get-MsrcSecurityUpdate -After 2017-01-01 -WarningVariable w -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$w.Message -eq 'No results returned from the /Update API' } | Should Be $true
} }
It 'Get-MsrcSecurityUpdate - by date - before and after' { It 'Get-MsrcSecurityUpdate - by date - before and after' {
Get-MsrcSecurityUpdate -Before 2018-01-01 -After 2017-10-01 | { $w = $null
Should Not BeNullOrEmpty Get-MsrcSecurityUpdate -Before 2018-01-01 -After 2017-10-01 -WarningVariable w -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$w.Message -eq 'No results returned from the /Update API' } | Should Be $true
} }
} }
Describe 'Function: Get-MsrcCvrfDocument (calls the MSRC /cvrf API)' { Describe ('Function: Get-MsrcCvrfDocument (calls the MSRC /cvrf API version {0})' -f $v) {
It 'Get-MsrcCvrfDocument - 2016-Nov' { It 'Get-MsrcCvrfDocument - 2016-Nov' {
Get-MsrcCvrfDocument -ID 2016-Nov | Get-MsrcCvrfDocument -ID 2016-Nov |
@ -71,7 +78,9 @@ Describe 'Function: Get-MsrcCvrfDocument (calls the MSRC /cvrf API)' {
Should Not BeNullOrEmpty Should Not BeNullOrEmpty
} }
<#
Get-MsrcSecurityUpdate | Where-Object { $_.ID -ne '2017-May-B' } | Get-MsrcSecurityUpdate | Where-Object { $_.ID -ne '2017-May-B' } |
Where-Object { $_.ID -eq "$(((Get-Date).AddMonths(-1)).ToString('yyyy-MMM',[System.Globalization.CultureInfo]'en-US'))" } |
Foreach-Object { Foreach-Object {
It "Get-MsrcCvrfDocument - none shall throw: $($PSItem.ID)" { It "Get-MsrcCvrfDocument - none shall throw: $($PSItem.ID)" {
{ {
@ -89,6 +98,7 @@ Describe 'Function: Get-MsrcCvrfDocument (calls the MSRC /cvrf API)' {
} }
} | Should Throw } | Should Throw
} }
#>
} }
Describe 'Function: Set-MSRCApiKey with proxy' { Describe 'Function: Set-MSRCApiKey with proxy' {
@ -147,25 +157,27 @@ InModuleScope MsrcSecurityUpdates {
} }
} }
Describe 'Function: Get-MsrcVulnerabilityReportHtml (generates the MSRC Vulnerability Summary HTML Report)' { Describe ('Function: Get-MsrcVulnerabilityReportHtml (generates the MSRC Vulnerability Summary HTML Report with API version {0})' -f $v) {
It 'Vulnerability Summary Report - does not throw' { It 'Vulnerability Summary Report - does not throw' {
{ {
$null = Get-MsrcCvrfDocument -ID 2016-Nov | $null = Get-MsrcCvrfDocument -ID 2016-Nov |
Get-MsrcVulnerabilityReportHtml -Verbose -ShowNoProgress Get-MsrcVulnerabilityReportHtml -Verbose:$false -ShowNoProgress -WarningAction SilentlyContinue
} | } |
Should Not Throw Should Not Throw
} }
<#
Get-MsrcSecurityUpdate | Where-Object { $_.ID -ne '2017-May-B' } | Get-MsrcSecurityUpdate | Where-Object { $_.ID -ne '2017-May-B' } |
Where-Object { $_.ID -eq "$(((Get-Date).AddMonths(-1)).ToString('yyyy-MMM',[System.Globalization.CultureInfo]'en-US'))" } |
Foreach-Object { Foreach-Object {
It "Vulnerability Summary Report - none shall throw: $($PSItem.ID)" { It "Vulnerability Summary Report - none shall throw: $($PSItem.ID)" {
{ {
$null = Get-MsrcCvrfDocument -ID $PSItem.ID | $null = Get-MsrcCvrfDocument -ID $PSItem.ID |
Get-MsrcVulnerabilityReportHtml -ShowNoProgress Get-MsrcVulnerabilityReportHtml -ShowNoProgress -WarningAction SilentlyContinue
} | } |
Should Not Throw Should Not Throw
} }
} }
#>
} }
InModuleScope MsrcSecurityUpdates { InModuleScope MsrcSecurityUpdates {
@ -191,6 +203,8 @@ InModuleScope MsrcSecurityUpdates {
} }
} }
}
#When a pester test fails, it writes out to stdout, and sets an error in $Error. When invoking powershell from C# it is a lot easier to read the stderr stream. #When a pester test fails, it writes out to stdout, and sets an error in $Error. When invoking powershell from C# it is a lot easier to read the stderr stream.
if($Error) if($Error)
{ {