diff --git a/README.md b/README.md index cba536a..d490483 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,9 @@ 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. + [Issue #142](https://github.com/PowerShell/PSDscResources/issues/142) * Fix Custom DSC Resource Kit PSSA Rule Failures ### 2.10.0.0 diff --git a/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 b/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 index 5abf0a9..185bf03 100644 --- a/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 +++ b/Tests/Integration/MSFT_MsiPackage.EndToEnd.Tests.ps1 @@ -13,6 +13,14 @@ if ($PSVersionTable.PSVersion -lt [Version] '5.1') return } +$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent +$testHelperFolderFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'TestHelpers' +$commonTestHelperFilePath = Join-Path -Path $testHelperFolderFilePath -ChildPath 'CommonTestHelper.psm1' +Import-Module -Name $script:commonTestHelperFilePath + +# Make sure strong crypto is enabled in .NET for HTTPS tests +Enable-StrongCryptoForDotNetFour + Describe 'MsiPackage End to End Tests' { BeforeAll { # Import CommonTestHelper diff --git a/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 b/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 index 740f9bf..bc35800 100644 --- a/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_MsiPackage.Integration.Tests.ps1 @@ -17,6 +17,9 @@ $script:testEnvironment = Enter-DscResourceTestEnvironment ` -DscResourceName 'MSFT_MsiPackage' ` -TestType 'Unit' +# Make sure strong crypto is enabled in .NET for HTTPS tests +Enable-StrongCryptoForDotNetFour + try { InModuleScope 'MSFT_MsiPackage' { diff --git a/Tests/TestHelpers/CommonTestHelper.psm1 b/Tests/TestHelpers/CommonTestHelper.psm1 index c5671e9..96538c3 100644 --- a/Tests/TestHelpers/CommonTestHelper.psm1 +++ b/Tests/TestHelpers/CommonTestHelper.psm1 @@ -790,6 +790,46 @@ function Exit-DscResourceTestEnvironment Restore-TestEnvironment -TestEnvironment $TestEnvironment } +<# + .SYNOPSIS + Enables strong crypto for .NET v4.0.30319 +#> +function Enable-StrongCryptoForDotNetFour +{ + [OutputType([System.Boolean])] + [CmdletBinding()] + param() + + $regBases = @( + 'HKLM:\SOFTWARE\Microsoft' + 'HKLM:\SOFTWARE\Wow6432Node' + ) + + $net4Suffix = 'Microsoft\.NetFramework\v4.0.30319' + + foreach ($regBase in $regBases) + { + $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 + + if ($null -eq $useStrongCryptoProp -or $useStrongCryptoProp.SchUseStrongCrypto -ne 1) + { + 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." + continue + } + } +} + Export-ModuleMember -Function @( 'Test-GetTargetResourceResult', ` 'Wait-ScriptBlockReturnTrue', ` @@ -802,5 +842,6 @@ Export-ModuleMember -Function @( 'Invoke-SetTargetResourceUnitTest', ` 'Invoke-TestTargetResourceUnitTest', ` 'Invoke-ExpectedMocksAreCalledTest', ` - 'Invoke-GenericUnitTest' + 'Invoke-GenericUnitTest', + 'Enable-StrongCryptoForDotNetFour' )