From 550f3000b70f96eac897f81fc6e42ea3369546e1 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 30 Apr 2019 20:53:17 +0100 Subject: [PATCH 01/24] Fix Example Configuration Names --- ...> Sample_MsiPackage_UninstallPackageFromHttps.ps1} | 0 Examples/Sample_Script.ps1 | 2 +- Examples/Sample_ServiceSet_BuiltInAccount.ps1 | 2 +- Examples/Sample_ServiceSet_StartServices.ps1 | 2 +- Examples/Sample_User_CreateUser.ps1 | 2 +- Examples/Sample_User_Generic.ps1 | 11 ++--------- Examples/Sample_WindowsFeature.ps1 | 2 +- Examples/Sample_WindowsFeatureSet_Install.ps1 | 2 +- Examples/Sample_WindowsFeatureSet_Uninstall.ps1 | 2 +- Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 | 2 +- Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 | 2 +- 11 files changed, 11 insertions(+), 18 deletions(-) rename Examples/{Sample_MsiPackage_UnstallPackageFromHttps.ps1 => Sample_MsiPackage_UninstallPackageFromHttps.ps1} (100%) diff --git a/Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 b/Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 similarity index 100% rename from Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 rename to Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 diff --git a/Examples/Sample_Script.ps1 b/Examples/Sample_Script.ps1 index caea309..f5e8de3 100644 --- a/Examples/Sample_Script.ps1 +++ b/Examples/Sample_Script.ps1 @@ -8,7 +8,7 @@ .PARAMETER FileContent The content to set for the new file. #> -Configuration ScriptExample { +Configuration Sample_Script { [CmdletBinding()] param ( diff --git a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 index d66b093..6d93750 100644 --- a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 +++ b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 @@ -3,7 +3,7 @@ Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the built-in account LocalService. #> -Configuration ServiceSetBuiltInAccountExample +Configuration Sample_ServiceSet_BuiltInAccount { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_ServiceSet_StartServices.ps1 b/Examples/Sample_ServiceSet_StartServices.ps1 index fb8dfee..62172ea 100644 --- a/Examples/Sample_ServiceSet_StartServices.ps1 +++ b/Examples/Sample_ServiceSet_StartServices.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Ensures that the DHCP Client and Windows Firewall services are running. #> -Configuration ServiceSetStartExample +Configuration Sample_ServiceSet_StartServices { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index b2aae55..5d45487 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,4 +1,4 @@ -Configuration UserExample +Configuration Sample_User_CreateUser { param ( [System.Management.Automation.PSCredential] diff --git a/Examples/Sample_User_Generic.ps1 b/Examples/Sample_User_Generic.ps1 index 17cd506..6bbe17c 100644 --- a/Examples/Sample_User_Generic.ps1 +++ b/Examples/Sample_User_Generic.ps1 @@ -1,11 +1,4 @@ -param -( - [Parameter(Mandatory)] - [System.String] - $ConfigurationName -) - -<# +<# Create a custom configuration by passing in whatever values you need. $Password is the only param that is required since it must be a PSCredential object. @@ -14,7 +7,7 @@ are optional. #> -Configuration $ConfigurationName +Configuration Sample_User_Generic { param ( diff --git a/Examples/Sample_WindowsFeature.ps1 b/Examples/Sample_WindowsFeature.ps1 index 77d0352..6946afe 100644 --- a/Examples/Sample_WindowsFeature.ps1 +++ b/Examples/Sample_WindowsFeature.ps1 @@ -30,7 +30,7 @@ in this configuration file currently. #> -Configuration 'Install_Feature_Telnet_Client' +Configuration Sample_WindowsFeature { param ( diff --git a/Examples/Sample_WindowsFeatureSet_Install.ps1 b/Examples/Sample_WindowsFeatureSet_Install.ps1 index 9c82264..5a9698c 100644 --- a/Examples/Sample_WindowsFeatureSet_Install.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Install.ps1 @@ -3,7 +3,7 @@ Installs the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Install { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 index 7e25124..2da010d 100644 --- a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 @@ -3,7 +3,7 @@ Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Uninstall { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 index 25f6f7b..e323aab 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 @@ -3,7 +3,7 @@ Disables the Windows optional features TelnetClient and LegacyComponents and removes all files associated with these features. #> -Configuration WindowsOptionalFeatureSet_Disable +Configuration Sample_WindowsOptionalFeatureSet_Disable { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 index 13a84c6..4712ed5 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 @@ -4,7 +4,7 @@ Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path 'C:\LogPath\Log.txt'. #> -Configuration WindowsOptionalFeatureSet_Enable +Configuration Sample_WindowsOptionalFeatureSet_Enable { Import-DscResource -ModuleName 'PSDscResources' From 9b36261051ab23254a44fa1e521fd52de97854ad Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 30 Apr 2019 21:03:23 +0100 Subject: [PATCH 02/24] Add MetaTestOptIn file --- .MetaTestOptIn.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .MetaTestOptIn.json diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json new file mode 100644 index 0000000..1dc8c7b --- /dev/null +++ b/.MetaTestOptIn.json @@ -0,0 +1,3 @@ +[ + "Common Tests - Validate Example Files" +] From 51d75eb0dde002700b2b85517f5404bd6c285a5c Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:22:56 +0100 Subject: [PATCH 03/24] Sample_User_CreateUser changes: - Rename PasswordCredential for opt-in tests - Add Mandatory parameter and ValidateNotNullorEmpty - Add Node localhost - Fix formatting --- Examples/Sample_User_CreateUser.ps1 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index 5d45487..4f7bd87 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,16 +1,22 @@ Configuration Sample_User_CreateUser { - param ( + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullorEmpty()] [System.Management.Automation.PSCredential] - $PasswordCredential + $Credential ) Import-DscResource -ModuleName PSDscResources - User UserExample + Node localhost { - Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" - UserName = 'SomeUserName' - Password = $PasswordCredential # This needs to be a credential object + User UserExample + { + Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" + UserName = 'SomeUserName' + Password = $Credential # This needs to be a credential object + } } } From 120d661776f79ddb86df2713189b68258dc70d89 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:25:08 +0100 Subject: [PATCH 04/24] Sample_WindowsPackageCab changes for example tests - Remove configuration call - Fix formatting - Add Node localhost --- Examples/Sample_WindowsPackageCab.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Examples/Sample_WindowsPackageCab.ps1 b/Examples/Sample_WindowsPackageCab.ps1 index 49af41f..ac1dab5 100644 --- a/Examples/Sample_WindowsPackageCab.ps1 +++ b/Examples/Sample_WindowsPackageCab.ps1 @@ -37,13 +37,14 @@ Configuration Sample_WindowsPackageCab Import-DscResource -ModuleName 'PSDscResources' - WindowsPackageCab WindowsPackageCab1 + Node localhost { - Name = $Name - Ensure = 'Present' - SourcePath = $SourcePath - LogPath = $LogPath + WindowsPackageCab WindowsPackageCab1 + { + Name = $Name + Ensure = 'Present' + SourcePath = $SourcePath + LogPath = $LogPath + } } } - -Sample_WindowsPackageCab From 9f7069afa7f0941b4d1c922637748fccb48e7545 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:37:36 +0100 Subject: [PATCH 05/24] Sample_WindowsOptionalFeature Changes - Add ValidateNotNullOrEmpty to mandatory parameters - Add Node localhost - Remove configuration call - Fix formatting - Rename incorrect resource name --- Examples/Sample_WindowsOptionalFeature.ps1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Examples/Sample_WindowsOptionalFeature.ps1 b/Examples/Sample_WindowsOptionalFeature.ps1 index f2895d4..db11f74 100644 --- a/Examples/Sample_WindowsOptionalFeature.ps1 +++ b/Examples/Sample_WindowsOptionalFeature.ps1 @@ -17,22 +17,25 @@ Configuration Sample_WindowsOptionalFeature param ( [Parameter (Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $FeatureName, [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $LogPath ) Import-DscResource -ModuleName 'PSDscResources' - WindowsOptionalFeature TelnetClient + Node localhost { - Name = $FeatureName - Ensure = 'Present' - LogPath = $LogPath + WindowsOptionalFeature FeatureExample + { + Name = $FeatureName + Ensure = 'Present' + LogPath = $LogPath + } } } - -Sample_WindowsOptionalFeature From 7d7858b3c8961430bd0cc5bb86eef8a1b2446684 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 11:36:58 +0100 Subject: [PATCH 06/24] Fix Pester 'Multiple Script Modules' error --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 6459b9c..42972fa 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -8,6 +8,12 @@ $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' + +# Remove module if it is already imported before re-import +If (Get-Module $script:resourceSetHelperFilePath) +{ + Remove-Module $script:resourceSetHelperFilePath +} Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' { From a172c3860c9fc104c4f9cce0de9b1f5e45052278 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 15:21:13 +0100 Subject: [PATCH 07/24] Add resourceSetHelpName var --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 42972fa..2e4a583 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,15 +4,16 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$resourceSetHelperName = 'ResourceSetHelper.psm1' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName # Remove module if it is already imported before re-import -If (Get-Module $script:resourceSetHelperFilePath) +If (Get-Module $resourceSetHelperName) { - Remove-Module $script:resourceSetHelperFilePath + Remove-Module $resourceSetHelperName } Import-Module -Name $script:resourceSetHelperFilePath From ec12d5c2edd8d981983783292d79258811f79b11 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 18:05:53 +0100 Subject: [PATCH 08/24] Fix resourceSetHelpName var --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 2e4a583..b5512b7 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,11 +4,11 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' -$resourceSetHelperName = 'ResourceSetHelper.psm1' +$resourceSetHelperName = 'ResourceSetHelper' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' # Remove module if it is already imported before re-import If (Get-Module $resourceSetHelperName) From 1c4bd93c4a1b778c879f8685b6bb53e3952c7a57 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 18:15:29 +0100 Subject: [PATCH 09/24] Force integration test re-run --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index b5512b7..657fcc3 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -10,7 +10,7 @@ $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Paren $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' -# Remove module if it is already imported before re-import +# Remove module if it is already imported before re-import. If (Get-Module $resourceSetHelperName) { Remove-Module $resourceSetHelperName From fd81a23255b9ea06fae27babc58b8e2164725a56 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 21:16:54 +0100 Subject: [PATCH 10/24] resourceSetHelpFilePath fix --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 657fcc3..853b2c9 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -8,7 +8,7 @@ $resourceSetHelperName = 'ResourceSetHelper' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') # Remove module if it is already imported before re-import. If (Get-Module $resourceSetHelperName) From 8924be9ce3a5bf61ca9afb7f5bde5886dd0eaaa1 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 21:55:38 +0100 Subject: [PATCH 11/24] Test: Disable import-module ResourceSetHelper --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 853b2c9..ee6f2ce 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -11,11 +11,11 @@ $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') # Remove module if it is already imported before re-import. -If (Get-Module $resourceSetHelperName) -{ - Remove-Module $resourceSetHelperName -} -Import-Module -Name $script:resourceSetHelperFilePath +#If (Get-Module $resourceSetHelperName) +#{ +# Remove-Module $resourceSetHelperName +#} +#Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' { Describe 'ResourceSetHelper\New-ResourceSetCommonParameterString' { From 31332dfaaf8e543902d5909da94d23afc9e5da2c Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Mon, 3 Jun 2019 21:34:46 +0100 Subject: [PATCH 12/24] Merge Dev (#1) * Test-Is NanoServer speed improvement Replace Get-ComputerInfo with Registry Value Test * update README.md * Add check for ServerLevels Reg Key for Non-Server * Update CommonResourceHelper.Tests * Moved comment to unreleased * Make requested changes * Remove whitespace * README.md markdownlint fixes * README markdownlint fix * README branch detail format change To match other DSC modules * Update README * Fix Example dir BOM files * Fix Tests\Integration dir BOM files * Fix Tests\Unit dir BOM files * Fix PSDscResources dir BOM files * Fix Tests\TestHelpers dir BOM files * Add Script & Module Common Tests to MetaTestOptIn * Update README * Revert "Fix msi package tests" * Fix MsiPackage tests... for real this time * Fix MsiPackage tests... for real this time * Fix MsiPackage tests... for real this time - Post Review #1 * Fix MsiPackage tests... for real this time - Post Review #1 * Update CommonResourceHelper.psm1 * Update README * Update README.md * Update README.md --- .MetaTestOptIn.json | 4 + DscResources/CommonResourceHelper.psm1 | 31 +- DscResources/GroupSet/GroupSet.psd1 | 2 +- DscResources/GroupSet/GroupSet.schema.psm1 | 2 +- DscResources/MSFT_Archive/MSFT_Archive.psm1 | 2 +- .../en-US/MSFT_Archive.strings.psd1 | 2 +- .../MSFT_EnvironmentResource.strings.psd1 | 2 +- .../MSFT_MsiPackage/MSFT_MsiPackage.psm1 | 4 +- .../en-US/MSFT_MsiPackage.strings.psd1 | 2 +- .../en-US/MSFT_ScriptResource.strings.psd1 | 2 +- .../en-US/MSFT_UserResource.strings.psd1 | 2 +- .../en-US/MSFT_WindowsFeature.strings.psd1 | 2 +- .../MSFT_WindowsPackageCab.psm1 | 2 +- .../en-US/MSFT_WindowsPackageCab.schema.mfl | 2 +- .../en-US/MSFT_WindowsPackageCab.strings.psd1 | 2 +- DscResources/ProcessSet/ProcessSet.psd1 | 2 +- .../ProcessSet/ProcessSet.schema.psm1 | 2 +- DscResources/ResourceSetHelper.psm1 | 2 +- DscResources/ServiceSet/ServiceSet.psd1 | 2 +- .../ServiceSet/ServiceSet.schema.psm1 | 2 +- .../WindowsFeatureSet/WindowsFeatureSet.psd1 | 2 +- .../WindowsFeatureSet.schema.psm1 | 2 +- .../WindowsOptionalFeatureSet.psd1 | 2 +- .../WindowsOptionalFeatureSet.schema.psm1 | 2 +- ...ve_ExpandArchiveNoValidationCredential.ps1 | 2 +- .../Sample_Archive_RemoveArchiveChecksum.ps1 | 2 +- ...mple_Archive_RemoveArchiveNoValidation.ps1 | 2 +- ...mple_Environment_CreateNonPathVariable.ps1 | 2 +- .../Sample_Environment_CreatePathVariable.ps1 | 2 +- Examples/Sample_Environment_Remove.ps1 | 2 +- Examples/Sample_GroupSet_AddMembers.ps1 | 2 +- Examples/Sample_Group_RemoveMembers.ps1 | 2 +- Examples/Sample_Group_SetMembers.ps1 | 2 +- Examples/Sample_ProcessSet_Start.ps1 | 2 +- Examples/Sample_ProcessSet_Stop.ps1 | 2 +- Examples/Sample_RegistryResource_AddKey.ps1 | 2 +- ...mple_RegistryResource_AddOrModifyValue.ps1 | 2 +- .../Sample_RegistryResource_RemoveKey.ps1 | 2 +- .../Sample_RegistryResource_RemoveValue.ps1 | 2 +- Examples/Sample_Script.ps1 | 2 +- Examples/Sample_ServiceSet_BuiltInAccount.ps1 | 2 +- Examples/Sample_ServiceSet_StartServices.ps1 | 2 +- Examples/Sample_User_CreateUser.ps1 | 2 +- Examples/Sample_User_Generic.ps1 | 2 +- Examples/Sample_WindowsFeature.ps1 | 2 +- Examples/Sample_WindowsFeatureSet_Install.ps1 | 2 +- .../Sample_WindowsFeatureSet_Uninstall.ps1 | 2 +- Examples/Sample_WindowsOptionalFeature.ps1 | 2 +- ...mple_WindowsOptionalFeatureSet_Disable.ps1 | 2 +- ...ample_WindowsOptionalFeatureSet_Enable.ps1 | 2 +- Examples/Sample_WindowsPackageCab.ps1 | 2 +- README.md | 46 +- .../GroupSet.Integration.Tests.ps1 | 2 +- Tests/Integration/GroupSet.config.ps1 | 2 +- .../MSFT_Archive.EndToEnd.Tests.ps1 | 2 +- .../MSFT_Archive_CredentialOnly.config.ps1 | 2 +- ...SFT_Archive_ValidateAndChecksum.config.ps1 | 2 +- .../MSFT_Archive_ValidateOnly.config.ps1 | 2 +- ...SFT_EnvironmentResource.EndToEnd.Tests.ps1 | 2 +- ..._EnvironmentResource.Integration.Tests.ps1 | 2 +- .../MSFT_EnvironmentResource.config.ps1 | 2 +- .../MSFT_GroupResource.Integration.Tests.ps1 | 2 +- .../MSFT_GroupResource_Members.config.ps1 | 2 +- ...esource_MembersToIncludeExclude.config.ps1 | 2 +- .../MSFT_GroupResource_NoMembers.config.ps1 | 2 +- .../MSFT_MsiPackage.EndToEnd.Tests.ps1 | 1019 +++++++++-------- .../MSFT_MsiPackage.Integration.Tests.ps1 | 49 +- Tests/Integration/MSFT_MsiPackage_LogPath.ps1 | 2 +- .../MSFT_MsiPackage_NoOptionalParameters.ps1 | 2 +- .../MSFT_RegistryResource.EndToEnd.Tests.ps1 | 2 +- ...SFT_RegistryResource.Integration.Tests.ps1 | 2 +- ...RegistryResource_KeyAndNameOnly.config.ps1 | 2 +- ...egistryResource_WithDataAndType.config.ps1 | 2 +- .../MSFT_ScriptResource.Integration.Tests.ps1 | 2 +- ...SFT_ScriptResource_NoCredential.config.ps1 | 2 +- ...T_ScriptResource_WithCredential.config.ps1 | 2 +- .../Integration/MSFT_UserResource.config.ps1 | 2 +- .../MSFT_WindowsFeature.Integration.Tests.ps1 | 2 +- .../MSFT_WindowsFeature.config.ps1 | 2 +- ...ndowsOptionalFeature.Integration.Tests.ps1 | 2 +- .../MSFT_WindowsOptionalFeature.config.ps1 | 2 +- ...FT_WindowsPackageCab.Integration.Tests.ps1 | 2 +- .../MSFT_WindowsPackageCab.config.ps1 | 2 +- .../MSFT_WindowsProcess.Integration.Tests.ps1 | 2 +- ...SFT_WindowsProcess_NoCredential.config.ps1 | 2 +- ...T_WindowsProcess_WithCredential.config.ps1 | 2 +- .../ProcessSet.Integration.Tests.ps1 | 2 +- Tests/Integration/ProcessSet.config.ps1 | 2 +- .../ServiceSet.Integration.Tests.ps1 | 2 +- ...viceSet_AllExceptBuiltInAccount.config.ps1 | 2 +- .../ServiceSet_BuiltInAccountOnly.config.ps1 | 2 +- .../WindowsFeatureSet.Integration.Tests.ps1 | 2 +- .../Integration/WindowsFeatureSet.config.ps1 | 2 +- ...wsOptionalFeatureSet.Integration.Tests.ps1 | 2 +- .../WindowsOptionalFeatureSet.config.ps1 | 2 +- Tests/TestHelpers/CommonTestHelper.psm1 | 156 ++- Tests/TestHelpers/DSCTestService.cs | 2 +- Tests/TestHelpers/DSCTestServiceNew.cs | 2 +- .../TestHelpers/MSFT_Archive.TestHelper.psm1 | 2 +- .../MSFT_GroupResource.TestHelper.psm1 | 2 +- .../MSFT_MsiPackageResource.TestHelper.psm1 | 190 ++- .../MSFT_UserResource.TestHelper.psm1 | 2 +- Tests/TestHelpers/WMF5Dot1Installation.psm1 | 2 +- .../TestHelpers/WindowsProcessTestProcess.cs | 2 +- Tests/Unit/CommonResourceHelper.Tests.ps1 | 122 +- Tests/Unit/MSFT_EnvironmentResource.Tests.ps1 | 2 +- Tests/Unit/MSFT_MsiPackage.Tests.ps1 | 44 +- Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 | 2 +- Tests/Unit/MSFT_WindowsProcess.Tests.ps1 | 2 +- Tests/Unit/ResourceSetHelper.Tests.ps1 | 2 +- 110 files changed, 953 insertions(+), 912 deletions(-) create mode 100644 .MetaTestOptIn.json diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json new file mode 100644 index 0000000..f6b4bc5 --- /dev/null +++ b/.MetaTestOptIn.json @@ -0,0 +1,4 @@ +[ + "Common Tests - Validate Module Files", + "Common Tests - Validate Script Files" +] diff --git a/DscResources/CommonResourceHelper.psm1 b/DscResources/CommonResourceHelper.psm1 index f1f9d3a..0299b7d 100644 --- a/DscResources/CommonResourceHelper.psm1 +++ b/DscResources/CommonResourceHelper.psm1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Tests if the current machine is a Nano server. #> @@ -8,23 +8,26 @@ function Test-IsNanoServer [CmdletBinding()] param () - $isNanoServer = $false - - if (Test-CommandExists -Name 'Get-ComputerInfo') + $serverLevelsRegKey = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels' + + if (Test-Path -Path $serverLevelsRegKey) { - $computerInfo = Get-ComputerInfo -ErrorAction 'SilentlyContinue' - - if ($null -ne $computerInfo) + $serverLevels = Get-ItemProperty -Path $serverLevelsRegKey + + if ($serverLevels.NanoServer -eq 1) { - $computerIsServer = 'Server' -ieq $computerInfo.OsProductType - - if ($computerIsServer) - { - $isNanoServer = 'NanoServer' -ieq $computerInfo.OsServerLevel - } + $isNanoServer = $true + } + else + { + $isNanoServer = $false } } - + else + { + $isNanoServer = $false + } + return $isNanoServer } diff --git a/DscResources/GroupSet/GroupSet.psd1 b/DscResources/GroupSet/GroupSet.psd1 index 1d19475..22c463b 100644 --- a/DscResources/GroupSet/GroupSet.psd1 +++ b/DscResources/GroupSet/GroupSet.psd1 @@ -1,4 +1,4 @@ -@{ +@{ # Script module or binary module file associated with this manifest. RootModule = 'GroupSet.schema.psm1' diff --git a/DscResources/GroupSet/GroupSet.schema.psm1 b/DscResources/GroupSet/GroupSet.schema.psm1 index d4b1c96..c82e64f 100644 --- a/DscResources/GroupSet/GroupSet.schema.psm1 +++ b/DscResources/GroupSet/GroupSet.schema.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock diff --git a/DscResources/MSFT_Archive/MSFT_Archive.psm1 b/DscResources/MSFT_Archive/MSFT_Archive.psm1 index f477867..27eb19a 100644 --- a/DscResources/MSFT_Archive/MSFT_Archive.psm1 +++ b/DscResources/MSFT_Archive/MSFT_Archive.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' <# diff --git a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 index be6af64..5f2eade 100644 --- a/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 +++ b/DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1 @@ -1,4 +1,4 @@ -# Localized MSFT_Archive.strings.psd1 +# Localized MSFT_Archive.strings.psd1 ConvertFrom-StringData @' RetrievingArchiveState = Retrieving the state of the archive with path "{0}" and destination "{1}"... diff --git a/DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.strings.psd1 b/DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.strings.psd1 index 496cc10..9ff1fef 100644 --- a/DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.strings.psd1 +++ b/DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for MSFT_EnvironmentResource +# Localized resources for MSFT_EnvironmentResource ConvertFrom-StringData @' ArgumentTooLong = Argument is too long. diff --git a/DscResources/MSFT_MsiPackage/MSFT_MsiPackage.psm1 b/DscResources/MSFT_MsiPackage/MSFT_MsiPackage.psm1 index 145ce96..fdc7f97 100644 --- a/DscResources/MSFT_MsiPackage/MSFT_MsiPackage.psm1 +++ b/DscResources/MSFT_MsiPackage/MSFT_MsiPackage.psm1 @@ -1,4 +1,4 @@ -# Suppress Global Vars PSSA Error because $global:DSCMachineStatus must be allowed +# Suppress Global Vars PSSA Error because $global:DSCMachineStatus must be allowed [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] param() @@ -269,7 +269,7 @@ function Set-TargetResource } finally { - if ($null -ne $responseStream) + if ((Test-Path -Path variable:responseStream) -and ($null -ne $responseStream)) { Close-Stream -Stream $responseStream } diff --git a/DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.strings.psd1 b/DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.strings.psd1 index ecb56be..9f33d00 100644 --- a/DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.strings.psd1 +++ b/DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for MSFT_MsiPackage +# Localized resources for MSFT_MsiPackage ConvertFrom-StringData @' CheckingFileHash = Checking file '{0}' for expected {2} hash value of {1} diff --git a/DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.strings.psd1 b/DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.strings.psd1 index 8a25d8d..241d133 100644 --- a/DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.strings.psd1 +++ b/DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.strings.psd1 @@ -1,4 +1,4 @@ -# Localized MSFT_ScriptResource.strings.psd1 +# Localized MSFT_ScriptResource.strings.psd1 ConvertFrom-StringData @' GetTargetResourceStartVerboseMessage = Begin executing get script. diff --git a/DscResources/MSFT_UserResource/en-US/MSFT_UserResource.strings.psd1 b/DscResources/MSFT_UserResource/en-US/MSFT_UserResource.strings.psd1 index 8381ba4..89860ac 100644 --- a/DscResources/MSFT_UserResource/en-US/MSFT_UserResource.strings.psd1 +++ b/DscResources/MSFT_UserResource/en-US/MSFT_UserResource.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for User +# Localized resources for User ConvertFrom-StringData @' UserWithName = User: {0} diff --git a/DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.strings.psd1 b/DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.strings.psd1 index f36ee5a..3a78e88 100644 --- a/DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.strings.psd1 +++ b/DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.strings.psd1 @@ -1,4 +1,4 @@ -# Localized strings for MSFT_WindowsFeature.psd1 +# Localized strings for MSFT_WindowsFeature.psd1 ConvertFrom-StringData @' FeatureNotFoundError = The requested feature {0} could not be found on the target machine. diff --git a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 index 111e483..777450f 100644 --- a/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 +++ b/DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) ` diff --git a/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.schema.mfl b/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.schema.mfl index ce59b5a..82f7e35 100644 --- a/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.schema.mfl +++ b/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.schema.mfl @@ -1,4 +1,4 @@ -[Description("This resource is used to install or uninstall a package from a windows cabinet (cab) file.") : Amended,AMENDMENT, LOCALE("MS_409")] +[Description("This resource is used to install or uninstall a package from a windows cabinet (cab) file.") : Amended,AMENDMENT, LOCALE("MS_409")] class MSFT_WindowsPackageCab : OMI_BaseResource { [Key, Description("The name of the package to install or uninstall.") : Amended] String Name; diff --git a/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.strings.psd1 b/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.strings.psd1 index 2d5fe9b..3085420 100644 --- a/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.strings.psd1 +++ b/DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.strings.psd1 @@ -1,4 +1,4 @@ -# Localized resources for WindowsPackageCab +# Localized resources for WindowsPackageCab ConvertFrom-StringData @' RetrievingPackage = Retrieving information for the package {0} diff --git a/DscResources/ProcessSet/ProcessSet.psd1 b/DscResources/ProcessSet/ProcessSet.psd1 index 4075e4c..518464d 100644 --- a/DscResources/ProcessSet/ProcessSet.psd1 +++ b/DscResources/ProcessSet/ProcessSet.psd1 @@ -1,4 +1,4 @@ -@{ +@{ # Script module or binary module file associated with this manifest. RootModule = 'ProcessSet.schema.psm1' diff --git a/DscResources/ProcessSet/ProcessSet.schema.psm1 b/DscResources/ProcessSet/ProcessSet.schema.psm1 index 4f25592..42435c0 100644 --- a/DscResources/ProcessSet/ProcessSet.schema.psm1 +++ b/DscResources/ProcessSet/ProcessSet.schema.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock diff --git a/DscResources/ResourceSetHelper.psm1 b/DscResources/ResourceSetHelper.psm1 index ee80714..6b9232b 100644 --- a/DscResources/ResourceSetHelper.psm1 +++ b/DscResources/ResourceSetHelper.psm1 @@ -1,4 +1,4 @@ -# This module should not write any verbose or error messages unless a localization file for it is added +# This module should not write any verbose or error messages unless a localization file for it is added $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' diff --git a/DscResources/ServiceSet/ServiceSet.psd1 b/DscResources/ServiceSet/ServiceSet.psd1 index 68f4796..3578a65 100644 --- a/DscResources/ServiceSet/ServiceSet.psd1 +++ b/DscResources/ServiceSet/ServiceSet.psd1 @@ -1,4 +1,4 @@ -@{ +@{ # Script module or binary module file associated with this manifest. RootModule = 'ServiceSet.schema.psm1' diff --git a/DscResources/ServiceSet/ServiceSet.schema.psm1 b/DscResources/ServiceSet/ServiceSet.schema.psm1 index b501f4c..3ae17cc 100644 --- a/DscResources/ServiceSet/ServiceSet.schema.psm1 +++ b/DscResources/ServiceSet/ServiceSet.schema.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock diff --git a/DscResources/WindowsFeatureSet/WindowsFeatureSet.psd1 b/DscResources/WindowsFeatureSet/WindowsFeatureSet.psd1 index a0a3694..53b27e2 100644 --- a/DscResources/WindowsFeatureSet/WindowsFeatureSet.psd1 +++ b/DscResources/WindowsFeatureSet/WindowsFeatureSet.psd1 @@ -1,4 +1,4 @@ -@{ +@{ # Script module or binary module file associated with this manifest. RootModule = 'WindowsFeatureSet.schema.psm1' diff --git a/DscResources/WindowsFeatureSet/WindowsFeatureSet.schema.psm1 b/DscResources/WindowsFeatureSet/WindowsFeatureSet.schema.psm1 index 3e8f20c..c96f468 100644 --- a/DscResources/WindowsFeatureSet/WindowsFeatureSet.schema.psm1 +++ b/DscResources/WindowsFeatureSet/WindowsFeatureSet.schema.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock diff --git a/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.psd1 b/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.psd1 index f9d27d2..2e95b92 100644 --- a/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.psd1 +++ b/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.psd1 @@ -1,4 +1,4 @@ -@{ +@{ # Script module or binary module file associated with this manifest. RootModule = 'WindowsOptionalFeatureSet.schema.psm1' diff --git a/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.schema.psm1 b/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.schema.psm1 index df15612..f430804 100644 --- a/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.schema.psm1 +++ b/DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.schema.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock diff --git a/Examples/Sample_Archive_ExpandArchiveNoValidationCredential.ps1 b/Examples/Sample_Archive_ExpandArchiveNoValidationCredential.ps1 index c1572df..060e53c 100644 --- a/Examples/Sample_Archive_ExpandArchiveNoValidationCredential.ps1 +++ b/Examples/Sample_Archive_ExpandArchiveNoValidationCredential.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path 'C:\ExampleDestinationPath\Destination'. diff --git a/Examples/Sample_Archive_RemoveArchiveChecksum.ps1 b/Examples/Sample_Archive_RemoveArchiveChecksum.ps1 index c05d805..c530b53 100644 --- a/Examples/Sample_Archive_RemoveArchiveChecksum.ps1 +++ b/Examples/Sample_Archive_RemoveArchiveChecksum.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Remove the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the destination path 'C:\ExampleDestinationPath\Destination'. diff --git a/Examples/Sample_Archive_RemoveArchiveNoValidation.ps1 b/Examples/Sample_Archive_RemoveArchiveNoValidation.ps1 index 5578da9..2ccc726 100644 --- a/Examples/Sample_Archive_RemoveArchiveNoValidation.ps1 +++ b/Examples/Sample_Archive_RemoveArchiveNoValidation.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Removes the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the destination path 'C:\ExampleDestinationPath\Destination'. diff --git a/Examples/Sample_Environment_CreateNonPathVariable.ps1 b/Examples/Sample_Environment_CreateNonPathVariable.ps1 index 9129fee..7598e0b 100644 --- a/Examples/Sample_Environment_CreateNonPathVariable.ps1 +++ b/Examples/Sample_Environment_CreateNonPathVariable.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Creates the environment variable 'TestEnvironmentVariable' and sets the value to 'TestValue' both on the machine and within the process. diff --git a/Examples/Sample_Environment_CreatePathVariable.ps1 b/Examples/Sample_Environment_CreatePathVariable.ps1 index 6b8270e..009a673 100644 --- a/Examples/Sample_Environment_CreatePathVariable.ps1 +++ b/Examples/Sample_Environment_CreatePathVariable.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Creates the environment variable 'TestPathEnvironmentVariable' and sets the value to 'TestValue' if it doesn't already exist or appends the value 'TestValue' to the existing path if it does diff --git a/Examples/Sample_Environment_Remove.ps1 b/Examples/Sample_Environment_Remove.ps1 index cabd3dd..4d88e33 100644 --- a/Examples/Sample_Environment_Remove.ps1 +++ b/Examples/Sample_Environment_Remove.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Removes the environment variable 'TestEnvironmentVariable' from both the machine and the process. diff --git a/Examples/Sample_GroupSet_AddMembers.ps1 b/Examples/Sample_GroupSet_AddMembers.ps1 index 702aa51..122e851 100644 --- a/Examples/Sample_GroupSet_AddMembers.ps1 +++ b/Examples/Sample_GroupSet_AddMembers.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS If the groups named GroupName1 and Administrators do not exist, creates the groups named GroupName1 and Administrators and adds the users with the usernames Username1 and Username2 diff --git a/Examples/Sample_Group_RemoveMembers.ps1 b/Examples/Sample_Group_RemoveMembers.ps1 index f75beee..58b1a34 100644 --- a/Examples/Sample_Group_RemoveMembers.ps1 +++ b/Examples/Sample_Group_RemoveMembers.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS If the group named GroupName1 does not exist, creates a group named GroupName1. diff --git a/Examples/Sample_Group_SetMembers.ps1 b/Examples/Sample_Group_SetMembers.ps1 index a050a3b..62be584 100644 --- a/Examples/Sample_Group_SetMembers.ps1 +++ b/Examples/Sample_Group_SetMembers.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS If the group named GroupName1 does not exist, creates a group named GroupName1 and adds the users with the usernames Username1 and Username2 to the group. diff --git a/Examples/Sample_ProcessSet_Start.ps1 b/Examples/Sample_ProcessSet_Start.ps1 index 7e32668..320fe15 100644 --- a/Examples/Sample_ProcessSet_Start.ps1 +++ b/Examples/Sample_ProcessSet_Start.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Starts the processes with the executables at the file paths C:\Windows\cmd.exe and C:\TestPath\TestProcess.exe with no arguments. diff --git a/Examples/Sample_ProcessSet_Stop.ps1 b/Examples/Sample_ProcessSet_Stop.ps1 index 4c47f6f..f1a9b06 100644 --- a/Examples/Sample_ProcessSet_Stop.ps1 +++ b/Examples/Sample_ProcessSet_Stop.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Stops the processes with the executables at the file paths C:\Windows\cmd.exe and C:\TestPath\TestProcess.exe with no arguments and logs any output to the path diff --git a/Examples/Sample_RegistryResource_AddKey.ps1 b/Examples/Sample_RegistryResource_AddKey.ps1 index 138d78f..c49cc96 100644 --- a/Examples/Sample_RegistryResource_AddKey.ps1 +++ b/Examples/Sample_RegistryResource_AddKey.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Create a new registry key called MyNewKey as a subkey under the key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. diff --git a/Examples/Sample_RegistryResource_AddOrModifyValue.ps1 b/Examples/Sample_RegistryResource_AddOrModifyValue.ps1 index df89a0a..ea98dc3 100644 --- a/Examples/Sample_RegistryResource_AddOrModifyValue.ps1 +++ b/Examples/Sample_RegistryResource_AddOrModifyValue.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS If the registry key value MyValue under the key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' does not exist, diff --git a/Examples/Sample_RegistryResource_RemoveKey.ps1 b/Examples/Sample_RegistryResource_RemoveKey.ps1 index 79a2d17..f2cf276 100644 --- a/Examples/Sample_RegistryResource_RemoveKey.ps1 +++ b/Examples/Sample_RegistryResource_RemoveKey.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Removes the registry key called MyNewKey under the parent key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. diff --git a/Examples/Sample_RegistryResource_RemoveValue.ps1 b/Examples/Sample_RegistryResource_RemoveValue.ps1 index 2dec121..37be0ec 100644 --- a/Examples/Sample_RegistryResource_RemoveValue.ps1 +++ b/Examples/Sample_RegistryResource_RemoveValue.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Removes the registry key value MyValue from the key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. diff --git a/Examples/Sample_Script.ps1 b/Examples/Sample_Script.ps1 index caea309..e086cf7 100644 --- a/Examples/Sample_Script.ps1 +++ b/Examples/Sample_Script.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Creates a file at the given file path with the specified content through the Script resource. diff --git a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 index d66b093..79c7820 100644 --- a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 +++ b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the built-in account LocalService. diff --git a/Examples/Sample_ServiceSet_StartServices.ps1 b/Examples/Sample_ServiceSet_StartServices.ps1 index fb8dfee..1ac00dd 100644 --- a/Examples/Sample_ServiceSet_StartServices.ps1 +++ b/Examples/Sample_ServiceSet_StartServices.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Ensures that the DHCP Client and Windows Firewall services are running. #> diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index b2aae55..fc75587 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,4 +1,4 @@ -Configuration UserExample +Configuration UserExample { param ( [System.Management.Automation.PSCredential] diff --git a/Examples/Sample_User_Generic.ps1 b/Examples/Sample_User_Generic.ps1 index 17cd506..bd44a8d 100644 --- a/Examples/Sample_User_Generic.ps1 +++ b/Examples/Sample_User_Generic.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory)] [System.String] diff --git a/Examples/Sample_WindowsFeature.ps1 b/Examples/Sample_WindowsFeature.ps1 index 77d0352..db23f46 100644 --- a/Examples/Sample_WindowsFeature.ps1 +++ b/Examples/Sample_WindowsFeature.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Creates a custom configuration for installing or uninstalling a Windows role or feature. diff --git a/Examples/Sample_WindowsFeatureSet_Install.ps1 b/Examples/Sample_WindowsFeatureSet_Install.ps1 index 9c82264..48aeb95 100644 --- a/Examples/Sample_WindowsFeatureSet_Install.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Install.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Installs the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. diff --git a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 index 7e25124..eb8ecdf 100644 --- a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. diff --git a/Examples/Sample_WindowsOptionalFeature.ps1 b/Examples/Sample_WindowsOptionalFeature.ps1 index f2895d4..151ba55 100644 --- a/Examples/Sample_WindowsOptionalFeature.ps1 +++ b/Examples/Sample_WindowsOptionalFeature.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Enables the Windows optional feature with the specified name and outputs a log to the specified path. diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 index 25f6f7b..ea8eb61 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Disables the Windows optional features TelnetClient and LegacyComponents and removes all files associated with these features. diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 index 13a84c6..16fb179 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Enables the Windows optional features MicrosoftWindowsPowerShellV2 and Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path diff --git a/Examples/Sample_WindowsPackageCab.ps1 b/Examples/Sample_WindowsPackageCab.ps1 index 49af41f..656a4bf 100644 --- a/Examples/Sample_WindowsPackageCab.ps1 +++ b/Examples/Sample_WindowsPackageCab.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Installs a package from the cab file with the specified name from the specified source path and outputs a log to the specified log path. diff --git a/README.md b/README.md index 7633f08..27592af 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,3 @@ -master: [![Build status](https://ci.appveyor.com/api/projects/status/9uf3wyys7ky7776d/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/master) -[![codecov](https://codecov.io/gh/PowerShell/PSDscResources/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/PSDscResources) - -dev: [![Build status](https://ci.appveyor.com/api/projects/status/9uf3wyys7ky7776d/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/dev) -[![codecov](https://codecov.io/gh/PowerShell/PSDscResources/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/PSDscResources) - # PSDscResources PSDscResources is the new home of the in-box resources from PSDesiredStateConfiguration. @@ -17,11 +11,13 @@ Because PSDscResources overwrites in-box resources, it is only available for WMF Many of the resource updates provided here are also included in the [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration) module which is still compatible with WMF 4 and WMF 5 (though this module is not supported and may be removed in the future). To update your in-box resources to the newest versions provided by PSDscResources, first install PSDscResources from the PowerShell Gallery: + ```powershell Install-Module PSDscResources ``` Then, simply add this line to your DSC configuration: + ```powershell Import-DscResource -ModuleName PSDscResources ``` @@ -29,6 +25,26 @@ Import-DscResource -ModuleName PSDscResources This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +## Branches + +### master + +[![Build status](https://ci.appveyor.com/api/projects/status/9uf3wyys7ky7776d/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/master) +[![codecov](https://codecov.io/gh/PowerShell/PSDscResources/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/PSDscResources) + +This is the branch containing the latest release - +no contributions should be made directly to this branch. + +### dev + +[![Build status](https://ci.appveyor.com/api/projects/status/9nsi30ladk1jaax5/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/AuditPolicyDsc/branch/dev) +[![codecov](https://codecov.io/gh/PowerShell/AuditPolicyDsc/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/AuditPolicyDsc/branch/dev) + +This is the development branch +to which contributions should be proposed by contributors as pull requests. +This development branch will periodically be merged to the master branch, +and be released to [PowerShell Gallery](https://www.powershellgallery.com/). + ## Contributing This module does not accept breaking changes. @@ -577,9 +593,19 @@ The following parameters will be the same for each process in the set: ### Unreleased -* Fixes issue where MsiPackage Integration tests fail to make an HTTPS - connection if Strong Crypto for .NET is not enabled. Fixes +* Fixes issue where MsiPackage Integration tests fail if the test HttpListener + fails to start. Moves the test HttpListener objects to dynamically assigned, + higher numbered ports to avoid conflicts with other services, and also checks + to ensure that the ports are available before using them. Adds checks to + ensure that no outstanding HTTP server jobs are running before attempting to + setup a new one. Also adds additional instrumentation to make it easier to + troubleshoot issues with the test HttpListener objects in the future. + Specifically fixes [Issue #142](https://github.com/PowerShell/PSDscResources/issues/142) +* Improved speed of Test-IsNanoServer function +* Remove the Byte Order Mark (BOM) from all affected files +* Opt-in to 'Validate Module Files' and 'Validate Script Files' common meta-tests +* Fix README markdownlint validation failures ### 2.11.0.0 @@ -686,8 +712,8 @@ The following parameters will be the same for each process in the set: ### 2.2.0.0 * WindowsFeature: - * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). - * Updated unit tests. + * Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell). + * Updated unit tests. * Added WindowsProcess * CommonTestHelper: * Added Get-AppVeyorAdministratorCredential. diff --git a/Tests/Integration/GroupSet.Integration.Tests.ps1 b/Tests/Integration/GroupSet.Integration.Tests.ps1 index 4315647..0cbd041 100644 --- a/Tests/Integration/GroupSet.Integration.Tests.ps1 +++ b/Tests/Integration/GroupSet.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () if ($PSVersionTable.PSVersion -lt [Version] '5.1') diff --git a/Tests/Integration/GroupSet.config.ps1 b/Tests/Integration/GroupSet.config.ps1 index 965f469..4b8f6ce 100644 --- a/Tests/Integration/GroupSet.config.ps1 +++ b/Tests/Integration/GroupSet.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [System.String] diff --git a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 index 674c8e4..eb51a23 100644 --- a/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_Archive.EndToEnd.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' if ($PSVersionTable.PSVersion -lt [Version] '5.1') diff --git a/Tests/Integration/MSFT_Archive_CredentialOnly.config.ps1 b/Tests/Integration/MSFT_Archive_CredentialOnly.config.ps1 index 8453105..f94bfbd 100644 --- a/Tests/Integration/MSFT_Archive_CredentialOnly.config.ps1 +++ b/Tests/Integration/MSFT_Archive_CredentialOnly.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_Archive_ValidateAndChecksum.config.ps1 b/Tests/Integration/MSFT_Archive_ValidateAndChecksum.config.ps1 index d912417..8f2376e 100644 --- a/Tests/Integration/MSFT_Archive_ValidateAndChecksum.config.ps1 +++ b/Tests/Integration/MSFT_Archive_ValidateAndChecksum.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_Archive_ValidateOnly.config.ps1 b/Tests/Integration/MSFT_Archive_ValidateOnly.config.ps1 index 6fb9566..a82abba 100644 --- a/Tests/Integration/MSFT_Archive_ValidateOnly.config.ps1 +++ b/Tests/Integration/MSFT_Archive_ValidateOnly.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_EnvironmentResource.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_EnvironmentResource.EndToEnd.Tests.ps1 index 3ef7aee..35418fe 100644 --- a/Tests/Integration/MSFT_EnvironmentResource.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_EnvironmentResource.EndToEnd.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# Please note that some of these tests depend on each other. They must be run in the order given - if one test fails, subsequent tests may also fail. diff --git a/Tests/Integration/MSFT_EnvironmentResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_EnvironmentResource.Integration.Tests.ps1 index bb7d1f6..d508eb7 100644 --- a/Tests/Integration/MSFT_EnvironmentResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_EnvironmentResource.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -# These tests must be run with elevated access +# These tests must be run with elevated access $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' diff --git a/Tests/Integration/MSFT_EnvironmentResource.config.ps1 b/Tests/Integration/MSFT_EnvironmentResource.config.ps1 index 1ee2b4d..0ad329f 100644 --- a/Tests/Integration/MSFT_EnvironmentResource.config.ps1 +++ b/Tests/Integration/MSFT_EnvironmentResource.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [System.String] diff --git a/Tests/Integration/MSFT_GroupResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_GroupResource.Integration.Tests.ps1 index 0f812a8..ff860d9 100644 --- a/Tests/Integration/MSFT_GroupResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_GroupResource.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () $errorActionPreference = 'Stop' diff --git a/Tests/Integration/MSFT_GroupResource_Members.config.ps1 b/Tests/Integration/MSFT_GroupResource_Members.config.ps1 index 8ca8298..b51d44c 100644 --- a/Tests/Integration/MSFT_GroupResource_Members.config.ps1 +++ b/Tests/Integration/MSFT_GroupResource_Members.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [System.String] diff --git a/Tests/Integration/MSFT_GroupResource_MembersToIncludeExclude.config.ps1 b/Tests/Integration/MSFT_GroupResource_MembersToIncludeExclude.config.ps1 index ecd15df..4c6b087 100644 --- a/Tests/Integration/MSFT_GroupResource_MembersToIncludeExclude.config.ps1 +++ b/Tests/Integration/MSFT_GroupResource_MembersToIncludeExclude.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [System.String] diff --git a/Tests/Integration/MSFT_GroupResource_NoMembers.config.ps1 b/Tests/Integration/MSFT_GroupResource_NoMembers.config.ps1 index 7497040..f0ee5cc 100644 --- a/Tests/Integration/MSFT_GroupResource_NoMembers.config.ps1 +++ b/Tests/Integration/MSFT_GroupResource_NoMembers.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [System.String] diff --git a/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 index 78bc29e..d385d4c 100644 --- a/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# Please note that some of these tests depend on each other. They must be run in the order given - if one test fails, subsequent tests may also fail. @@ -13,647 +13,650 @@ if ($PSVersionTable.PSVersion -lt [Version] '5.1') return } -# Import CommonTestHelper -$testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent -$testHelperFolderFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'TestHelpers' -$commonTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'CommonTestHelper.psm1' -Import-Module -Name $commonTestHelperFilePath - -try -{ - # Make sure strong crypto is enabled in .NET for HTTPS tests - $originalStrongCryptoSettings = Enable-StrongCryptoForDotNetFour - - Describe 'MsiPackage End to End Tests' { - BeforeAll { - # Import CommonTestHelper - $testsFolderFilePath = Split-Path $PSScriptRoot -Parent - $testHelperFolderFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'TestHelpers' - $commonTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'CommonTestHelper.psm1' - Import-Module -Name $commonTestHelperFilePath - - $script:testEnvironment = Enter-DscResourceTestEnvironment ` - -DscResourceModuleName 'PSDscResources' ` - -DscResourceName 'MSFT_MsiPackage' ` - -TestType 'Integration' - - # Import MsiPackage resource module for Test-TargetResource - $moduleRootFilePath = Split-Path -Path $testsFolderFilePath -Parent - $dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources' - $msiPackageResourceFolderFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'MSFT_MsiPackage' - $msiPackageResourceModuleFilePath = Join-Path -Path $msiPackageResourceFolderFilePath -ChildPath 'MSFT_MsiPackage.psm1' - Import-Module -Name $msiPackageResourceModuleFilePath -Force - - # Import the MsiPackage test helper - $packageTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'MSFT_MsiPackageResource.TestHelper.psm1' - Import-Module -Name $packageTestHelperFilePath -Force - - # Set up the paths to the test configurations - $script:configurationFilePathNoOptionalParameters = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_MsiPackage_NoOptionalParameters' - $script:configurationFilePathLogPath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_MsiPackage_LogPath' +Describe 'MsiPackage End to End Tests' { + BeforeAll { + # Import CommonTestHelper + $testsFolderFilePath = Split-Path $PSScriptRoot -Parent + $testHelperFolderFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'TestHelpers' + $commonTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'CommonTestHelper.psm1' + Import-Module -Name $commonTestHelperFilePath + + $script:testEnvironment = Enter-DscResourceTestEnvironment ` + -DscResourceModuleName 'PSDscResources' ` + -DscResourceName 'MSFT_MsiPackage' ` + -TestType 'Integration' + + # Import MsiPackage resource module for Test-TargetResource + $moduleRootFilePath = Split-Path -Path $testsFolderFilePath -Parent + $dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources' + $msiPackageResourceFolderFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'MSFT_MsiPackage' + $msiPackageResourceModuleFilePath = Join-Path -Path $msiPackageResourceFolderFilePath -ChildPath 'MSFT_MsiPackage.psm1' + Import-Module -Name $msiPackageResourceModuleFilePath -Force + + # Import the MsiPackage test helper + $packageTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'MSFT_MsiPackageResource.TestHelper.psm1' + Import-Module -Name $packageTestHelperFilePath -Force + + # Set up the paths to the test configurations + $script:configurationFilePathNoOptionalParameters = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_MsiPackage_NoOptionalParameters' + $script:configurationFilePathLogPath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_MsiPackage_LogPath' + + <# + This log file is used to log messages from the mock server which is important for debugging since + most of the work of the mock server is done within a separate process. + #> + $script:logFile = Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt' + $script:environmentInIncorrectStateErrorMessage = 'The current environment is not in the expected state for this test - either something was setup incorrectly on your machine or a previous test failed - results after this may be invalid.' + + $script:msiName = 'DSCSetupProject.msi' + $script:msiLocation = Join-Path -Path $TestDrive -ChildPath $script:msiName + + $script:packageId = '{deadbeef-80c6-41e6-a1b9-8bdb8a05027f}' + + $null = New-TestMsi -DestinationPath $script:msiLocation + + $script:testHttpPort = Get-UnusedTcpPort + $script:testHttpsPort = Get-UnusedTcpPort -ExcludePorts @($script:testHttpPort) + + # Clear the log file + 'Beginning integration tests' > $script:logFile + } - <# - This log file is used to log messages from the mock server which is important for debugging since - most of the work of the mock server is done within a separate process. - #> - $script:logFile = Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt' - $script:environmentInIncorrectStateErrorMessage = 'The current environment is not in the expected state for this test - either something was setup incorrectly on your machine or a previous test failed - results after this may be invalid.' + AfterAll { + # Remove the test MSI if it is still installed + if (Test-PackageInstalledById -ProductId $script:packageId) + { + $null = Start-Process -FilePath 'msiexec.exe' -ArgumentList @("/x$script:packageId", '/passive') -Wait + $null = Start-Sleep -Seconds 1 + } - $script:msiName = 'DSCSetupProject.msi' - $script:msiLocation = Join-Path -Path $TestDrive -ChildPath $script:msiName + if (Test-PackageInstalledById -ProductId $script:packageId) + { + throw 'Test package could not be uninstalled after running all tests. It may cause errors in subsequent test runs.' + } - $script:packageId = '{deadbeef-80c6-41e6-a1b9-8bdb8a05027f}' + Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment + } - $null = New-TestMsi -DestinationPath $script:msiLocation + Context 'Uninstall package that is already Absent' { + $configurationName = 'RemoveAbsentMsiPackage' - # Clear the log file - 'Beginning integration tests' > $script:logFile + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Absent' } - AfterAll { - # Remove the test MSI if it is still installed - if (Test-PackageInstalledById -ProductId $script:packageId) + It 'Should return True from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $true + + if ($testTargetResourceInitialResult -ne $true) { - $null = Start-Process -FilePath 'msiexec.exe' -ArgumentList @("/x$script:packageId", '/passive') -Wait - $null = Start-Sleep -Seconds 1 + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - if (Test-PackageInstalledById -ProductId $script:packageId) + It 'Package should not exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + + It 'Should compile and run configuration' { { - throw 'Test package could not be uninstalled after running all tests. It may cause errors in subsequent test runs.' - } + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } - Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true } - Context 'Uninstall package that is already Absent' { - $configurationName = 'RemoveAbsentMsiPackage' + It 'Package should not exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Absent' - } + Context 'Install package that is not installed yet' { + $configurationName = 'InstallMsiPackage' - It 'Should return True from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $true + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Present' + } - if ($testTargetResourceInitialResult -ne $true) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - It 'Package should not exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + if ($testTargetResourceInitialResult -ne $false) + { + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } + It 'Package should not exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Should compile and run configuration' { + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } - It 'Package should not exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true } - Context 'Install package that is not installed yet' { - $configurationName = 'InstallMsiPackage' + It 'Package should exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Present' - } + Context 'Install package that is already installed' { + $configurationName = 'InstallExistingMsiPackage' - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Present' + } - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + It 'Should return True from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $true - It 'Package should not exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + if ($testTargetResourceInitialResult -ne $true) + { + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } + It 'Package should exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Should compile and run configuration' { + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } - It 'Package should exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true } - Context 'Install package that is already installed' { - $configurationName = 'InstallExistingMsiPackage' + It 'Package should exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Present' - } + Context 'Uninstall package that is installed' { + $configurationName = 'UninstallExistingMsiPackage' - It 'Should return True from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $true + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Absent' + } - if ($testTargetResourceInitialResult -ne $true) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - It 'Package should exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + if ($testTargetResourceInitialResult -ne $false) + { + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } + It 'Package should exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Should compile and run configuration' { + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } - It 'Package should exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true } - Context 'Uninstall package that is installed' { - $configurationName = 'UninstallExistingMsiPackage' + It 'Package should not exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Absent' - } + Context 'Install package that is not installed and write to specified log file' { + $configurationName = 'InstallWithLogFile' - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $logPath = Join-Path -Path $TestDrive -ChildPath 'TestMsiLog.txt' - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + if (Test-Path -Path $logPath) + { + Remove-Item -Path $logPath -Force + } - It 'Package should exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Present' + LogPath = $logPath + } - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + if ($testTargetResourceInitialResult -ne $false) + { + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Package should not exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + It 'Package should not exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false } - Context 'Install package that is not installed and write to specified log file' { - $configurationName = 'InstallWithLogFile' + It 'Should compile and run configuration' { + { + . $script:configurationFilePathLogPath -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } - $logPath = Join-Path -Path $TestDrive -ChildPath 'TestMsiLog.txt' + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } - if (Test-Path -Path $logPath) - { - Remove-Item -Path $logPath -Force - } + It 'Should have created the log file' { + Test-Path -Path $logPath | Should Be $true + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Present' - LogPath = $logPath - } + It 'Package should exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + } - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + Context 'Uninstall package that is installed and write to specified log file' { + $configurationName = 'InstallWithLogFile' - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + $logPath = Join-Path -Path $TestDrive -ChildPath 'TestMsiLog.txt' - It 'Package should not exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + if (Test-Path -Path $logPath) + { + Remove-Item -Path $logPath -Force + } - It 'Should compile and run configuration' { - { - . $script:configurationFilePathLogPath -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $script:msiLocation + Ensure = 'Absent' + LogPath = $logPath + } - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - It 'Should have created the log file' { - Test-Path -Path $logPath | Should Be $true + if ($testTargetResourceInitialResult -ne $false) + { + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Package should exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } + It 'Package should exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true } - Context 'Uninstall package that is installed and write to specified log file' { - $configurationName = 'InstallWithLogFile' + It 'Should compile and run configuration' { + { + . $script:configurationFilePathLogPath -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw + } + + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } + + It 'Should have created the log file' { + Test-Path -Path $logPath | Should Be $true + } + + It 'Package should not exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + } + + Context 'Install package from HTTP Url' { + $configurationName = 'UninstallExistingMsiPackageFromHttp' + + $uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort) + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri + + $fileServerStarted = $null + $job = $null - $logPath = Join-Path -Path $TestDrive -ChildPath 'TestMsiLog.txt' + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $msiUrl + Ensure = 'Present' + } + + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - if (Test-Path -Path $logPath) + if ($testTargetResourceInitialResult -ne $false) { - Remove-Item -Path $logPath -Force + <# + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be + #> + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $script:msiLocation - Ensure = 'Absent' - LogPath = $logPath - } + It 'Package should not exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + try + { + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort + $fileServerStarted = $serverResult.FileServerStarted + $job = $serverResult.Job - It 'Package should exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } + $fileServerStarted.WaitOne(30000) It 'Should compile and run configuration' { - { - . $script:configurationFilePathLogPath -ConfigurationName $configurationName + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName & $configurationName -OutputPath $TestDrive @msiPackageParameters Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force } | Should Not Throw } - - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } - - It 'Should have created the log file' { - Test-Path -Path $logPath | Should Be $true - } - - It 'Package should not exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + } + finally + { + <# + This must be called after Start-Server to ensure the listening port is closed, + otherwise subsequent tests may fail until the machine is rebooted. + #> + Stop-Server -FileServerStarted $fileServerStarted -Job $job } - Context 'Install package from HTTP Url' { - $configurationName = 'UninstallExistingMsiPackageFromHttp' + It 'Should return True from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } - $baseUrl = 'http://localhost:1242/' - $msiUrl = "$baseUrl" + 'package.msi' + It 'Package should exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + } - $fileServerStarted = $null - $job = $null + Context 'Uninstall Msi package from HTTP Url' { + $configurationName = 'InstallMsiPackageFromHttp' - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $msiUrl - Ensure = 'Present' - } + $uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort) + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $fileServerStarted = $null + $job = $null - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $msiUrl + Ensure = 'Absent' + } - It 'Package should not exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false - try - { - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false - $fileServerStarted = $serverResult.FileServerStarted - $job = $serverResult.Job - - $fileServerStarted.WaitOne(30000) - - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } - } - finally + if ($testTargetResourceInitialResult -ne $false) { <# - This must be called after Start-Server to ensure the listening port is closed, - otherwise subsequent tests may fail until the machine is rebooted. + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be #> - Stop-Server -FileServerStarted $fileServerStarted -Job $job + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Should return True from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Package should exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + + try + { + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance + + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort + $fileServerStarted = $serverResult.FileServerStarted + $job = $serverResult.Job - It 'Package should exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + $fileServerStarted.WaitOne(30000) + + It 'Should compile and run configuration' { + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw } } + finally + { + <# + This must be called after Start-Server to ensure the listening port is closed, + otherwise subsequent tests may fail until the machine is rebooted. + #> + Stop-Server -FileServerStarted $fileServerStarted -Job $job + } - Context 'Uninstall Msi package from HTTP Url' { - $configurationName = 'InstallMsiPackageFromHttp' + It 'Should return true from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } - $baseUrl = 'http://localhost:1242/' - $msiUrl = "$baseUrl" + 'package.msi' + It 'Package should not exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + } - $fileServerStarted = $null - $job = $null + Context 'Install Msi package from HTTPS Url' { + $configurationName = 'InstallMsiPackageFromHttpS' - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $msiUrl - Ensure = 'Absent' - } + $uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort) + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $fileServerStarted = $null + $job = $null - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $msiUrl + Ensure = 'Present' + } - It 'Package should exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } - - try - { - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false - $fileServerStarted = $serverResult.FileServerStarted - $job = $serverResult.Job - - $fileServerStarted.WaitOne(30000) - - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } - } - finally + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false + + if ($testTargetResourceInitialResult -ne $false) { <# - This must be called after Start-Server to ensure the listening port is closed, - otherwise subsequent tests may fail until the machine is rebooted. + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be #> - Stop-Server -FileServerStarted $fileServerStarted -Job $job + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } + } - It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Package should not exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + } + + try + { + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance + + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort + $fileServerStarted = $serverResult.FileServerStarted + $job = $serverResult.Job + + $fileServerStarted.WaitOne(30000) - It 'Package should not exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false + It 'Should compile and run configuration' { + { + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw } } + finally + { + <# + This must be called after Start-Server to ensure the listening port is closed, + otherwise subsequent tests may fail until the machine is rebooted. + #> + Stop-Server -FileServerStarted $fileServerStarted -Job $job + } - Context 'Install Msi package from HTTPS Url' { - $configurationName = 'InstallMsiPackageFromHttpS' + It 'Should return true from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } - $baseUrl = 'https://localhost:1243/' - $msiUrl = "$baseUrl" + 'package.msi' + It 'Package should exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } + } - $fileServerStarted = $null - $job = $null + Context 'Uninstall Msi package from HTTPS Url' { + $configurationName = 'UninstallMsiPackageFromHttps' - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $msiUrl - Ensure = 'Present' - } + $uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort) + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $fileServerStarted = $null + $job = $null - if ($testTargetResourceInitialResult -ne $false) - { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } + $msiPackageParameters = @{ + ProductId = $script:packageId + Path = $msiUrl + Ensure = 'Absent' + } - It 'Package should not exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } - - try - { - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true - $fileServerStarted = $serverResult.FileServerStarted - $job = $serverResult.Job - - $fileServerStarted.WaitOne(30000) - - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } - } - finally + It 'Should return False from Test-TargetResource with the same parameters before configuration' { + $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters + $testTargetResourceInitialResult | Should Be $false + + if ($testTargetResourceInitialResult -ne $false) { <# - This must be called after Start-Server to ensure the listening port is closed, - otherwise subsequent tests may fail until the machine is rebooted. + Not throwing an error here since the tests should still run correctly after this, + we just want to notify the user that the tests aren't necessarily testing what + they should be #> - Stop-Server -FileServerStarted $fileServerStarted -Job $job - } - - It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } - - It 'Package should exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + Write-Error -Message $script:environmentInIncorrectStateErrorMessage } } - - Context 'Uninstall Msi package from HTTPS Url' { - $configurationName = 'UninstallMsiPackageFromHttps' - $baseUrl = 'https://localhost:1243/' - $msiUrl = "$baseUrl" + 'package.msi' + It 'Package should exist on the machine before configuration is run' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $true + } - $fileServerStarted = $null - $job = $null + try + { + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance - $msiPackageParameters = @{ - ProductId = $script:packageId - Path = $msiUrl - Ensure = 'Absent' - } + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort + $fileServerStarted = $serverResult.FileServerStarted + $job = $serverResult.Job - It 'Should return False from Test-TargetResource with the same parameters before configuration' { - $testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters - $testTargetResourceInitialResult | Should Be $false + $fileServerStarted.WaitOne(30000) - if ($testTargetResourceInitialResult -ne $false) + It 'Should compile and run configuration' { { - <# - Not throwing an error here since the tests should still run correctly after this, - we just want to notify the user that the tests aren't necessarily testing what - they should be - #> - Write-Error -Message $script:environmentInIncorrectStateErrorMessage - } - } - - It 'Package should exist on the machine before configuration is run' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $true - } - - try - { - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true - $fileServerStarted = $serverResult.FileServerStarted - $job = $serverResult.Job - - $fileServerStarted.WaitOne(30000) - - It 'Should compile and run configuration' { - { - . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName - & $configurationName -OutputPath $TestDrive @msiPackageParameters - Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force - } | Should Not Throw - } - } - finally - { - <# - This must be called after Start-Server to ensure the listening port is closed, - otherwise subsequent tests may fail until the machine is rebooted. - #> - Stop-Server -FileServerStarted $fileServerStarted -Job $job + . $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName + & $configurationName -OutputPath $TestDrive @msiPackageParameters + Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force + } | Should Not Throw } + } + finally + { + <# + This must be called after Start-Server to ensure the listening port is closed, + otherwise subsequent tests may fail until the machine is rebooted. + #> + Stop-Server -FileServerStarted $fileServerStarted -Job $job + } - It 'Should return true from Test-TargetResource with the same parameters after configuration' { - MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true - } + It 'Should return true from Test-TargetResource with the same parameters after configuration' { + MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true + } - It 'Package should not exist on the machine' { - Test-PackageInstalledById -ProductId $script:packageId | Should Be $false - } + It 'Package should not exist on the machine' { + Test-PackageInstalledById -ProductId $script:packageId | Should Be $false } } } -finally -{ - Undo-ChangesToStrongCryptoForDotNetFour -OriginalSettings $originalStrongCryptoSettings -} diff --git a/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 b/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 index a6a5e45..2f446ee 100644 --- a/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' if ($PSVersionTable.PSVersion -lt [Version] '5.1') @@ -19,9 +19,6 @@ $script:testEnvironment = Enter-DscResourceTestEnvironment ` try { - # Make sure strong crypto is enabled in .NET for HTTPS tests - $originalStrongCryptoSettings = Enable-StrongCryptoForDotNetFour - InModuleScope 'MSFT_MsiPackage' { Describe 'MSFT_MsiPackage Integration Tests' { BeforeAll { @@ -40,7 +37,7 @@ try <# This log file is used to log messages from the mock server which is important for debugging since - most of the work of the mock server is done within a separate process. + most of the work of the mock server is done within a separate process. #> $script:logFile = Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt' @@ -52,6 +49,9 @@ try $null = New-TestMsi -DestinationPath $script:msiLocation + $script:testHttpPort = Get-UnusedTcpPort + $script:testHttpsPort = Get-UnusedTcpPort -ExcludePorts @($script:testHttpPort) + # Clear the log file 'Beginning integration tests' > $script:logFile } @@ -174,8 +174,11 @@ try } It 'Should correctly install and remove a package from a HTTP URL' { - $baseUrl = 'http://localhost:1242/' - $msiUrl = "$baseUrl" + 'package.msi' + $uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort) + $baseUrl = $uriBuilder.Uri.AbsoluteUri + + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri $fileServerStarted = $null $job = $null @@ -184,7 +187,10 @@ try { 'Http tests:' >> $script:logFile - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance + + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort $fileServerStarted = $serverResult.FileServerStarted $job = $serverResult.Job @@ -199,6 +205,12 @@ try Set-TargetResource -Ensure 'Absent' -Path $msiUrl -ProductId $script:packageId Test-PackageInstalledById -ProductId $script:packageId | Should Be $false } + catch + { + Write-Warning -Message 'Caught exception performing HTTP server tests. Outputting HTTP server log.' -Verbose + Get-Content -Path $script:logFile | Write-Verbose -Verbose + throw $_ + } finally { <# @@ -210,9 +222,11 @@ try } It 'Should correctly install and remove a package from a HTTPS URL' -Skip:$script:skipHttpsTest { + $uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort) + $baseUrl = $uriBuilder.Uri.AbsoluteUri - $baseUrl = 'https://localhost:1243/' - $msiUrl = "$baseUrl" + 'package.msi' + $uriBuilder.Path = 'package.msi' + $msiUrl = $uriBuilder.Uri.AbsoluteUri $fileServerStarted = $null $job = $null @@ -221,9 +235,12 @@ try { 'Https tests:' >> $script:logFile - $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true + # Make sure no existing HTTP(S) test servers are running + Stop-EveryTestServerInstance + + $serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort $fileServerStarted = $serverResult.FileServerStarted - $job = $serverResult.Job + $job = $serverResult.Job # Wait for the file server to be ready to receive requests $fileServerStarted.WaitOne(30000) @@ -236,6 +253,12 @@ try Set-TargetResource -Ensure 'Absent' -Path $msiUrl -ProductId $script:packageId Test-PackageInstalledById -ProductId $script:packageId | Should Be $false } + catch + { + Write-Warning -Message 'Caught exception performing HTTPS server tests. Outputting HTTPS server log.' -Verbose + Get-Content -Path $script:logFile | Write-Verbose -Verbose + throw $_ + } finally { <# @@ -309,6 +332,4 @@ try finally { Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment - - Undo-ChangesToStrongCryptoForDotNetFour -OriginalSettings $originalStrongCryptoSettings } diff --git a/Tests/Integration/MSFT_MsiPackage_LogPath.ps1 b/Tests/Integration/MSFT_MsiPackage_LogPath.ps1 index ee5dafe..2f7c76b 100644 --- a/Tests/Integration/MSFT_MsiPackage_LogPath.ps1 +++ b/Tests/Integration/MSFT_MsiPackage_LogPath.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_MsiPackage_NoOptionalParameters.ps1 b/Tests/Integration/MSFT_MsiPackage_NoOptionalParameters.ps1 index 209cd28..5ef329f 100644 --- a/Tests/Integration/MSFT_MsiPackage_NoOptionalParameters.ps1 +++ b/Tests/Integration/MSFT_MsiPackage_NoOptionalParameters.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_RegistryResource.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_RegistryResource.EndToEnd.Tests.ps1 index b7d3c1f..440e74b 100644 --- a/Tests/Integration/MSFT_RegistryResource.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_RegistryResource.EndToEnd.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# WARNING: DO NOT RUN THESE TESTS ON A VALUABLE MACHINE! Running on a disposable VM or AppVeyor is strongly recommended. If these tests go awry, your machine's registry could be corrupted which will brick your machine! diff --git a/Tests/Integration/MSFT_RegistryResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_RegistryResource.Integration.Tests.ps1 index 3426ff5..6f5cce4 100644 --- a/Tests/Integration/MSFT_RegistryResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_RegistryResource.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# WARNING: DO NOT RUN THESE TESTS ON A VALUABLE MACHINE! Running on a disposable VM or AppVeyor is strongly recommended. If these tests go awry, your machine's registry could be corrupted which will brick your machine! diff --git a/Tests/Integration/MSFT_RegistryResource_KeyAndNameOnly.config.ps1 b/Tests/Integration/MSFT_RegistryResource_KeyAndNameOnly.config.ps1 index 30622fa..8c6f477 100644 --- a/Tests/Integration/MSFT_RegistryResource_KeyAndNameOnly.config.ps1 +++ b/Tests/Integration/MSFT_RegistryResource_KeyAndNameOnly.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_RegistryResource_WithDataAndType.config.ps1 b/Tests/Integration/MSFT_RegistryResource_WithDataAndType.config.ps1 index 16615a4..d4532cc 100644 --- a/Tests/Integration/MSFT_RegistryResource_WithDataAndType.config.ps1 +++ b/Tests/Integration/MSFT_RegistryResource_WithDataAndType.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_ScriptResource.Integration.Tests.ps1 b/Tests/Integration/MSFT_ScriptResource.Integration.Tests.ps1 index 52a7b95..953f4a6 100644 --- a/Tests/Integration/MSFT_ScriptResource.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_ScriptResource.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' if ($PSVersionTable.PSVersion -lt [Version] '5.1') diff --git a/Tests/Integration/MSFT_ScriptResource_NoCredential.config.ps1 b/Tests/Integration/MSFT_ScriptResource_NoCredential.config.ps1 index 7c33181..c1803c8 100644 --- a/Tests/Integration/MSFT_ScriptResource_NoCredential.config.ps1 +++ b/Tests/Integration/MSFT_ScriptResource_NoCredential.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_ScriptResource_WithCredential.config.ps1 b/Tests/Integration/MSFT_ScriptResource_WithCredential.config.ps1 index 0f9f066..a0c3e2e 100644 --- a/Tests/Integration/MSFT_ScriptResource_WithCredential.config.ps1 +++ b/Tests/Integration/MSFT_ScriptResource_WithCredential.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_UserResource.config.ps1 b/Tests/Integration/MSFT_UserResource.config.ps1 index cd33399..4f2448d 100644 --- a/Tests/Integration/MSFT_UserResource.config.ps1 +++ b/Tests/Integration/MSFT_UserResource.config.ps1 @@ -1,4 +1,4 @@ - + # Integration Test Config Template Version 1.0.0 param ( diff --git a/Tests/Integration/MSFT_WindowsFeature.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsFeature.Integration.Tests.ps1 index cbf4ce4..ca00b19 100644 --- a/Tests/Integration/MSFT_WindowsFeature.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_WindowsFeature.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# Integration tests for installing/uninstalling a Windows Feature. Currently Telnet-Client is set as the feature to test since it's fairly small and doesn't require a restart. ADRMS is set as the feature to test installing/uninstalling a feature with subfeatures, diff --git a/Tests/Integration/MSFT_WindowsFeature.config.ps1 b/Tests/Integration/MSFT_WindowsFeature.config.ps1 index 149a631..2a7b8d8 100644 --- a/Tests/Integration/MSFT_WindowsFeature.config.ps1 +++ b/Tests/Integration/MSFT_WindowsFeature.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory)] [System.String] diff --git a/Tests/Integration/MSFT_WindowsOptionalFeature.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsOptionalFeature.Integration.Tests.ps1 index 6ddcf2e..fd7dac0 100644 --- a/Tests/Integration/MSFT_WindowsOptionalFeature.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_WindowsOptionalFeature.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -if ($PSVersionTable.PSVersion -lt [Version] '5.1') +if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' return diff --git a/Tests/Integration/MSFT_WindowsOptionalFeature.config.ps1 b/Tests/Integration/MSFT_WindowsOptionalFeature.config.ps1 index dd59b61..26fc947 100644 --- a/Tests/Integration/MSFT_WindowsOptionalFeature.config.ps1 +++ b/Tests/Integration/MSFT_WindowsOptionalFeature.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_WindowsPackageCab.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsPackageCab.Integration.Tests.ps1 index 77493bd..1486817 100644 --- a/Tests/Integration/MSFT_WindowsPackageCab.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_WindowsPackageCab.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -if ($PSVersionTable.PSVersion -lt [Version] '5.1') +if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' return diff --git a/Tests/Integration/MSFT_WindowsPackageCab.config.ps1 b/Tests/Integration/MSFT_WindowsPackageCab.config.ps1 index 94fc5b2..6924659 100644 --- a/Tests/Integration/MSFT_WindowsPackageCab.config.ps1 +++ b/Tests/Integration/MSFT_WindowsPackageCab.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_WindowsProcess.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsProcess.Integration.Tests.ps1 index 683077a..fde7f6c 100644 --- a/Tests/Integration/MSFT_WindowsProcess.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_WindowsProcess.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' if ($PSVersionTable.PSVersion -lt [Version] '5.1') diff --git a/Tests/Integration/MSFT_WindowsProcess_NoCredential.config.ps1 b/Tests/Integration/MSFT_WindowsProcess_NoCredential.config.ps1 index f3e2b9a..825cb15 100644 --- a/Tests/Integration/MSFT_WindowsProcess_NoCredential.config.ps1 +++ b/Tests/Integration/MSFT_WindowsProcess_NoCredential.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/MSFT_WindowsProcess_WithCredential.config.ps1 b/Tests/Integration/MSFT_WindowsProcess_WithCredential.config.ps1 index 38e5b07..a8a5544 100644 --- a/Tests/Integration/MSFT_WindowsProcess_WithCredential.config.ps1 +++ b/Tests/Integration/MSFT_WindowsProcess_WithCredential.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/ProcessSet.Integration.Tests.ps1 b/Tests/Integration/ProcessSet.Integration.Tests.ps1 index 9a53a9e..e91e3fb 100644 --- a/Tests/Integration/ProcessSet.Integration.Tests.ps1 +++ b/Tests/Integration/ProcessSet.Integration.Tests.ps1 @@ -1,4 +1,4 @@ - + if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' diff --git a/Tests/Integration/ProcessSet.config.ps1 b/Tests/Integration/ProcessSet.config.ps1 index 6c36f61..04a5694 100644 --- a/Tests/Integration/ProcessSet.config.ps1 +++ b/Tests/Integration/ProcessSet.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/ServiceSet.Integration.Tests.ps1 b/Tests/Integration/ServiceSet.Integration.Tests.ps1 index b4c7b80..605abe9 100644 --- a/Tests/Integration/ServiceSet.Integration.Tests.ps1 +++ b/Tests/Integration/ServiceSet.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -<# +<# These tests should only be run in AppVeyor since they currently require the AppVeyor administrator account credential to run. diff --git a/Tests/Integration/ServiceSet_AllExceptBuiltInAccount.config.ps1 b/Tests/Integration/ServiceSet_AllExceptBuiltInAccount.config.ps1 index e839623..77f4ad1 100644 --- a/Tests/Integration/ServiceSet_AllExceptBuiltInAccount.config.ps1 +++ b/Tests/Integration/ServiceSet_AllExceptBuiltInAccount.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/ServiceSet_BuiltInAccountOnly.config.ps1 b/Tests/Integration/ServiceSet_BuiltInAccountOnly.config.ps1 index c85009c..bd08a66 100644 --- a/Tests/Integration/ServiceSet_BuiltInAccountOnly.config.ps1 +++ b/Tests/Integration/ServiceSet_BuiltInAccountOnly.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/WindowsFeatureSet.Integration.Tests.ps1 b/Tests/Integration/WindowsFeatureSet.Integration.Tests.ps1 index 2b5edb6..366521e 100644 --- a/Tests/Integration/WindowsFeatureSet.Integration.Tests.ps1 +++ b/Tests/Integration/WindowsFeatureSet.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -if ($PSVersionTable.PSVersion -lt [Version] '5.1') +if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' return diff --git a/Tests/Integration/WindowsFeatureSet.config.ps1 b/Tests/Integration/WindowsFeatureSet.config.ps1 index 8f20e3d..5adedb4 100644 --- a/Tests/Integration/WindowsFeatureSet.config.ps1 +++ b/Tests/Integration/WindowsFeatureSet.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/Integration/WindowsOptionalFeatureSet.Integration.Tests.ps1 b/Tests/Integration/WindowsOptionalFeatureSet.Integration.Tests.ps1 index 8966f61..9cd37ac 100644 --- a/Tests/Integration/WindowsOptionalFeatureSet.Integration.Tests.ps1 +++ b/Tests/Integration/WindowsOptionalFeatureSet.Integration.Tests.ps1 @@ -1,4 +1,4 @@ -if ($PSVersionTable.PSVersion -lt [Version] '5.1') +if ($PSVersionTable.PSVersion -lt [Version] '5.1') { Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' return diff --git a/Tests/Integration/WindowsOptionalFeatureSet.config.ps1 b/Tests/Integration/WindowsOptionalFeatureSet.config.ps1 index 694887c..f0bee05 100644 --- a/Tests/Integration/WindowsOptionalFeatureSet.config.ps1 +++ b/Tests/Integration/WindowsOptionalFeatureSet.config.ps1 @@ -1,4 +1,4 @@ -param +param ( [Parameter(Mandatory = $true)] [String] diff --git a/Tests/TestHelpers/CommonTestHelper.psm1 b/Tests/TestHelpers/CommonTestHelper.psm1 index 725b4ad..74e5c58 100644 --- a/Tests/TestHelpers/CommonTestHelper.psm1 +++ b/Tests/TestHelpers/CommonTestHelper.psm1 @@ -1,4 +1,4 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () $errorActionPreference = 'Stop' @@ -157,7 +157,7 @@ function Invoke-ExpectedMocksAreCalledTest Each item in the array is a hashtable that contains the name of the command being mocked, the number of times it is called (can be 0) and, optionally, an extra custom string to make the test name more descriptive. The custom - string will only work if the command has a corresponding variable in the + string will only work if the command has a corresponding variable in the string data name. .PARAMETER ShouldThrow @@ -227,7 +227,7 @@ function Invoke-GenericUnitTest { Each item in the array is a hashtable that contains the name of the command being mocked, the number of times it is called (can be 0) and, optionally, an extra custom string to make the test name more descriptive. The custom - string will only work if the command has a corresponding variable in the + string will only work if the command has a corresponding variable in the string data name. .PARAMETER ExpectedReturnValue @@ -288,7 +288,7 @@ function Invoke-GetTargetResourceUnitTest Each item in the array is a hashtable that contains the name of the command being mocked, the number of times it is called (can be 0) and, optionally, an extra custom string to make the test name more descriptive. The custom - string will only work if the command has a corresponding variable in the + string will only work if the command has a corresponding variable in the string data name. .PARAMETER ShouldThrow @@ -354,7 +354,7 @@ function Invoke-SetTargetResourceUnitTest { Each item in the array is a hashtable that contains the name of the command being mocked, the number of times it is called (can be 0) and, optionally, an extra custom string to make the test name more descriptive. The custom - string will only work if the command has a corresponding variable in the + string will only work if the command has a corresponding variable in the string data name. .PARAMETER ExpectedReturnValue @@ -573,7 +573,7 @@ function Test-IsFileLocked .PARAMETER ExpectedOutput The output expected to be in the output from running WhatIf with the Set-TargetResource cmdlet. If this parameter is empty or null, this cmdlet will check that there was no output from - Set-TargetResource with WhatIf specified. + Set-TargetResource with WhatIf specified. #> function Test-SetTargetResourceWithWhatIf { @@ -584,7 +584,7 @@ function Test-SetTargetResourceWithWhatIf [Parameter(Mandatory = $true)] [Hashtable] $Parameters, - + [String[]] $ExpectedOutput ) @@ -792,101 +792,82 @@ function Exit-DscResourceTestEnvironment <# .SYNOPSIS - Enables strong crypto for .NET v4.0.30319. Returns a Hashtable - containing the relevant, original registry settings, prior to - modification. + Finds an unused TCP port in the specified port range. By default, + searches within ports 38473 - 38799, which at the time of writing, show + as unassigned in: + https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml + + .PARAMETER LowestPortNumber + The TCP port number at which to begin the unused port search. Must be + greater than 0. + + .PARAMETER HighestPortNumber + The highest TCP port number to search for unused ports within. Must be + greater than 0, and greater than LowestPortNumber. + + .PARAMETER ExcludePorts + TCP ports to exclude from the search, even if they fall within the + LowestPortNumber and HighestPortNumber range. #> -function Enable-StrongCryptoForDotNetFour +function Get-UnusedTcpPort { - [OutputType([System.Collections.Hashtable])] + [OutputType([System.UInt16])] [CmdletBinding()] - param () - - $originalValues = @{} - - $regBases = @( - 'HKLM:\SOFTWARE' - 'HKLM:\SOFTWARE\Wow6432Node' + param + ( + [Parameter()] + [ValidateScript({$_ -gt 0})] + [System.UInt16] + $LowestPortNumber = 38473, + + [Parameter()] + [ValidateScript({$_ -gt $0})] + [System.UInt16] + $HighestPortNumber = 38799, + + [Parameter()] + [System.UInt16[]] + $ExcludePorts = @() ) - $net4Suffix = 'Microsoft\.NetFramework\v4.0.30319' - - foreach ($regBase in $regBases) + if ($HighestPortNumber -lt $LowestPortNumber) { - $regPath = Join-Path -Path $regBase -ChildPath $net4Suffix - - if ($null -ne (Get-Item -Path $regPath -ErrorAction SilentlyContinue)) - { - $useStrongCryptoProp = Get-ItemProperty -Path $regPath -Name 'SchUseStrongCrypto' -ErrorAction SilentlyContinue - $needsUpdate = $false - - if ($null -eq $useStrongCryptoProp) - { - $originalValues.Add($regPath, $null) - $needsUpdate = $true - } - else - { - $originalValues.Add($regPath, $useStrongCryptoProp.SchUseStrongCrypto) + throw 'HighestPortNumber must be greater than or equal to LowestPortNumber' + } - if ($useStrongCryptoProp.SchUseStrongCrypto -ne 1) - { - $needsUpdate = $true - } - } + [System.UInt16] $unusedPort = 0 - if ($needsUpdate) - { - Write-Verbose -Message "Setting property SchUseStrongCrypto at path '$regPath' to 1" - - Set-ItemProperty -Path $regPath -Name 'SchUseStrongCrypto' -Value '1' -Type DWord -ErrorAction Stop - } - } - else - { - Write-Warning -Message "Failed to find registry key at path: $regPath. Skipping setting SchUseStrongCrypto to 1. This may cause Integration tests to fail that depend on this setting." - continue - } + [System.Collections.ArrayList] $usedAndExcludedPorts = (Get-NetTCPConnection).LocalPort | Where-Object -FilterScript { + $_ -ge $LowestPortNumber -and $_ -le $HighestPortNumber } - return $originalValues -} + if (!(Test-Path -Path variable:usedAndExcludedPorts) -or ($null -eq $usedAndExcludedPorts)) + { + [System.Collections.ArrayList] $usedAndExcludedPorts = @() + } -<# - .SYNOPSIS - Restores strong crypto for .NET v4.0.30319 settings to what they were - prior to calling Enable-StrongCryptoForDotNetFour. + if (!(Test-Path -Path variable:ExcludePorts) -or ($null -eq $ExcludePorts)) + { + $ExcludePorts = @() + } - .PARAMETER OriginalSettings - A Hashtable containing the original registry settings for strong crypto - for .NET v4.0.30319. -#> -function Undo-ChangesToStrongCryptoForDotNetFour -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.Collections.Hashtable] - $OriginalSettings - ) + $null = $usedAndExcludedPorts.Add($ExcludePorts) - foreach ($regPath in $OriginalSettings.Keys) + foreach ($port in $LowestPortNumber..$HighestPortNumber) { - $useStrongCryptoProp = Get-ItemProperty -Path $regPath -Name 'SchUseStrongCrypto' -ErrorAction SilentlyContinue - - # The SchUseStrongCrypto value previously didn't exist, but now does. Delete it. - if ($null -eq $OriginalSettings[$regPath] -and $null -ne $useStrongCryptoProp) + if (!($usedAndExcludedPorts.Contains($port))) { - Remove-ItemProperty -Path $regPath -Name 'SchUseStrongCrypto' -ErrorAction Stop - } - # The SchUseStrongCrypto value previously existed but had a different value. - elseif($OriginalSettings[$regPath] -ne $useStrongCryptoProp.SchUseStrongCrypto) - { - Set-ItemProperty -Path $regPath -Name 'SchUseStrongCrypto' -Value $OriginalSettings[$regPath] -Type DWord -ErrorAction Stop + $unusedPort = $port + break } } + + if ($unusedPort -eq 0) + { + throw "Failed to find unused TCP port between ports $LowestPortNumber and $HighestPortNumber." + } + + return $unusedPort } Export-ModuleMember -Function @( @@ -901,7 +882,6 @@ Export-ModuleMember -Function @( 'Invoke-SetTargetResourceUnitTest', ` 'Invoke-TestTargetResourceUnitTest', ` 'Invoke-ExpectedMocksAreCalledTest', ` - 'Invoke-GenericUnitTest', - 'Enable-StrongCryptoForDotNetFour', - 'Undo-ChangesToStrongCryptoForDotNetFour' + 'Invoke-GenericUnitTest', ` + 'Get-UnusedTcpPort' ) diff --git a/Tests/TestHelpers/DSCTestService.cs b/Tests/TestHelpers/DSCTestService.cs index 6903e89..41fdf3b 100644 --- a/Tests/TestHelpers/DSCTestService.cs +++ b/Tests/TestHelpers/DSCTestService.cs @@ -1,4 +1,4 @@ -namespace TestServiceNamespace +namespace TestServiceNamespace { using System; using System.ComponentModel; diff --git a/Tests/TestHelpers/DSCTestServiceNew.cs b/Tests/TestHelpers/DSCTestServiceNew.cs index 6903e89..41fdf3b 100644 --- a/Tests/TestHelpers/DSCTestServiceNew.cs +++ b/Tests/TestHelpers/DSCTestServiceNew.cs @@ -1,4 +1,4 @@ -namespace TestServiceNamespace +namespace TestServiceNamespace { using System; using System.ComponentModel; diff --git a/Tests/TestHelpers/MSFT_Archive.TestHelper.psm1 b/Tests/TestHelpers/MSFT_Archive.TestHelper.psm1 index 2b5f3ef..abd3495 100644 --- a/Tests/TestHelpers/MSFT_Archive.TestHelper.psm1 +++ b/Tests/TestHelpers/MSFT_Archive.TestHelper.psm1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' Add-Type -AssemblyName 'System.IO.Compression.FileSystem' diff --git a/Tests/TestHelpers/MSFT_GroupResource.TestHelper.psm1 b/Tests/TestHelpers/MSFT_GroupResource.TestHelper.psm1 index 5b8175a..7da19dd 100644 --- a/Tests/TestHelpers/MSFT_GroupResource.TestHelper.psm1 +++ b/Tests/TestHelpers/MSFT_GroupResource.TestHelper.psm1 @@ -1,4 +1,4 @@ - + $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' diff --git a/Tests/TestHelpers/MSFT_MsiPackageResource.TestHelper.psm1 b/Tests/TestHelpers/MSFT_MsiPackageResource.TestHelper.psm1 index b96befe..65444e5 100644 --- a/Tests/TestHelpers/MSFT_MsiPackageResource.TestHelper.psm1 +++ b/Tests/TestHelpers/MSFT_MsiPackageResource.TestHelper.psm1 @@ -1,6 +1,8 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$testJobPrefix = 'MsiPackageTestJob' + <# .SYNOPSIS Tests if the package with the given Id is installed. @@ -55,9 +57,15 @@ function Test-PackageInstalledById .PARAMETER Https Indicates whether the server should use Https. If True then the file server will use Https - and listen on port 'https://localhost:1243'. Otherwise the file server will use Http and - listen on port 'http://localhost:1242' + and listen on port 'https://localhost:HttpsPort'. Otherwise the file server will use Http and + listen on port 'http://localhost:HttpPort' Default value is False (Http). + + .PARAMETER HttpPort + Specifies the TCP port to register an Http based HttpListener on. + + .PARAMETER HttspPort + Specifies the TCP port to register an Https based HttpListener on. #> function Start-Server { @@ -74,7 +82,17 @@ function Start-Server $LogPath = (Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt'), [System.Boolean] - $Https = $false + $Https = $false, + + [Parameter(Mandatory = $true)] + [ValidateScript({$_ -gt 0})] + [System.UInt16] + $HttpPort, + + [Parameter(Mandatory = $true)] + [ValidateScript({$_ -gt 0})] + [System.UInt16] + $HttpsPort ) # Create an event object to let the client know when the server is ready to begin receiving requests. @@ -82,7 +100,7 @@ function Start-Server 'HttpIntegrationTest.FileServerStarted') $null = $fileServerStarted.Reset() - <# + <# The server is run on a separate process so that it can receive requests while the tests continue to run. It takes in the same parameterss that are passed in to this function. All helper functions that the server uses have to be @@ -90,7 +108,7 @@ function Start-Server #> $server = { - param($FilePath, $LogPath, $Https) + param($FilePath, $LogPath, $Https, $HttpPort, $HttpsPort) <# .SYNOPSIS @@ -101,6 +119,9 @@ function Start-Server .PARAMETER Https Indicates whether https was used and if so, removes the SSL binding. + + .PARAMETER HttspPort + Specifies the TCP port to de-register an Https based HttpListener from. #> function Stop-Listener { @@ -109,16 +130,21 @@ function Start-Server ( [Parameter(Mandatory = $true)] [System.Net.HttpListener] - $HttpListener, + $HttpListener, [Parameter(Mandatory = $true)] [System.Boolean] - $Https + $Https, + + [Parameter(Mandatory = $true)] + [ValidateScript({$_ -gt 0})] + [System.UInt16] + $HttpsPort ) Write-Log -LogFile $LogPath -Message 'Finished listening for requests. Shutting down HTTP server.' - - $ipPort = '0.0.0.0:1243' + + $ipPort = "0.0.0.0:$HttpsPort" if ($null -eq $HttpListener) { @@ -159,16 +185,25 @@ function Start-Server <# .SYNOPSIS Creates and registers an SSL certificate for Https connections. + + .PARAMETER HttspPort + Specifies the TCP port to register an Https based HttpListener on. #> function Register-Ssl { [CmdletBinding()] - param() + param + ( + [Parameter(Mandatory = $true)] + [ValidateScript({$_ -gt 0})] + [System.UInt16] + $HttpsPort + ) # Create certificate $certificate = New-SelfSignedCertificate -CertStoreLocation 'Cert:\LocalMachine\My' -DnsName localhost Write-Log -LogFile $LogPath -Message 'Created certificate' - + $hash = $certificate.Thumbprint $certPassword = ConvertTo-SecureString -String 'password12345' -AsPlainText -Force $tempPath = 'C:\certForTesting' @@ -176,11 +211,11 @@ function Start-Server $null = Export-PfxCertificate -Cert $certificate -FilePath $tempPath -Password $certPassword $null = Import-PfxCertificate -CertStoreLocation 'Cert:\LocalMachine\Root' -FilePath 'C:\certForTesting' -Password $certPassword Remove-Item -Path $tempPath - + Write-Log -LogFile $LogPath -Message 'Finished importing certificate into root. About to bind it to port.' - + # Use net shell command to directly bind certificate to designated testing port - $null = netsh http add sslcert ipport=0.0.0.0:1243 certhash=$hash appid='{833f13c2-319a-4799-9d1a-5b267a0c3593}' clientcertnegotiation=enable + $null = netsh http add sslcert ipport=0.0.0.0:$HttpsPort certhash=$hash appid='{833f13c2-319a-4799-9d1a-5b267a0c3593}' clientcertnegotiation=enable } <# @@ -204,32 +239,32 @@ function Start-Server # Add the CallbackEventBridge type if it's not already defined if (-not ('CallbackEventBridge' -as [Type])) { - Add-Type @' - using System; - - public sealed class CallbackEventBridge { - public event AsyncCallback CallbackComplete = delegate { }; - - private CallbackEventBridge() {} - + Add-Type @' + using System; + + public sealed class CallbackEventBridge { + public event AsyncCallback CallbackComplete = delegate { }; + + private CallbackEventBridge() {} + private void CallbackInternal(IAsyncResult result) - { - CallbackComplete(result); - } - + { + CallbackComplete(result); + } + public AsyncCallback Callback - { - get { return new AsyncCallback(CallbackInternal); } - } - + { + get { return new AsyncCallback(CallbackInternal); } + } + public static CallbackEventBridge Create() - { - return new CallbackEventBridge(); - } - } + { + return new CallbackEventBridge(); + } + } '@ } - + $bridge = [CallbackEventBridge]::Create() Register-ObjectEvent -InputObject $bridge -EventName 'CallbackComplete' -Action $Callback -MessageData $args > $null $bridge.Callback @@ -249,7 +284,7 @@ function Start-Server .PARAMETER ScriptBlock The code to execute. - + #> function Invoke-ConsoleCommand { @@ -277,7 +312,7 @@ function Start-Server $message = ('Failed action ''{0}'' on target ''{1}'' (exit code {2}): {3}' -f $Action,$Target,$LASTEXITCODE,$output) Write-Error -Message $message Write-Log -LogFile $LogPath -Message "Error from Invoke-ConsoleCommand: $message" - } + } else { $nonNullOutput = $output | Where-Object { $_ -ne $null } @@ -309,7 +344,7 @@ function Start-Server [String] $Message ) - + $Message >> $LogFile } @@ -332,11 +367,11 @@ function Start-Server # Set up the listener if ($Https) { - $HttpListener.Prefixes.Add([Uri]'https://localhost:1243') - + $HttpListener.Prefixes.Add([Uri] "https://localhost:$HttpsPort") + try { - Register-SSL + Register-SSL -HttpsPort $HttpsPort } catch { @@ -349,7 +384,7 @@ function Start-Server } else { - $HttpListener.Prefixes.Add([Uri]'http://localhost:1242') + $HttpListener.Prefixes.Add([Uri] "http://localhost:$HttpPort") } Write-Log -LogFile $LogPath -Message 'Finished listener setup - about to start listener' @@ -374,7 +409,7 @@ function Start-Server .PARAMETER Result th IAsyncResult containing the listener object and path to the MSI file. - + #> $requestListener = { @@ -450,8 +485,22 @@ function Start-Server catch { $errorMessage = "There were problems setting up the HTTP(s) listener. Error: $_" + Write-Log -LogFile $LogPath -Message $errorMessage - throw $errorMessage + + 'Error Record Info' >> $LogPath + $_ | ConvertTo-Xml -As String >> $LogPath + + 'Exception Info' >> $LogPath + $_.Exception | ConvertTo-Xml -As String >> $LogPath + + 'Running Process Info' >> $LogPath + Get-Process | Format-List | Out-String >> $LogPath + + 'Open TCP Connections Info' >> $LogPath + Get-NetTCPConnection | Format-List | Out-String >> $LogPath + + throw $_ } finally { @@ -459,19 +508,39 @@ function Start-Server { $fileServerStarted.Dispose() } - + Write-Log -LogFile $LogPath -Message 'Stopping the Server' - Stop-Listener -HttpListener $HttpListener -Https $Https + Stop-Listener -HttpListener $HttpListener -Https $Https -HttpsPort $HttpsPort } } - $job = Start-Job -ScriptBlock $server -ArgumentList @( $FilePath, $LogPath, $Https ) + if ($Https) + { + $jobName = $testJobPrefix + 'Https' + } + else + { + $jobName = $testJobPrefix + 'Http' + } + + $job = Start-Job -ScriptBlock $server -Name $jobName -ArgumentList @( $FilePath, $LogPath, $Https, $HttpPort, $HttpsPort ) + + # Verify that the job is receivable and does not contain an exception. If it does, re-throw it. + try + { + $receivedJob = $job | Receive-Job + } + catch + { + Write-Error -Message 'Failed to setup HTTP(S) listener for MsiPackage Tests' + throw $_ + } <# - Return the event object so that client knows when it can start sending requests and + Return the event object so that client knows when it can start sending requests and the job object so that the client can stop the job once it is done sending requests. #> - return @{ + return @{ FileServerStarted = $fileServerStarted Job = $job } @@ -501,7 +570,7 @@ function Stop-Server $FileServerStarted, [System.Management.Automation.Job] - $Job + $Job ) if ($null -ne $FileServerStarted) @@ -516,6 +585,20 @@ function Stop-Server } } +<# + .SYNOPSIS + Removes any jobs associated with HTTP(S) servers that were created + for MsiPackage tests. +#> +function Stop-EveryTestServerInstance +{ + [CmdletBinding()] + param () + + Get-Job -Name "$($testJobPrefix)*" | Stop-Job + Get-Job -Name "$($testJobPrefix)*" | Remove-Job +} + <# .SYNOPSIS Creates a new MSI package for testing. @@ -526,7 +609,7 @@ function Stop-Server function New-TestMsi { [CmdletBinding()] - param + param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -1061,4 +1144,5 @@ Export-ModuleMember -Function ` New-TestMsi, ` Start-Server, ` Stop-Server, ` - Test-PackageInstalledById + Test-PackageInstalledById, ` + Stop-EveryTestServerInstance diff --git a/Tests/TestHelpers/MSFT_UserResource.TestHelper.psm1 b/Tests/TestHelpers/MSFT_UserResource.TestHelper.psm1 index 1ed7d5a..a6873c3 100644 --- a/Tests/TestHelpers/MSFT_UserResource.TestHelper.psm1 +++ b/Tests/TestHelpers/MSFT_UserResource.TestHelper.psm1 @@ -1,4 +1,4 @@ -Import-Module "$PSScriptRoot\..\..\DSCResources\CommonResourceHelper.psm1" -Force +Import-Module "$PSScriptRoot\..\..\DSCResources\CommonResourceHelper.psm1" -Force <# .SYNOPSIS diff --git a/Tests/TestHelpers/WMF5Dot1Installation.psm1 b/Tests/TestHelpers/WMF5Dot1Installation.psm1 index 6fb8af7..8b35ca7 100644 --- a/Tests/TestHelpers/WMF5Dot1Installation.psm1 +++ b/Tests/TestHelpers/WMF5Dot1Installation.psm1 @@ -1,4 +1,4 @@ -Set-StrictMode -Version 'latest' +Set-StrictMode -Version 'latest' $errorActionPreference = 'Stop' <# diff --git a/Tests/TestHelpers/WindowsProcessTestProcess.cs b/Tests/TestHelpers/WindowsProcessTestProcess.cs index ceb28b5..d3050f7 100644 --- a/Tests/TestHelpers/WindowsProcessTestProcess.cs +++ b/Tests/TestHelpers/WindowsProcessTestProcess.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Threading; // This is a test process used for testing configuring running and stopping a process on a machine diff --git a/Tests/Unit/CommonResourceHelper.Tests.ps1 b/Tests/Unit/CommonResourceHelper.Tests.ps1 index 241c18f..49a7bac 100644 --- a/Tests/Unit/CommonResourceHelper.Tests.ps1 +++ b/Tests/Unit/CommonResourceHelper.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' Describe 'CommonResourceHelper Unit Tests' { @@ -14,112 +14,38 @@ Describe 'CommonResourceHelper Unit Tests' { InModuleScope 'CommonResourceHelper' { Describe 'Test-IsNanoServer' { $testComputerInfoNanoServer = @{ - OsProductType = 'Server' - OsServerLevel = 'NanoServer' + NanoServer = 1 } $testComputerInfoServerNotNano = @{ - OsProductType = 'Server' - OsServerLevel = 'NotNano' } - $testComputerInfoNotServer = @{ - OsProductType = 'NotServer' - OsServerLevel = 'NotNano' - } - - Mock -CommandName 'Test-CommandExists' -MockWith { return $true } - Mock -CommandName 'Get-ComputerInfo' -MockWith { return $testComputerInfoNanoServer } - - Context 'Get-ComputerInfo command exists and succeeds' { - Context 'Computer OS type is Server and OS server level is NanoServer' { - It 'Should not throw' { - { $null = Test-IsNanoServer } | Should -Not -Throw - } - - It 'Should test if the Get-ComputerInfo command exists' { - $testCommandExistsParameterFilter = { - return $Name -eq 'Get-ComputerInfo' - } - - Assert-MockCalled -CommandName 'Test-CommandExists' -ParameterFilter $testCommandExistsParameterFilter -Exactly 1 -Scope 'Context' - } - - It 'Should retrieve the computer info' { - Assert-MockCalled -CommandName 'Get-ComputerInfo' -Exactly 1 -Scope 'Context' - } - - It 'Should return true' { - Test-IsNanoServer | Should -Be $true - } + Context 'Computer OS type is Server and OS server level is NanoServer' { + Mock -CommandName 'Test-Path' -MockWith { return $true } + Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoNanoServer } + It 'Should not throw' { + { $null = Test-IsNanoServer } | Should -Not -Throw } - Context 'Computer OS type is Server and OS server level is not NanoServer' { - Mock -CommandName 'Get-ComputerInfo' -MockWith { return $testComputerInfoServerNotNano } - - It 'Should not throw' { - { $null = Test-IsNanoServer } | Should -Not -Throw - } - - It 'Should test if the Get-ComputerInfo command exists' { - $testCommandExistsParameterFilter = { - return $Name -eq 'Get-ComputerInfo' - } - - Assert-MockCalled -CommandName 'Test-CommandExists' -ParameterFilter $testCommandExistsParameterFilter -Exactly 1 -Scope 'Context' - } - - It 'Should retrieve the computer info' { - Assert-MockCalled -CommandName 'Get-ComputerInfo' -Exactly 1 -Scope 'Context' - } - - It 'Should return false' { - Test-IsNanoServer | Should -Be $false - } + It 'Should check the ServerLevels registry path' { + Assert-MockCalled -CommandName 'Get-ItemProperty' -Exactly 1 -Scope 'Context' } - Context 'Computer OS type is not Server' { - Mock -CommandName 'Get-ComputerInfo' -MockWith { return $testComputerInfoNotServer } - - It 'Should not throw' { - { $null = Test-IsNanoServer } | Should -Not -Throw - } - - It 'Should test if the Get-ComputerInfo command exists' { - $testCommandExistsParameterFilter = { - return $Name -eq 'Get-ComputerInfo' - } - - Assert-MockCalled -CommandName 'Test-CommandExists' -ParameterFilter $testCommandExistsParameterFilter -Exactly 1 -Scope 'Context' - } - - It 'Should retrieve the computer info' { - Assert-MockCalled -CommandName 'Get-ComputerInfo' -Exactly 1 -Scope 'Context' - } - - It 'Should return false' { - Test-IsNanoServer | Should -Be $false - } + It 'Should return true' { + Test-IsNanoServer | Should -Be $true } } - Context 'Get-ComputerInfo command exists but throws an error and returns null' { - Mock -CommandName 'Get-ComputerInfo' -MockWith { return $null } + Context 'Computer OS type is Server and OS server level is not NanoServer' { + Mock -CommandName 'Test-Path' -MockWith { return $true } + Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoServerNotNano } It 'Should not throw' { { $null = Test-IsNanoServer } | Should -Not -Throw } - It 'Should test if the Get-ComputerInfo command exists' { - $testCommandExistsParameterFilter = { - return $Name -eq 'Get-ComputerInfo' - } - - Assert-MockCalled -CommandName 'Test-CommandExists' -ParameterFilter $testCommandExistsParameterFilter -Exactly 1 -Scope 'Context' - } - - It 'Should retrieve the computer info' { - Assert-MockCalled -CommandName 'Get-ComputerInfo' -Exactly 1 -Scope 'Context' + It 'Should check the ServerLevels registry path' { + Assert-MockCalled -CommandName 'Get-ItemProperty' -Exactly 1 -Scope 'Context' } It 'Should return false' { @@ -127,23 +53,15 @@ Describe 'CommonResourceHelper Unit Tests' { } } - Context 'Get-ComputerInfo command does not exist' { - Mock -CommandName 'Test-CommandExists' -MockWith { return $false } + Context 'Computer OS type is not Server' { + Mock -CommandName 'Test-Path' -MockWith { return $false } It 'Should not throw' { { $null = Test-IsNanoServer } | Should -Not -Throw } - It 'Should test if the Get-ComputerInfo command exists' { - $testCommandExistsParameterFilter = { - return $Name -eq 'Get-ComputerInfo' - } - - Assert-MockCalled -CommandName 'Test-CommandExists' -ParameterFilter $testCommandExistsParameterFilter -Exactly 1 -Scope 'Context' - } - - It 'Should not attempt to retrieve the computer info' { - Assert-MockCalled -CommandName 'Get-ComputerInfo' -Exactly 0 -Scope 'Context' + It 'Should check the ServerLevels registry path' { + Assert-MockCalled -CommandName 'Test-Path' -Exactly 1 -Scope 'Context' } It 'Should return false' { diff --git a/Tests/Unit/MSFT_EnvironmentResource.Tests.ps1 b/Tests/Unit/MSFT_EnvironmentResource.Tests.ps1 index 2c78453..7b55ca9 100644 --- a/Tests/Unit/MSFT_EnvironmentResource.Tests.ps1 +++ b/Tests/Unit/MSFT_EnvironmentResource.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment diff --git a/Tests/Unit/MSFT_MsiPackage.Tests.ps1 b/Tests/Unit/MSFT_MsiPackage.Tests.ps1 index 8516b3c..2238883 100644 --- a/Tests/Unit/MSFT_MsiPackage.Tests.ps1 +++ b/Tests/Unit/MSFT_MsiPackage.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' Describe 'MsiPackage Unit Tests' { @@ -123,7 +123,7 @@ Describe 'MsiPackage Unit Tests' { -ExpectedReturnValue $expectedReturnValue } } - + Describe 'Set-TargetResource' { $setTargetResourceParameters = @{ ProductId = 'TestProductId' @@ -138,7 +138,7 @@ Describe 'MsiPackage Unit Tests' { ServerCertificateValidationCallback = 'TestValidationCallback' RunAsCredential = $script:testCredential } - + Mock -CommandName 'Convert-PathToUri' -MockWith { return $script:testUriNonUnc } Mock -CommandName 'Convert-ProductIdToIdentifyingNumber' -MockWith { return $script:testIdentifyingNumber } Mock -CommandName 'Assert-PathExtensionValid' -MockWith {} @@ -158,7 +158,7 @@ Describe 'MsiPackage Unit Tests' { Mock -CommandName 'Invoke-CimMethod' -MockWith {} Mock -CommandName 'Get-ItemProperty' -MockWith { return $null } Mock -CommandName 'Get-ProductEntry' -MockWith { return $script:mockProductEntry } - + Context 'Uri scheme is non-UNC file and installation succeeds' { $mocksCalled = @( @{ Command = 'Convert-PathToUri'; Times = 1 } @@ -219,13 +219,13 @@ Describe 'MsiPackage Unit Tests' { @{ Command = 'Assert-PathExtensionValid'; Times = 1 } @{ Command = 'New-LogFile'; Times = 1 } @{ Command = 'New-PSDrive'; Times = 0 } - @{ Command = 'Test-Path'; Times = 2; Custom = 'to the package cache' } + @{ Command = 'Test-Path'; Times = 3; Custom = 'to the package cache' } @{ Command = 'New-Item'; Times = 0; Custom = 'directory for the package cache' } @{ Command = 'New-Object'; Times = 1; Custom = 'file stream to copy the response to' } @{ Command = 'Get-WebRequestResponse'; Times = 1 } @{ Command = 'Copy-ResponseStreamToFileStream'; Times = 1 } @{ Command = 'Close-Stream'; Times = 2 } - @{ Command = 'Test-Path'; Times = 2; Custom = 'to the MSI file' } + @{ Command = 'Test-Path'; Times = 3; Custom = 'to the MSI file' } @{ Command = 'Assert-FileValid'; Times = 1 } @{ Command = 'Get-MsiProductCode'; Times = 1 } @{ Command = 'Start-MsiProcess'; Times = 1 } @@ -250,13 +250,13 @@ Describe 'MsiPackage Unit Tests' { @{ Command = 'Assert-PathExtensionValid'; Times = 1 } @{ Command = 'New-LogFile'; Times = 1 } @{ Command = 'New-PSDrive'; Times = 0 } - @{ Command = 'Test-Path'; Times = 2; Custom = 'to the package cache' } + @{ Command = 'Test-Path'; Times = 3; Custom = 'to the package cache' } @{ Command = 'New-Item'; Times = 0; Custom = 'directory for the package cache' } @{ Command = 'New-Object'; Times = 1; Custom = 'file stream to copy the response to' } @{ Command = 'Get-WebRequestResponse'; Times = 1 } @{ Command = 'Copy-ResponseStreamToFileStream'; Times = 1 } @{ Command = 'Close-Stream'; Times = 2 } - @{ Command = 'Test-Path'; Times = 2; Custom = 'to the MSI file' } + @{ Command = 'Test-Path'; Times = 3; Custom = 'to the MSI file' } @{ Command = 'Assert-FileValid'; Times = 1 } @{ Command = 'Get-MsiProductCode'; Times = 1 } @{ Command = 'Start-MsiProcess'; Times = 1 } @@ -349,7 +349,7 @@ Describe 'MsiPackage Unit Tests' { -ErrorMessage ($script:localizedData.PostValidationError -f $setTargetResourceParameters.Path) ` -ErrorTestName $script:errorMessageTitles.PostValidationError } - + Mock -CommandName 'Get-MsiProductCode' -MockWith { return $script:testWrongProductId } Context 'Product code from downloaded MSI package does not match specified ID' { @@ -491,25 +491,27 @@ Describe 'MsiPackage Unit Tests' { Convert-PathToUri -Path $filePath | Should Be $expectedReturnValue } - + It 'Should return the expected URI when scheme is http' { - $filePath = 'http://localhost:1242/testMsi.msi' - $expectedReturnValue = [Uri] $filePath + $uriBuilder = [System.UriBuilder]::new('http', 'localhost') + $uriBuilder.Path = 'testMsi.msi' + $filePath = $uriBuilder.Uri.AbsoluteUri - Convert-PathToUri -Path $filePath | Should Be $expectedReturnValue + Convert-PathToUri -Path $filePath | Should Be $uriBuilder.Uri } It 'Should return the expected URI when scheme is https' { - $filePath = 'https://localhost:1243/testMsi.msi' - $expectedReturnValue = [Uri] $filePath + $uriBuilder = [System.UriBuilder]::new('https', 'localhost') + $uriBuilder.Path = 'testMsi.msi' + $filePath = $uriBuilder.Uri.AbsoluteUri - Convert-PathToUri -Path $filePath | Should Be $expectedReturnValue + Convert-PathToUri -Path $filePath | Should Be $uriBuilder.Uri } } Context 'Invalid path passed in' { It 'Should throw an error when uri scheme is invalid' { - $filePath = 'ht://localhost:1243/testMsi.msi' + $filePath = 'ht://localhost/testMsi.msi' $expectedErrorMessage = ($script:localizedData.InvalidPath -f $filePath) { Convert-PathToUri -Path $filePath } | Should Throw $expectedErrorMessage @@ -686,7 +688,7 @@ Describe 'MsiPackage Unit Tests' { -ErrorTestName $script:errorMessageTitles.CouldNotOpenLog } } - + Describe 'Get-WebRequestResponse' { Mock -CommandName 'Get-WebRequest' -MockWith { return $script:mockWebRequest } Mock -CommandName 'Get-ScriptBlock' -MockWith { return { Write-Verbose 'Hello World' } } @@ -702,7 +704,7 @@ Describe 'MsiPackage Unit Tests' { It 'Should return the expected response stream' { Get-WebRequestResponse -Uri $script:testUriHttp | Should Be $script:mockStream } - + Invoke-ExpectedMocksAreCalledTest -MocksCalled $mocksCalled } @@ -716,7 +718,7 @@ Describe 'MsiPackage Unit Tests' { It 'Should return the expected response stream' { Get-WebRequestResponse -Uri $script:testUriHttps | Should Be $script:mockStream } - + Invoke-ExpectedMocksAreCalledTest -MocksCalled $mocksCalled } @@ -859,7 +861,7 @@ Describe 'MsiPackage Unit Tests' { Describe 'Assert-FileSignatureValid' { $mockThumbprint = 'mockThumbprint' $mockSubject = 'mockSubject' - $mockSignature = @{ + $mockSignature = @{ Status = [System.Management.Automation.SignatureStatus]::Valid SignerCertificate = @{ Thumbprint = $mockThumbprint; Subject = $mockSubject } } diff --git a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 index 9e899f9..d49eda0 100644 --- a/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsPackageCab.Tests.ps1 @@ -1,4 +1,4 @@ -$errorActionPreference = 'Stop' +$errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' $script:testFolderPath = Split-Path -Path $PSScriptRoot -Parent diff --git a/Tests/Unit/MSFT_WindowsProcess.Tests.ps1 b/Tests/Unit/MSFT_WindowsProcess.Tests.ps1 index 2f88da3..eed2e5b 100644 --- a/Tests/Unit/MSFT_WindowsProcess.Tests.ps1 +++ b/Tests/Unit/MSFT_WindowsProcess.Tests.ps1 @@ -1,4 +1,4 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () $errorActionPreference = 'Stop' diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 6459b9c..3ec0627 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -1,4 +1,4 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] param () $errorActionPreference = 'Stop' From eeddbba110032bcc38d5851add1436d294619834 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 30 Apr 2019 20:53:17 +0100 Subject: [PATCH 13/24] Fix Example Configuration Names --- ..._MsiPackage_UninstallPackageFromHttps.ps1} | 0 Examples/Sample_Script.ps1 | 2 +- Examples/Sample_ServiceSet_BuiltInAccount.ps1 | 2 +- Examples/Sample_ServiceSet_StartServices.ps1 | 2 +- Examples/Sample_User_CreateUser.ps1 | 2 +- Examples/Sample_User_Generic.ps1 | 27 +++++++------------ Examples/Sample_WindowsFeature.ps1 | 2 +- Examples/Sample_WindowsFeatureSet_Install.ps1 | 2 +- .../Sample_WindowsFeatureSet_Uninstall.ps1 | 2 +- ...mple_WindowsOptionalFeatureSet_Disable.ps1 | 2 +- ...ample_WindowsOptionalFeatureSet_Enable.ps1 | 2 +- 11 files changed, 19 insertions(+), 26 deletions(-) rename Examples/{Sample_MsiPackage_UnstallPackageFromHttps.ps1 => Sample_MsiPackage_UninstallPackageFromHttps.ps1} (100%) diff --git a/Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 b/Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 similarity index 100% rename from Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 rename to Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 diff --git a/Examples/Sample_Script.ps1 b/Examples/Sample_Script.ps1 index e086cf7..013d2bc 100644 --- a/Examples/Sample_Script.ps1 +++ b/Examples/Sample_Script.ps1 @@ -8,7 +8,7 @@ .PARAMETER FileContent The content to set for the new file. #> -Configuration ScriptExample { +Configuration Sample_Script { [CmdletBinding()] param ( diff --git a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 index 79c7820..c614dc3 100644 --- a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 +++ b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 @@ -3,7 +3,7 @@ Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the built-in account LocalService. #> -Configuration ServiceSetBuiltInAccountExample +Configuration Sample_ServiceSet_BuiltInAccount { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_ServiceSet_StartServices.ps1 b/Examples/Sample_ServiceSet_StartServices.ps1 index 1ac00dd..08c932b 100644 --- a/Examples/Sample_ServiceSet_StartServices.ps1 +++ b/Examples/Sample_ServiceSet_StartServices.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Ensures that the DHCP Client and Windows Firewall services are running. #> -Configuration ServiceSetStartExample +Configuration Sample_ServiceSet_StartServices { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index fc75587..6b65cae 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,4 +1,4 @@ -Configuration UserExample +Configuration Sample_User_CreateUser { param ( [System.Management.Automation.PSCredential] diff --git a/Examples/Sample_User_Generic.ps1 b/Examples/Sample_User_Generic.ps1 index bd44a8d..134a510 100644 --- a/Examples/Sample_User_Generic.ps1 +++ b/Examples/Sample_User_Generic.ps1 @@ -1,10 +1,3 @@ -param -( - [Parameter(Mandatory)] - [System.String] - $ConfigurationName -) - <# Create a custom configuration by passing in whatever values you need. $Password is the only param that is @@ -14,28 +7,28 @@ param are optional. #> -Configuration $ConfigurationName +Configuration Sample_User_Generic { - param - ( + param + ( [System.String] $UserName = 'Test UserName', - + [System.String] $Description = 'Test Description', - + [System.String] $FullName = 'Test Full Name', - + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present', - + [Parameter(Mandatory = $true)] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Password, - + [System.Boolean] $Disabled = $false, @@ -48,9 +41,9 @@ Configuration $ConfigurationName [System.Boolean] $PasswordChangeNotAllowed = $false ) - + Import-DscResource -ModuleName 'PSDscResources' - + Node Localhost { User UserResource1 diff --git a/Examples/Sample_WindowsFeature.ps1 b/Examples/Sample_WindowsFeature.ps1 index db23f46..4e6ad0c 100644 --- a/Examples/Sample_WindowsFeature.ps1 +++ b/Examples/Sample_WindowsFeature.ps1 @@ -30,7 +30,7 @@ in this configuration file currently. #> -Configuration 'Install_Feature_Telnet_Client' +Configuration Sample_WindowsFeature { param ( diff --git a/Examples/Sample_WindowsFeatureSet_Install.ps1 b/Examples/Sample_WindowsFeatureSet_Install.ps1 index 48aeb95..6653bcc 100644 --- a/Examples/Sample_WindowsFeatureSet_Install.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Install.ps1 @@ -3,7 +3,7 @@ Installs the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Install { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 index eb8ecdf..45261bf 100644 --- a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 @@ -3,7 +3,7 @@ Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Uninstall { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 index ea8eb61..dc8accc 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 @@ -3,7 +3,7 @@ Disables the Windows optional features TelnetClient and LegacyComponents and removes all files associated with these features. #> -Configuration WindowsOptionalFeatureSet_Disable +Configuration Sample_WindowsOptionalFeatureSet_Disable { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 index 16fb179..68d9535 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 @@ -4,7 +4,7 @@ Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path 'C:\LogPath\Log.txt'. #> -Configuration WindowsOptionalFeatureSet_Enable +Configuration Sample_WindowsOptionalFeatureSet_Enable { Import-DscResource -ModuleName 'PSDscResources' From 380cdb81b262c0397056c24974c61ed65b4e6c10 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 30 Apr 2019 21:03:23 +0100 Subject: [PATCH 14/24] Add MetaTestOptIn file --- .MetaTestOptIn.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index f6b4bc5..000f052 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -1,4 +1,5 @@ [ "Common Tests - Validate Module Files", - "Common Tests - Validate Script Files" + "Common Tests - Validate Script Files", + "Common Tests - Validate Example Files" ] From 8e6abcb77b000f8285ccb434ecab92c1bcdb198d Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:22:56 +0100 Subject: [PATCH 15/24] Sample_User_CreateUser changes: - Rename PasswordCredential for opt-in tests - Add Mandatory parameter and ValidateNotNullorEmpty - Add Node localhost - Fix formatting --- Examples/Sample_User_CreateUser.ps1 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index 6b65cae..43fdf60 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,16 +1,22 @@ Configuration Sample_User_CreateUser { - param ( + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullorEmpty()] [System.Management.Automation.PSCredential] - $PasswordCredential + $Credential ) Import-DscResource -ModuleName PSDscResources - User UserExample + Node localhost { - Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" - UserName = 'SomeUserName' - Password = $PasswordCredential # This needs to be a credential object + User UserExample + { + Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" + UserName = 'SomeUserName' + Password = $Credential # This needs to be a credential object + } } } From a1712d1a184bc1a727d5210c531cfc2d08b40079 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:25:08 +0100 Subject: [PATCH 16/24] Sample_WindowsPackageCab changes for example tests - Remove configuration call - Fix formatting - Add Node localhost --- Examples/Sample_WindowsPackageCab.ps1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Examples/Sample_WindowsPackageCab.ps1 b/Examples/Sample_WindowsPackageCab.ps1 index 656a4bf..80a2eea 100644 --- a/Examples/Sample_WindowsPackageCab.ps1 +++ b/Examples/Sample_WindowsPackageCab.ps1 @@ -37,13 +37,14 @@ Configuration Sample_WindowsPackageCab Import-DscResource -ModuleName 'PSDscResources' - WindowsPackageCab WindowsPackageCab1 + Node localhost { - Name = $Name - Ensure = 'Present' - SourcePath = $SourcePath - LogPath = $LogPath + WindowsPackageCab WindowsPackageCab1 + { + Name = $Name + Ensure = 'Present' + SourcePath = $SourcePath + LogPath = $LogPath + } } } - -Sample_WindowsPackageCab From 66f9f130ebc191842afc0bfed00e6b7a0c8c6c02 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 1 May 2019 21:37:36 +0100 Subject: [PATCH 17/24] Sample_WindowsOptionalFeature Changes - Add ValidateNotNullOrEmpty to mandatory parameters - Add Node localhost - Remove configuration call - Fix formatting - Rename incorrect resource name --- Examples/Sample_WindowsOptionalFeature.ps1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Examples/Sample_WindowsOptionalFeature.ps1 b/Examples/Sample_WindowsOptionalFeature.ps1 index 151ba55..8abdc19 100644 --- a/Examples/Sample_WindowsOptionalFeature.ps1 +++ b/Examples/Sample_WindowsOptionalFeature.ps1 @@ -17,22 +17,25 @@ Configuration Sample_WindowsOptionalFeature param ( [Parameter (Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $FeatureName, [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $LogPath ) Import-DscResource -ModuleName 'PSDscResources' - WindowsOptionalFeature TelnetClient + Node localhost { - Name = $FeatureName - Ensure = 'Present' - LogPath = $LogPath + WindowsOptionalFeature FeatureExample + { + Name = $FeatureName + Ensure = 'Present' + LogPath = $LogPath + } } } - -Sample_WindowsOptionalFeature From 841afa05d6e0c6e2e312b0680e727ab138bece71 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 11:36:58 +0100 Subject: [PATCH 18/24] Fix Pester 'Multiple Script Modules' error --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 3ec0627..1c16e03 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -8,6 +8,12 @@ $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' + +# Remove module if it is already imported before re-import +If (Get-Module $script:resourceSetHelperFilePath) +{ + Remove-Module $script:resourceSetHelperFilePath +} Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' { From 98ee363189d01c6176ad61eb41dfdab7faf541a2 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 15:21:13 +0100 Subject: [PATCH 19/24] Add resourceSetHelpName var --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 1c16e03..3c3771d 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,15 +4,16 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$resourceSetHelperName = 'ResourceSetHelper.psm1' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName # Remove module if it is already imported before re-import -If (Get-Module $script:resourceSetHelperFilePath) +If (Get-Module $resourceSetHelperName) { - Remove-Module $script:resourceSetHelperFilePath + Remove-Module $resourceSetHelperName } Import-Module -Name $script:resourceSetHelperFilePath From 15828e91af5315cb66fa364e057fa51bca03d6f8 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 18:05:53 +0100 Subject: [PATCH 20/24] Fix resourceSetHelpName var --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 3c3771d..3ddcf81 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,11 +4,11 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' -$resourceSetHelperName = 'ResourceSetHelper.psm1' +$resourceSetHelperName = 'ResourceSetHelper' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' # Remove module if it is already imported before re-import If (Get-Module $resourceSetHelperName) From 6be1629e25f625780b3586aa0ed0e0defb737eb6 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 18:15:29 +0100 Subject: [PATCH 21/24] Force integration test re-run --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 3ddcf81..846627b 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -10,7 +10,7 @@ $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Paren $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' -# Remove module if it is already imported before re-import +# Remove module if it is already imported before re-import. If (Get-Module $resourceSetHelperName) { Remove-Module $resourceSetHelperName From f77ce1f1b76a016488c77e0779e7ea40418b2b84 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 21:16:54 +0100 Subject: [PATCH 22/24] resourceSetHelpFilePath fix --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 846627b..e14dc08 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -8,7 +8,7 @@ $resourceSetHelperName = 'ResourceSetHelper' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath $resourceSetHelperName+'.psm1' +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') # Remove module if it is already imported before re-import. If (Get-Module $resourceSetHelperName) From e602741c8f0e22bf28e6f39559a2bb2fae955cc1 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 4 May 2019 21:55:38 +0100 Subject: [PATCH 23/24] Test: Disable import-module ResourceSetHelper --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index e14dc08..e9c7038 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -11,11 +11,11 @@ $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') # Remove module if it is already imported before re-import. -If (Get-Module $resourceSetHelperName) -{ - Remove-Module $resourceSetHelperName -} -Import-Module -Name $script:resourceSetHelperFilePath +#If (Get-Module $resourceSetHelperName) +#{ +# Remove-Module $resourceSetHelperName +#} +#Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' { Describe 'ResourceSetHelper\New-ResourceSetCommonParameterString' { From d2a97d846c7ee573af1bcd4cc283d24ada6b58bd Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 4 Jun 2019 08:13:26 +0100 Subject: [PATCH 24/24] Revert ResourceSetHelper.Ttests change --- Tests/Unit/ResourceSetHelper.Tests.ps1 | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index e9c7038..137243e 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -9,13 +9,7 @@ $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') - -# Remove module if it is already imported before re-import. -#If (Get-Module $resourceSetHelperName) -#{ -# Remove-Module $resourceSetHelperName -#} -#Import-Module -Name $script:resourceSetHelperFilePath +Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' { Describe 'ResourceSetHelper\New-ResourceSetCommonParameterString' { @@ -24,7 +18,7 @@ InModuleScope 'ResourceSetHelper' { Name = 'Name' CommonStringParameter1 = 'CommonParameter1' } - + $keyParameterName = 'Name' $commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $keyParameterName -Parameters $parameters @@ -34,12 +28,12 @@ InModuleScope 'ResourceSetHelper' { It 'Should return string containing one variable reference for one credential common parameter' { $testUserName = 'testUserName' $secureTestPassword = ConvertTo-SecureString -String 'testPassword' -AsPlainText -Force - + $parameters = @{ Name = 'Name' CommonCredentialParameter1 = New-Object -TypeName 'PSCredential' -ArgumentList @( $testUsername, $secureTestPassword ) } - + $keyParameterName = 'Name' $commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $keyParameterName -Parameters $parameters @@ -107,7 +101,7 @@ InModuleScope 'ResourceSetHelper' { CommonParameter2 = 'CommonParameterValue2' } } - + $newResourceSetConfigurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams It 'Should return a ScriptBlock' {