From b10c090e8523a8129757b5a3a00ffbdd40dce813 Mon Sep 17 00:00:00 2001 From: Chris Gardner Date: Tue, 11 Jul 2017 22:12:58 +0100 Subject: [PATCH 1/3] xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key - Fixes #55 (#56) * Update tests to look for correct value. * Fix property returned by Get-TargetResource. * Fix other uses of Service in Test and Set functions * Add tests for Test-TargetResourceProperties * Add tests for Get-WuAuNotificationLevelInt --- .../MSFT_xWindowsUpdateAgent.psm1 | 6 +- Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1 | 86 +++++++++++++++++-- 2 files changed, 84 insertions(+), 8 deletions(-) diff --git a/DscResources/MSFT_xWindowsUpdateAgent/MSFT_xWindowsUpdateAgent.psm1 b/DscResources/MSFT_xWindowsUpdateAgent/MSFT_xWindowsUpdateAgent.psm1 index 54b9c89..2e0e97f 100644 --- a/DscResources/MSFT_xWindowsUpdateAgent/MSFT_xWindowsUpdateAgent.psm1 +++ b/DscResources/MSFT_xWindowsUpdateAgent/MSFT_xWindowsUpdateAgent.psm1 @@ -399,7 +399,7 @@ function Get-TargetResource TotalUpdatesNotInstalled = $totalUpdatesNotInstalled RebootRequired = $rebootRequired Notifications = $notificationLevel - Service = $SourceReturn + Source = $SourceReturn UpdateNow = $UpdateNowReturn } $returnValue @@ -443,7 +443,7 @@ function Set-TargetResource Write-Verbose "updateNow compliant: $updateCompliant" $notificationCompliant = (!$Notifications -or $Notifications -eq $Get.Notifications) Write-Verbose "notifications compliant: $notificationCompliant" - $SourceCompliant = (!$Source -or $Source -eq $Get.Service) + $SourceCompliant = (!$Source -or $Source -eq $Get.Source) Write-Verbose "service compliant: $notificationCompliant" If(!$updateCompliant -and $PSCmdlet.ShouldProcess("Install Updates")) @@ -549,7 +549,7 @@ function Test-TargetResource Write-Verbose "updateNow compliant: $updateCompliant" $notificationCompliant = (!$Notifications -or $Notifications -eq $Get.Notifications) Write-Verbose "notifications compliant: $notificationCompliant" - $SourceCompliant = (!$Source -or $Source -eq $Get.Service) + $SourceCompliant = (!$Source -or $Source -eq $Get.Source) Write-Verbose "service compliant: $notificationCompliant" If($updateCompliant -and $notificationCompliant -and $SourceCompliant) { diff --git a/Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1 b/Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1 index 27ac26a..8781388 100644 --- a/Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1 +++ b/Tests/Unit/MSFT_xWindowsUpdateAgent.tests.ps1 @@ -42,7 +42,7 @@ try # The InModuleScope command allows you to perform white-box unit testing on the internal # (non-exported) code of a Script Module. InModuleScope $Global:DSCResourceName { - + #region Pester Test Initialization $Global:mockedSearchResultWithUpdate = [PSCustomObject] @{ Updates = @{ @@ -149,8 +149,8 @@ try it 'should return UpdateNome=$true'{ $getResult.UpdateNow | should be $true } - it 'should return Service=MU'{ - $getResult.Service | should be "MicrosoftUpdate" + it 'should return Source=MU'{ + $getResult.Source | should be "MicrosoftUpdate" } it 'should have called the mock' { @@ -203,8 +203,8 @@ try it 'should return UpdateNome=$true'{ $getResult.UpdateNow | should be $true } - it 'should return Service=WU'{ - $getResult.Service | should be "WindowsUpdate" + it 'should return Source=WU'{ + $getResult.Source | should be "WindowsUpdate" } it 'should have called the mock' { @@ -1587,6 +1587,82 @@ try } } + Describe "$($Global:DSCResourceName)\Test-TargetResourceProperties" { + Mock -CommandName Write-Warning -MockWith {} -Verifiable + Mock -CommandName Write-Verbose -MockWith {} + + It 'Calls write-warning when no categories are passed' { + $PropertiesToTest = @{ + IsSingleInstance = 'Yes' + Notifications = 'Disabled' + Source = 'WindowsUpdate' + Category = @() + UpdateNow = $True + } + Test-TargetResourceProperties @PropertiesToTest + + Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It + } + + It 'Calls write-warning when Important updates are requested but not Security updates' { + $PropertiesToTest = @{ + IsSingleInstance = 'Yes' + Notifications = 'Disabled' + Source = 'WindowsUpdate' + Category = 'Important' + } + Test-TargetResourceProperties @PropertiesToTest + + Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It + } + + It 'Calls write-warning when Optional updates are requested but not Security updates' { + $PropertiesToTest = @{ + IsSingleInstance = 'Yes' + Notifications = 'Disabled' + Source = 'WindowsUpdate' + Category = 'Optional' + UpdateNow = $True + } + Test-TargetResourceProperties @PropertiesToTest + + Assert-MockCalled -CommandName Write-Verbose -Times 1 -Exactly -Scope It + } + + It 'Throws an exception when passed WSUS as a source' { + $PropertiesToTest = @{ + IsSingleInstance = 'Yes' + Category = 'Security' + Notifications = 'Disabled' + Source = 'WSUS' + } + {Test-TargetResourceProperties @PropertiesToTest} | Should Throw + } + } + + Describe "$($Global:DSCResourceName)\Get-WuaAuNotificationLevelInt" { + It 'Gets int for notification level of Not Configured' { + Get-WuaAuNotificationLevelInt -notificationLevel 'Not Configured' | Should be 0 + } + It 'Gets int for notification level of Disabled' { + Get-WuaAuNotificationLevelInt -notificationLevel 'Disabled' | Should be 1 + } + It 'Gets int for notification level of Notify before download' { + Get-WuaAuNotificationLevelInt -notificationLevel 'Notify before download' | Should be 2 + } + It 'Gets int for notification level of Notify before installation' { + Get-WuaAuNotificationLevelInt -notificationLevel 'Notify before installation' | Should be 3 + } + It 'Gets int for notification level of Scheduled Installation' { + Get-WuaAuNotificationLevelInt -notificationLevel 'Scheduled Installation' | Should be 4 + } + It 'Gets int for notification level of ScheduledInstallation' { + Get-WuaAuNotificationLevelInt -notificationLevel 'ScheduledInstallation' | Should be 4 + } + It 'Gets int for notification level when nothing is provided' { + { Get-WuaAuNotificationLevelInt } | Should Throw + } + } } #endregion From 91b39275c4ba0a927aba1370eb0a40a0f9f307c6 Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Wed, 12 Jul 2017 11:03:43 -0700 Subject: [PATCH 2/3] Add missing release notes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 42ae506..013bf76 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Please check out common DSC Resources ### Unreleased +* xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key + ### 2.6.0.0 * Converted appveyor.yml to install Pester from PSGallery instead of from From 2e3e68e9f91fe627c215b797a4b627e3e4f348b8 Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Wed, 12 Jul 2017 11:08:25 -0700 Subject: [PATCH 3/3] Releasing version 2.7.0.0 --- README.md | 2 ++ xWindowsUpdate.psd1 | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 013bf76..6136e0b 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Please check out common DSC Resources ### Unreleased +### 2.7.0.0 + * xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key ### 2.6.0.0 diff --git a/xWindowsUpdate.psd1 b/xWindowsUpdate.psd1 index fa410ec..f0693d3 100644 --- a/xWindowsUpdate.psd1 +++ b/xWindowsUpdate.psd1 @@ -1,6 +1,6 @@ @{ # Version number of this module. -ModuleVersion = '2.6.0.0' +ModuleVersion = '2.7.0.0' # ID used to uniquely identify this module GUID = 'a9cba250-ea73-4d82-b31b-7e58cc50ffd1' @@ -47,12 +47,7 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '* Converted appveyor.yml to install Pester from PSGallery instead of from - Chocolatey. -* Fixed PSScriptAnalyzer issues. -* Fixed common test breaks (markdown style, and example style). -* Added CodeCov.io reporting -* Deprecated xMicrosoftUpdate as it"s functionality is replaced by xWindowsUpdateAgent + ReleaseNotes = '* xWindowsUpdateAgent: Fix Get-TargetResource returning incorrect key ' @@ -62,3 +57,4 @@ PrivateData = @{ } +