From 514e632804d00b8886087ff71fc9b4c423f6497b Mon Sep 17 00:00:00 2001 From: Craig Tolley Date: Tue, 26 May 2020 15:44:37 +0100 Subject: [PATCH 1/2] Add IGNORE option to UpstreamServerName --- CHANGELOG.md | 1 + ReadMe.md | 2 +- .../Unit/MSFT_UpdateServicesServer.tests.ps1 | 31 ++++++++++++++++++- .../MSFT_UpdateServicesServer.psm1 | 3 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42319b9..7c05ee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated inital offline package sync WSUS.cab. +- Added IGNORE option for UpstreamServerName to prevent it being changed when SCCM is managing the upstream source ## [1.2.0] - 2020-05-18 diff --git a/ReadMe.md b/ReadMe.md index a2ccdcc..6cc24f9 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -93,7 +93,7 @@ Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2. * **SQLServer**: SQL Server for the WSUS database, omit for Windows Internal Database. * **ContentDir**: Folder for WSUS update files. * **UpdateImprovementProgram**: Join the Microsoft Update Improvement Program. -* **UpstreamServerName**: Upstream WSUS server, omit for Microsoft Update. +* **UpstreamServerName**: Upstream WSUS server, omit for Microsoft Update. Set to 'IGNORE' to prevent changes being made, for example in a SCCM environment * **UpstreamServerPort**: Port of upstream WSUS server. * **UpstreamServerSSL**: Use SSL with upstream WSUS server. * **UpstreamServerReplica**: Replica of upstream WSUS server. diff --git a/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 b/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 index d9814f9..0bc28bd 100644 --- a/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 +++ b/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 @@ -214,7 +214,36 @@ try } } - } + Context "upstream server difference is ignored" { + + $DSCTestValues.Remove('UpstreamServerName') + $DSCTestValues.Add('UpstreamServerName', 'IGNORE') + + Mock -CommandName Get-TargetResource -MockWith { + $GetValues = $DSCTestValues + $GetValues.Remove('UpstreamServerName') + $GetValues.Add('UpstreamServerName', 'SomeOtherServer') + $GetValues + } -Verifiable + + $script:result = $null + + It "calling test with change to UpstreamServerName should not throw" { + { $script:result = Test-TargetResource @DSCTestValues -verbose } | Should not throw + } + + It "result should be true, even when UpstreamServerName is different" { + $script:result | Should be $true + } + + It 'mocks were called' { + Assert-VerifiableMock + } + + $DSCTestValues.Remove('UpstreamServerName') + $DSCTestValues.Add('UpstreamServerName', 'UpstreamServer') + } + } #endregion #region Function Set-TargetResource diff --git a/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 b/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 index 8759fa5..cc58354 100644 --- a/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 +++ b/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 @@ -849,7 +849,8 @@ function Test-TargetResource } # Test Upstream Server - if ($Wsus.UpstreamServerName -ne $UpstreamServerName) + + if ($Wsus.UpstreamServerName -ne $UpstreamServerName -and $UpstreamServerName -ne "IGNORE") { Write-Verbose -Message $script:localizedData.UpstreamNameTestFailed $result = $false From 70d15f2aa73c433edff6a1aececb76b1daadda54 Mon Sep 17 00:00:00 2001 From: Craig Tolley Date: Tue, 26 May 2020 16:11:47 +0100 Subject: [PATCH 2/2] Remove tabs --- .../Unit/MSFT_UpdateServicesServer.tests.ps1 | 28 +++++++++---------- .../MSFT_UpdateServicesServer.psm1 | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 b/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 index 0bc28bd..113c686 100644 --- a/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 +++ b/Tests/Unit/MSFT_UpdateServicesServer.tests.ps1 @@ -221,27 +221,27 @@ try Mock -CommandName Get-TargetResource -MockWith { $GetValues = $DSCTestValues - $GetValues.Remove('UpstreamServerName') - $GetValues.Add('UpstreamServerName', 'SomeOtherServer') - $GetValues + $GetValues.Remove('UpstreamServerName') + $GetValues.Add('UpstreamServerName', 'SomeOtherServer') + $GetValues } -Verifiable $script:result = $null - It "calling test with change to UpstreamServerName should not throw" { - { $script:result = Test-TargetResource @DSCTestValues -verbose } | Should not throw - } + It "calling test with change to UpstreamServerName should not throw" { + { $script:result = Test-TargetResource @DSCTestValues -verbose } | Should not throw + } - It "result should be true, even when UpstreamServerName is different" { - $script:result | Should be $true - } + It "result should be true, even when UpstreamServerName is different" { + $script:result | Should be $true + } - It 'mocks were called' { - Assert-VerifiableMock - } + It 'mocks were called' { + Assert-VerifiableMock + } - $DSCTestValues.Remove('UpstreamServerName') - $DSCTestValues.Add('UpstreamServerName', 'UpstreamServer') + $DSCTestValues.Remove('UpstreamServerName') + $DSCTestValues.Add('UpstreamServerName', 'UpstreamServer') } } #endregion diff --git a/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 b/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 index cc58354..958b36c 100644 --- a/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 +++ b/source/DSCResources/MSFT_UpdateServicesServer/MSFT_UpdateServicesServer.psm1 @@ -850,7 +850,7 @@ function Test-TargetResource # Test Upstream Server - if ($Wsus.UpstreamServerName -ne $UpstreamServerName -and $UpstreamServerName -ne "IGNORE") + if ($Wsus.UpstreamServerName -ne $UpstreamServerName -and $UpstreamServerName -ne "IGNORE") { Write-Verbose -Message $script:localizedData.UpstreamNameTestFailed $result = $false