From e71e0627c0f077f1cbf632bf8a7e4e8e141854cf Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Sat, 2 Dec 2017 05:39:04 -0600 Subject: [PATCH 1/7] Fix Get-EnvironmentInformation IsCoreCLR logic (#5592) * Fix Get-EnvironmentInformation IsCoreCLR logic Replace $Runtime = [System.Runtime.InteropServices.RuntimeInformation] and $OSPlatform = [System.Runtime.InteropServices.OSPlatform] with ($PSVersionTable.ContainsKey("PSEdition") -and $PSVersionTable.PSEdition -eq "Core"). --- build.psm1 | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/build.psm1 b/build.psm1 index 9c97a4e65ef..a51eb6d47b5 100644 --- a/build.psm1 +++ b/build.psm1 @@ -97,19 +97,13 @@ function Get-PSCommitId function Get-EnvironmentInformation { $environment = @{} - # Use the .NET Core APIs to determine the current platform. - # If a runtime exception is thrown, we are on Windows PowerShell, not PowerShell Core, - # because System.Runtime.InteropServices.RuntimeInformation - # and System.Runtime.InteropServices.OSPlatform do not exist in Windows PowerShell. - try { - $Runtime = [System.Runtime.InteropServices.RuntimeInformation] - $OSPlatform = [System.Runtime.InteropServices.OSPlatform] - + # PowerShell Core will likely not be built on pre-1709 nanoserver + if ($PSVersionTable.ContainsKey("PSEdition") -and "Core" -eq $PSVersionTable.PSEdition) { $environment += @{'IsCoreCLR' = $true} - $environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)} - $environment += @{'IsMacOS' = $Runtime::IsOSPlatform($OSPlatform::OSX)} - $environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)} - } catch { + $environment += @{'IsLinux' = $IsLinux} + $environment += @{'IsMacOS' = $IsMacOS} + $environment += @{'IsWindows' = $IsWindows} + } else { $environment += @{'IsCoreCLR' = $false} $environment += @{'IsLinux' = $false} $environment += @{'IsMacOS' = $false} From 0c4f3be3b3077b4d70929bb6a625736496f931be Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Mon, 4 Dec 2017 11:52:14 -0600 Subject: [PATCH 2/7] Replace HttpListener Response Tests with WebListener (#5540) * Add Response Controller * [Feature] Replace HttpListener Response tests with WebListener --- .../WebCmdlets.Tests.ps1 | 528 ++++++------------ .../Modules/WebListener/WebListener.psm1 | 1 + test/tools/WebListener/Constants.cs | 6 + .../Controllers/ResponseController.cs | 103 ++++ test/tools/WebListener/README.md | 35 ++ .../tools/WebListener/Views/Home/Index.cshtml | 1 + 6 files changed, 328 insertions(+), 346 deletions(-) create mode 100644 test/tools/WebListener/Controllers/ResponseController.cs diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 656d0bec69f..9cd0ae22d18 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -788,7 +788,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { It "Validate Invoke-WebRequest returns empty RelationLink property if there is no Link Header" { - $command = "Invoke-WebRequest -Uri http://localhost:8080/PowerShell?test=response" + $uri = $uri = Get-WebListenerUrl -Test 'Get' + $command = "Invoke-WebRequest -Uri '$uri'" $result = ExecuteWebCommand -command $command $result.Output.RelationLink.Count | Should Be 0 @@ -805,14 +806,18 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # Test pending support for multiple header capable server on Linux/macOS see issue #4639 It "Validate Invoke-WebRequest returns valid RelationLink property with absolute uris if Multiple Link Headers are present" -Pending:$(!$IsWindows){ - $headers = @{ - Link = - '; rel="self"', - '; rel="next"', - '; rel="last"' - } | ConvertTo-Json -Compress - $headers = [uri]::EscapeDataString($headers) - $uri = "http://localhost:8080/PowerShell?test=response&contenttype=text/plain&output=OK&headers=$headers" + $Query = @{ + body = "ok" + contenttype = 'text/plain' + headers = @{ + Link = @( + '; rel="self"' + '; rel="next"' + '; rel="last"' + ) + } | ConvertTo-Json -Compress + } + $Uri = Get-WebListenerUrl -Test 'Response' -Query $Query $command = "Invoke-WebRequest -Uri '$uri'" $result = ExecuteWebCommand -command $command $result.Output.RelationLink.Count | Should BeExactly 3 @@ -946,9 +951,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { Context "BasicHtmlWebResponseObject Encoding tests" { It "Verifies Invoke-WebRequest detects charset meta value when the ContentType header does not define it." { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -956,17 +965,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest detects charset meta value when newlines are encountered in the element." { - $output = @' - - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n `n `n `n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -974,9 +979,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest detects charset meta value when the attribute value is unquoted." { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -984,14 +993,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest detects http-equiv charset meta value when the ContentType header does not define it." { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -999,16 +1007,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest detects http-equiv charset meta value newlines are encountered in the element." { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -1016,10 +1021,14 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest ignores meta charset value when Content-Type header defines it." { - $output = '' + $query = @{ + contenttype = 'text/html; charset=utf-8' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query # NOTE: meta charset should be ignored $expectedEncoding = [System.Text.Encoding]::UTF8 - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html; charset=utf-8&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -1027,10 +1036,14 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest honors non-utf8 charsets in the Content-Type header" { - $output = '' + $query = @{ + contenttype = 'text/html; charset=utf-16' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query # NOTE: meta charset should be ignored $expectedEncoding = [System.Text.Encoding]::GetEncoding('utf-16') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html; charset=utf-16&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -1038,9 +1051,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest defaults to iso-8859-1 when an unsupported/invalid charset is declared" { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -1048,14 +1065,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest defaults to iso-8859-1 when an unsupported/invalid charset is declared using http-equiv" { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html&output=$output" -UseBasicParsing + $response = ExecuteWebRequest -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -1063,127 +1079,16 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } } - Context "HtmlWebResponseObject Encoding" { - # these tests are dependent on https://github.com/PowerShell/PowerShell/issues/2867 - # Currently, all paths return BasicHtmlWebResponseObject - It "Verifies Invoke-WebRequest detects charset meta value when the ContentType header does not define it." -Pending { - $output = '' - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest detects charset meta value when newlines are encountered in the element." -Pending { - $output = @' - - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest ignores meta charset value when Content-Type header defines it." -Pending { - $output = '' - # NOTE: meta charset should be ignored - $expectedEncoding = [System.Text.Encoding]::UTF8 - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html; charset=utf-8&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest detects http-equiv charset meta value when the ContentType header does not define it." -Pending { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest detects http-equiv charset meta value newlines are encountered in the element." -Pending { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest honors non-utf8 charsets in the Content-Type header" -Pending { - $output = '' - # NOTE: meta charset should be ignored - $expectedEncoding = [System.Text.Encoding]::GetEncoding('utf-16') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html; charset=utf-16&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest defaults to iso-8859-1 when an unsupported/invalid charset is declared" -Pending { - $output = '' - $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - - It "Verifies Invoke-WebRequest defaults to iso-8859-1 when an unsupported/invalid charset is declared using http-equiv" -Pending { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteWebRequest -Uri "http://localhost:8080/PowerShell?test=response&contenttype=text/html&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Output.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - $response.Output | Should BeOfType 'Microsoft.PowerShell.Commands.HtmlWebResponseObject' - } - } - #endregion charset encoding tests #region Content Header Inclusion + It "Verifies Invoke-WebRequest includes Content headers in Headers property" { - $uri = "http://localhost:8080/PowerShell?test=response&contenttype=text/plain&output=OK" + $query = @{ + contenttype = 'text/plain' + body ='OK' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $command = "Invoke-WebRequest -Uri '$uri'" $result = ExecuteWebCommand -command $command ValidateResponse $result @@ -1193,7 +1098,11 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } It "Verifies Invoke-WebRequest includes Content headers in RawContent property" { - $uri = "http://localhost:8080/PowerShell?test=response&contenttype=text/plain&output=OK" + $query = @{ + contenttype = 'text/plain' + body ='OK' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $command = "Invoke-WebRequest -Uri '$uri'" $result = ExecuteWebCommand -command $command ValidateResponse $result @@ -1202,13 +1111,17 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Output.RawContent | Should Match ([regex]::Escape('Content-Length: 2')) } - # Test pending due to HttpListener limitation on Linux/macOS + # Test pending due to limitation on Linux/macOS # https://github.com/PowerShell/PowerShell/pull/4640 - It "Verifies Invoke-WebRequest Supports Multiple response headers with same name" -Pending { - $headers = @{ - 'X-Fake-Header' = 'testvalue01','testvalue02' - } | ConvertTo-Json -Compress - $uri = "http://localhost:8080/PowerShell?test=response&contenttype=text/plain&output=OK&headers=$headers" + It "Verifies Invoke-WebRequest Supports Multiple response headers with same name" -Pending:$(!$IsWindows) { + $query = @{ + contenttype = 'text/plain' + body ='OK' + headers = @{ + 'X-Fake-Header' = @('testvalue01','testvalue02') + } | ConvertTo-Json -Compress + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $command = "Invoke-WebRequest -Uri '$uri'" $result = ExecuteWebCommand -command $command ValidateResponse $result @@ -1500,7 +1413,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'} @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'} # macOS does not support multiple SslProtocols - if (-not $IsMacOS) + if (-not $IsMacOS) { @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'} @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'} @@ -1514,7 +1427,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { # macOS does not support multiple SslProtocols and possible CoreFX for this combo on Linux if($IsWindows) { - + @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls12'} } ) { @@ -1538,7 +1451,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'} @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'} # macOS does not support multiple SslProtocols - if (-not $IsMacOS) + if (-not $IsMacOS) { @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'} @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'} @@ -1909,7 +1822,12 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" { - $command = "Invoke-RestMethod -Uri 'http://localhost:8081/PowerShell?test=response&output=foo' -FollowRelLink" + $query = @{ + contenttype = 'application/json' + body = '"foo"' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + $command = "Invoke-RestMethod -Uri '$uri' -FollowRelLink" $result = ExecuteWebCommand -command $command $result.Output | Should BeExactly "foo" @@ -2135,212 +2053,119 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { Context "Invoke-RestMethod Encoding tests with BasicHtmlWebResponseObject response" { It "Verifies Invoke-RestMethod detects charset meta value when the ContentType header does not define it." { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-WebRequest detects charset meta value when newlines are encountered in the element." { - $output = @' - - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n `n `n `n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod detects charset meta value when the attribute value is unquoted." { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod detects http-equiv charset meta value when the ContentType header does not define it." { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod detects http-equiv charset meta value newlines are encountered in the element." { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod ignores meta charset value when Content-Type header defines it." { - $output = '' + $query = @{ + contenttype = 'text/html; charset=utf-8' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query # NOTE: meta charset should be ignored $expectedEncoding = [System.Text.Encoding]::UTF8 - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html; charset=utf-8&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod honors non-utf8 charsets in the Content-Type header" { - $output = '' + $query = @{ + contenttype = 'text/html; charset=utf-16' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query # NOTE: meta charset should be ignored $expectedEncoding = [System.Text.Encoding]::GetEncoding('utf-16') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html; charset=utf-16&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod defaults to iso-8859-1 when an unsupported/invalid charset is declared" { - $output = '' + $query = @{ + contenttype = 'text/html' + body = '' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html&output=$output" -UseBasicParsing + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName } It "Verifies Invoke-RestMethod defaults to iso-8859-1 when an unsupported/invalid charset is declared using http-equiv" { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html&output=$output" -UseBasicParsing - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - } - - Context "Invoke-RestMethod Encoding tests with HtmlWebResponseObject response" { - # these tests are dependent on https://github.com/PowerShell/PowerShell/issues/2867 - # Currently, all paths return BasicHtmlWebResponseObject - It "Verifies Invoke-RestMethod detects charset meta value when the ContentType header does not define it." -Pending { - $output = '' - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod detects charset meta value when newlines are encountered in the element." -Pending { - $output = @' - - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod ignores meta charset value when Content-Type header defines it." -Pending { - $output = '' - # NOTE: meta charset should be ignored - $expectedEncoding = [System.Text.Encoding]::UTF8 - # Update to test for HtmlWebResponseObject when mshtl dependency has been resolved. - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html; charset=utf-8&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod detects http-equiv charset meta value when the ContentType header does not define it." -Pending { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod detects http-equiv charset meta value newlines are encountered in the element." -Pending { - $output = @' - - - - -'@ - $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod honors non-utf8 charsets in the Content-Type header" -Pending { - $output = '' - # NOTE: meta charset should be ignored - $expectedEncoding = [System.Text.Encoding]::GetEncoding('utf-16') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html; charset=utf-16&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod defaults to iso-8859-1 when an unsupported/invalid charset is declared" -Pending { - $output = '' - $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html&output=$output" - - $response.Error | Should BeNullOrEmpty - $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName - } - - It "Verifies Invoke-RestMethod defaults to iso-8859-1 when an unsupported/invalid charset is declared using http-equiv" -Pending { - $output = @' - - - - -'@ + $query = @{ + contenttype = 'text/html' + body = "`n`n`n" + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query $expectedEncoding = [System.Text.Encoding]::GetEncoding('iso-8859-1') - $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&contenttype=text/html&output=$output" + $response = ExecuteRestMethod -Uri $uri -UseBasicParsing $response.Error | Should BeNullOrEmpty $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName @@ -2557,7 +2382,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'} @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'} # macOS does not support multiple SslProtocols - if (-not $IsMacOS) + if (-not $IsMacOS) { @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'} @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'} @@ -2593,7 +2418,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'} @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'} # macOS does not support multiple SslProtocols - if (-not $IsMacOS) + if (-not $IsMacOS) { @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'} @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'} @@ -2614,18 +2439,24 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { } Context "Invoke-RestMethod Single Value JSON null support" { - BeforeAll { - $baseUrl = 'http://localhost:8081/PowerShell?test=response&contenttype=application/json&output=' - } It "Invoke-RestMethod Supports a Single Value JSON null" { - $url = '{0}{1}' -f $baseUrl, 'null' - Invoke-RestMethod -Uri $url | Should Be $null + $query = @{ + contenttype = 'application/json' + body = 'null' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + Invoke-RestMethod -Uri $uri | Should Be $null } It "Invoke-RestMethod Supports a Single Value JSON null and ignores whitespace" { - $url = '{0}{1}' -f $baseUrl, " null " - Invoke-RestMethod -Uri $url | Should Be $null - $url = '{0}{1}' -f $baseUrl, " null `n" - Invoke-RestMethod -Uri $url | Should Be $null + $query = @{ + contenttype = 'application/json' + body = " null " + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + Invoke-RestMethod -Uri $uri | Should Be $null + $query['body'] = " null `n" + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + Invoke-RestMethod -Uri $uri | Should Be $null } } @@ -2740,22 +2571,27 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI" { BeforeAll { - $response = Start-HttpListener -Port 8079 - } - - AfterAll { - $null = Stop-HttpListener -Port 8079 - $response.PowerShell.Dispose() + $WebListener = Start-WebListener } It "Execute Invoke-WebRequest" { - $result = iwr "http://localhost:8079/PowerShell?test=response&output=hello" -TimeoutSec 5 + $query = @{ + body = "hello" + contenttype = 'text/plain' + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + $result = iwr $uri -TimeoutSec 5 $result.StatusCode | Should Be "200" $result.Content | Should Be "hello" } It "Execute Invoke-RestMethod" { - $result = irm "http://localhost:8079/PowerShell?test=response&output={%22hello%22:%22world%22}&contenttype=application/json" -TimeoutSec 5 + $query = @{ + contenttype = 'application/json' + body = @{Hello = "world"} | ConvertTo-Json -Compress + } + $uri = Get-WebListenerUrl -Test 'Response' -Query $query + $result = irm $uri -TimeoutSec 5 $result.Hello | Should Be "world" } } diff --git a/test/tools/Modules/WebListener/WebListener.psm1 b/test/tools/Modules/WebListener/WebListener.psm1 index 9c51a9b1715..981f09f2bbd 100644 --- a/test/tools/Modules/WebListener/WebListener.psm1 +++ b/test/tools/Modules/WebListener/WebListener.psm1 @@ -136,6 +136,7 @@ function Get-WebListenerUrl { 'Home', 'Multipart', 'Redirect', + 'Response', 'ResponseHeaders', '/' )] diff --git a/test/tools/WebListener/Constants.cs b/test/tools/WebListener/Constants.cs index 1eae8c284f2..b36a4e80810 100644 --- a/test/tools/WebListener/Constants.cs +++ b/test/tools/WebListener/Constants.cs @@ -5,5 +5,11 @@ namespace mvc.Controllers internal static class Constants { public const string HeaderSeparator = ", "; + public const string ApplicationJson = "application/json"; + } + + internal static class StatusCodes + { + public const Int32 ApplicationError = 500; } } diff --git a/test/tools/WebListener/Controllers/ResponseController.cs b/test/tools/WebListener/Controllers/ResponseController.cs new file mode 100644 index 00000000000..c2688cf0556 --- /dev/null +++ b/test/tools/WebListener/Controllers/ResponseController.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.Extensions.Primitives; +using mvc.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace mvc.Controllers +{ + public class ResponseController : Controller + { + public String Index() + { + string output = String.Empty; + string contentType = Constants.ApplicationJson; + + StringValues contentTypes; + if (Request.Query.TryGetValue("contenttype", out contentTypes)) + { + contentType = contentTypes.FirstOrDefault(); + } + + StringValues statusCodes; + Int32 statusCode; + if (Request.Query.TryGetValue("statuscode", out statusCodes) && + Int32.TryParse(statusCodes.FirstOrDefault(), out statusCode)) + { + Response.StatusCode = statusCode; + } + + StringValues body; + if (Request.Query.TryGetValue("body", out body)) + { + output = body.FirstOrDefault(); + } + + StringValues headers; + if (Request.Query.TryGetValue("headers", out headers)) + { + try + { + Response.Headers.Clear(); + JObject jobject = JObject.Parse(headers.FirstOrDefault()); + foreach (JProperty property in (JToken)jobject) + { + // Only set Content-Type through contenttype field. + if (String.Equals(property.Name, "Content-Type", StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + foreach (string entry in GetSingleOrArray(property.Value)) + { + Response.Headers.Append(property.Name,entry); + } + } + } + catch (Exception ex) + { + output = JsonConvert.SerializeObject(ex); + Response.StatusCode = StatusCodes.ApplicationError; + contentType = Constants.ApplicationJson; + } + } + + // Content-Type must be applied right before it is sent to the client or MVC will overwrite. + Response.OnStarting(state => + { + var httpContext = (HttpContext) state; + httpContext.Response.ContentType = contentType; + return Task.FromResult(0); + }, HttpContext); + + Response.ContentLength = Encoding.UTF8.GetBytes(output).Length; + + return output; + } + + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + + private List GetSingleOrArray(JToken token) + { + if (token.HasValues) + { + return token.ToObject>(); + } + else + { + return new List { token.ToObject() }; + } + } + } +} diff --git a/test/tools/WebListener/README.md b/test/tools/WebListener/README.md index a5ce45df0a1..efa200a3e61 100644 --- a/test/tools/WebListener/README.md +++ b/test/tools/WebListener/README.md @@ -342,6 +342,41 @@ Location: /Get/

You should be redirected automatically to target URL: /Get/. If not click the link. ``` +## /Response/ + +Will return a response crafted from the query string. The following four fields are supported: + +* `body` - a string containing the response body +* `statuscode` - the HTTP Status Code to return +* `contenttype` - The `Content-Type` response header +* `headers` - a JSON string containing response headers. `Content-Type` will be ignored in `headers`. Use `contenttype` instead. + +```powershell +$Query = @{ + statsucode = 200 + contenttype = 'application/json' + body = '{"key1": "value1"}' + headers = @{ + "X-Header" = "Response header value" + } | ConvertTo-Json +} +$Uri = Get-WebListenerUrl -Test 'Response' -Query $Query +Invoke-RestMethod -Uri $uri +``` + +Response headers: + +```none +Content-Type: application/json +X-Header: Response header value +``` + +Response Body: + +```json +{"key1": "value1"} +``` + ## /ResponseHeaders/ Will return the response headers passed in query string. The response body will be the supplied headers as a JSON object. diff --git a/test/tools/WebListener/Views/Home/Index.cshtml b/test/tools/WebListener/Views/Home/Index.cshtml index 13699a36b33..253ed6879e4 100644 --- a/test/tools/WebListener/Views/Home/Index.cshtml +++ b/test/tools/WebListener/Views/Home/Index.cshtml @@ -12,5 +12,6 @@

  • /Get/ - Emulates functionality of https://httpbin.org/get by returning GET headers, Arguments, and Request URL
  • /Multipart/ - Multipart/form-data submission testing
  • /Redirect/{count} - 302 redirect count times.
  • +
  • /Response/?statuscode=<StatusCode>&body=<ResponseBody>&contenttype=<ResponseContentType>&headers=<JsonHeadersObject> - Returns the given response.
  • /ResponseHeaders/?key=val - Returns given response headers.
  • From c0d5d5438f862566b190e354f28c336ef9ebff01 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 4 Dec 2017 10:07:30 -0800 Subject: [PATCH 3/7] Add retry logic to prerequisite URL tests (#5601) * Disable Requisiste URLs tests * Add retry for the URL tests --- .../Installer/WindowsInstaller.Tests.ps1 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/powershell/Installer/WindowsInstaller.Tests.ps1 b/test/powershell/Installer/WindowsInstaller.Tests.ps1 index 759869784a5..8ee74bfcd76 100644 --- a/test/powershell/Installer/WindowsInstaller.Tests.ps1 +++ b/test/powershell/Installer/WindowsInstaller.Tests.ps1 @@ -15,10 +15,21 @@ Describe "Windows Installer" -Tags "Scenario" { (Get-Content $wixProductFile -Raw).Contains($preRequisitesLink) | Should Be $true } - It "Pre-Requisistes link for '' is reachable: " -TestCases $linkCheckTestCases -Test { + ## Running 'Invoke-WebRequest' with WMF download URLs has been failing intermittently, + ## because sometimes the URLs lead to a 'this download is no longer available' page. + ## We use a retry logic here. Retry for 5 times with 1 second interval. + It "Pre-Requisistes link for '' is reachable: " -TestCases $linkCheckTestCases { param ($Url) - # Because an outdated link 'https://www.microsoft.com/download/details.aspx?id=504100000' would still return a 200 reponse (due to a redirection to an error page), it only checks that it returns something - (Invoke-WebRequest $Url -UseBasicParsing) | Should Not Be $null + foreach ($i in 1..5) { + try { + $result = Invoke-WebRequest $Url -UseBasicParsing + break; + } catch { + Start-Sleep -Seconds 1 + } + } + + $result | Should Not Be $null } } From 03b6b9b085a0b617d5eef60504b6a01240a2391a Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 4 Dec 2017 11:38:30 -0800 Subject: [PATCH 4/7] [Feature] Make the -SslProtocol tests pending (#5605) --- .../WebCmdlets.Tests.ps1 | 221 +++++++++--------- 1 file changed, 112 insertions(+), 109 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 9cd0ae22d18..e9282b5245c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -1407,67 +1407,69 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } Context "Invoke-WebRequest -SslProtocol Test" { - It "Verifies Invoke-WebRequest -SslProtocol works on " -TestCases @( - @{SslProtocol = 'Default'; ActualProtocol = 'Default'} - @{SslProtocol = 'Tls'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'} - # macOS does not support multiple SslProtocols - if (-not $IsMacOS) - { - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'} - @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'} - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls'} - } - # macOS does not support multiple SslProtocols and possible CoreFX for this combo on Linux - if($IsWindows) - { - - @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls12'} - } - ) { - param($SslProtocol, $ActualProtocol) - $params = @{ - Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol - SslProtocol = $SslProtocol - SkipCertificateCheck = $true - } - $response = Invoke-WebRequest @params - $result = $Response.Content | ConvertFrom-Json + BeforeAll { + ## Test cases for the 1st 'It' + $testCases1 = @( + @{ Test = @{SslProtocol = 'Default'; ActualProtocol = 'Default'}; Pending = $false } + @{ Test = @{SslProtocol = 'Tls'; ActualProtocol = 'Tls'}; Pending = $false } + # these two currently fail on Travis CI macOS build + @{ Test = @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols and possible CoreFX issue for this combo on Linux + @{ Test = @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls12'}; Pending = -not $IsWindows } + ) - $result.headers.Host | Should Be $params.Uri.Authority + $testCases2 = @( + @{ Test = @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls12'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls11'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls12'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'}; Pending = $false } + # these two currently fail on Travis CI macOS build + @{ Test = @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols + @{ Test = @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + ) } - It "Verifies Invoke-WebRequest -SslProtocol -SslProtocol fails on a only connection" -TestCases @( - @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls12'} - @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls11'} - @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls12'} - @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'} - # macOS does not support multiple SslProtocols - if (-not $IsMacOS) - { - @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'} - @{IntendedProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls12'} - } - ) { - param( $IntendedProtocol, $ActualProtocol) - $params = @{ - Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol - SslProtocol = $IntendedProtocol - SkipCertificateCheck = $true - ErrorAction = 'Stop' + foreach ($entry in $testCases1) { + It "Verifies Invoke-WebRequest -SslProtocol works on " -TestCases ($entry.Test) -Pending:($entry.Pending) { + param($SslProtocol, $ActualProtocol) + $params = @{ + Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol + SslProtocol = $SslProtocol + SkipCertificateCheck = $true + } + $response = Invoke-WebRequest @params + $result = $Response.Content | ConvertFrom-Json + + $result.headers.Host | Should Be $params.Uri.Authority } - { Invoke-WebRequest @params } | ShouldBeErrorId 'WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand' } + foreach ($entry in $testCases2) { + It "Verifies Invoke-WebRequest -SslProtocol -SslProtocol fails on a only connection" -TestCases ($entry.Test) -Pending:($entry.Pending) { + param( $IntendedProtocol, $ActualProtocol) + $params = @{ + Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol + SslProtocol = $IntendedProtocol + SkipCertificateCheck = $true + ErrorAction = 'Stop' + } + { Invoke-WebRequest @params } | ShouldBeErrorId 'WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand' + } + } } BeforeEach { @@ -2376,66 +2378,67 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { } Context "Invoke-RestMethod -SslProtocol Test" { - It "Verifies Invoke-RestMethod -SslProtocol works on " -TestCases @( - @{SslProtocol = 'Default'; ActualProtocol = 'Default'} - @{SslProtocol = 'Tls'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'} - # macOS does not support multiple SslProtocols - if (-not $IsMacOS) - { - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'} - @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'} - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls11'} - @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls'} - @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls'} - } - # macOS does not support multiple SslProtocols and possible CoreFX for this combo on Linux - if($IsWindows) - { - @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls12'} - } - ) { - param($SslProtocol, $ActualProtocol) - $params = @{ - Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol - SslProtocol = $SslProtocol - SkipCertificateCheck = $true - } - $result = Invoke-RestMethod @params + BeforeAll { + $testCases1 = @( + @{ Test = @{SslProtocol = 'Default'; ActualProtocol = 'Default'}; Pending = $false } + @{ Test = @{SslProtocol = 'Tls'; ActualProtocol = 'Tls'}; Pending = $false } + # these two currently fail on Travis CI macOS build + @{ Test = @{SslProtocol = 'Tls11'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols and possible CoreFX issue for this combo on Linux + @{ Test = @{SslProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls12'}; Pending = -not $IsWindows } + ) - $result.headers.Host | Should Be $params.Uri.Authority + $testCases2 = @( + @{ Test = @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls12'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls11'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls12'}; Pending = $false } + @{ Test = @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'}; Pending = $false } + # these two currently fail on Travis CI macOS build + @{ Test = @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + # macOS does not support multiple SslProtocols + @{ Test = @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'}; Pending = $IsMacOS } + @{ Test = @{IntendedProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls12'}; Pending = $IsMacOS } + ) } - It "Verifies Invoke-RestMethod -SslProtocol fails on a only connection" -TestCases @( - @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls12'} - @{IntendedProtocol = 'Tls'; ActualProtocol = 'Tls11'} - @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls12'} - @{IntendedProtocol = 'Tls11'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls12'; ActualProtocol = 'Tls11'} - # macOS does not support multiple SslProtocols - if (-not $IsMacOS) - { - @{IntendedProtocol = 'Tls11, Tls12'; ActualProtocol = 'Tls'} - @{IntendedProtocol = 'Tls, Tls12'; ActualProtocol = 'Tls11'} - @{IntendedProtocol = 'Tls, Tls11'; ActualProtocol = 'Tls12'} - } - ) { - param( $IntendedProtocol, $ActualProtocol) - $params = @{ - Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol - SslProtocol = $IntendedProtocol - SkipCertificateCheck = $true - ErrorAction = 'Stop' + foreach ($entry in $testCases1) { + It "Verifies Invoke-RestMethod -SslProtocol works on " -TestCases ($entry.Test) -Pending:($entry.Pending) { + param($SslProtocol, $ActualProtocol) + $params = @{ + Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol + SslProtocol = $SslProtocol + SkipCertificateCheck = $true + } + $result = Invoke-RestMethod @params + + $result.headers.Host | Should Be $params.Uri.Authority } - { Invoke-RestMethod @params } | ShouldBeErrorId 'WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand' } - + foreach ($entry in $testCases2) { + It "Verifies Invoke-RestMethod -SslProtocol fails on a only connection" -TestCases ($entry.Test) -Pending:($entry.Pending) { + param( $IntendedProtocol, $ActualProtocol) + $params = @{ + Uri = Get-WebListenerUrl -Test 'Get' -Https -SslProtocol $ActualProtocol + SslProtocol = $IntendedProtocol + SkipCertificateCheck = $true + ErrorAction = 'Stop' + } + { Invoke-RestMethod @params } | ShouldBeErrorId 'WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand' + } + } } Context "Invoke-RestMethod Single Value JSON null support" { From c25cb722371f6aee062b8b9d7580be08ab55d182 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 4 Dec 2017 13:26:53 -0800 Subject: [PATCH 5/7] [Feature] Supress the expected errors from Select-Xml tests (#5591) --- .../Microsoft.PowerShell.Utility/xml.tests.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 index 7a8f2ad001b..f37280a8020 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/xml.tests.ps1 @@ -2,15 +2,15 @@ Context "Select-XML" { BeforeAll { $fileName = New-Item -Path 'TestDrive:\testSelectXml.xml' - Push-Location "$fileName\.." - "" | out-file -LiteralPath $fileName - " " | out-file -LiteralPath $fileName -Append - "" | out-file -LiteralPath $fileName -Append + Push-Location "$fileName\.." + "" | out-file -LiteralPath $fileName + " " | out-file -LiteralPath $fileName -Append + "" | out-file -LiteralPath $fileName -Append $fileNameWithDots = $fileName.FullName.Replace("\", "\.\") $driveLetter = [string]($fileName.FullName)[0] - $fileNameAsNetworkPath = "\\localhost\$driveLetter`$" + $fileName.FullName.SubString(2) + $fileNameAsNetworkPath = "\\localhost\$driveLetter`$" + $fileName.FullName.SubString(2) class TestData { @@ -65,7 +65,7 @@ $file = 'env:xmltestfile' $params = @{$parameter=$file} $err = $null - Select-XML @params "Root" -ErrorVariable err + Select-XML @params "Root" -ErrorVariable err -ErrorAction SilentlyContinue $err.FullyQualifiedErrorId | Should Be $expectedError } finally @@ -78,7 +78,7 @@ $testfile = "$testdrive/test.xml" Set-Content -Path $testfile -Value "" $err = $null - Select-Xml -Path $testfile -XPath foo -ErrorVariable err + Select-Xml -Path $testfile -XPath foo -ErrorVariable err -ErrorAction SilentlyContinue $err.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand' } @@ -93,13 +93,13 @@ It "Returns error for invalid xmlnamespace" { $err = $null [xml]$xml = "helloworld" - Select-Xml -Xml $xml -XPath foo -Namespace @{c=$null} -ErrorVariable err + Select-Xml -Xml $xml -XPath foo -Namespace @{c=$null} -ErrorVariable err -ErrorAction SilentlyContinue $err.FullyQualifiedErrorId | Should Be 'PrefixError,Microsoft.PowerShell.Commands.SelectXmlCommand' } It "Returns error for invalid content" { $err = $null - Select-Xml -Content "hello" -XPath foo -ErrorVariable err + Select-Xml -Content "hello" -XPath foo -ErrorVariable err -ErrorAction SilentlyContinue $err.FullyQualifiedErrorId | Should Be 'InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand' } From 19e800b882e8cc0e5952649c035bdd432e02cd10 Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Mon, 4 Dec 2017 14:18:52 -0800 Subject: [PATCH 6/7] Run tests for Windows installer only on Windows (#5619) --- test/powershell/Installer/WindowsInstaller.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/powershell/Installer/WindowsInstaller.Tests.ps1 b/test/powershell/Installer/WindowsInstaller.Tests.ps1 index 8ee74bfcd76..bf1eba54d04 100644 --- a/test/powershell/Installer/WindowsInstaller.Tests.ps1 +++ b/test/powershell/Installer/WindowsInstaller.Tests.ps1 @@ -1,6 +1,7 @@ Describe "Windows Installer" -Tags "Scenario" { BeforeAll { + $skipTest = -not $IsWindows $preRequisitesLink = 'https://aka.ms/pscore6-prereq' $linkCheckTestCases = @( @{ Name = "Universal C Runtime"; Url = $preRequisitesLink } @@ -10,7 +11,7 @@ Describe "Windows Installer" -Tags "Scenario" { ) } - It "WiX (Windows Installer XML) file contains pre-requisites link $preRequisitesLink" { + It "WiX (Windows Installer XML) file contains pre-requisites link $preRequisitesLink" -skip:$skipTest { $wixProductFile = Join-Path -Path $PSScriptRoot -ChildPath "..\..\..\assets\Product.wxs" (Get-Content $wixProductFile -Raw).Contains($preRequisitesLink) | Should Be $true } @@ -18,7 +19,7 @@ Describe "Windows Installer" -Tags "Scenario" { ## Running 'Invoke-WebRequest' with WMF download URLs has been failing intermittently, ## because sometimes the URLs lead to a 'this download is no longer available' page. ## We use a retry logic here. Retry for 5 times with 1 second interval. - It "Pre-Requisistes link for '' is reachable: " -TestCases $linkCheckTestCases { + It "Pre-Requisistes link for '' is reachable: " -TestCases $linkCheckTestCases -skip:$skipTest { param ($Url) foreach ($i in 1..5) { From 6b837ceba45a353b9f95eacdd69b5381cd4468d6 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 4 Dec 2017 14:32:02 -0800 Subject: [PATCH 7/7] contribution guidelines: change to say updating changelog is required (#5586) - Update contribution guidelines to make updating the changelog required - add a checklist to PR template Comment by @SteveL-MSFT : > Everyone should understand that we are always open to feedback and nothing is set in stone. Based on a team discussion, one of the biggest costs for a release is creating the ChangeLog hence updating this document to push it to the contributor most aware of why the changes are being made and ideally how it's useful to end users. --- .github/CODEOWNERS | 2 +- .github/CONTRIBUTING.md | 15 ++++++++------- .github/PULL_REQUEST_TEMPLATE.md | 18 ++++++++++++------ CHANGELOG.md | 4 ++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4431b761d90..9a778e4b4cd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -13,7 +13,7 @@ # @TravisEz13 @PaulHigin # Area: Documentation -# @joeyaiello @TravisEz13 +.github/ @joeyaiello @TravisEz13 # Area: Test # @JamesWTruher @TravisEz13 @adityapatwardhan diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a7491ea8bd9..6ac13aadac6 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -129,19 +129,20 @@ Additional references: If the changes are related to an existing GitHub issue, please reference the issue in PR description (e.g. ```Fix #11```). See [this][closing-via-message] for more details. -* If the change warrants a note in the [changelog](../CHANGELOG.MD) - either update the changelog in your pull request or - add a comment in the PR description saying that the change may warrant a note in the changelog. - New changes always go into the **Unreleased** section. + +#### Pull request - Change log + +* All PRs must update the [changelog](../CHANGELOG.MD) in your pull request. + New changes always go into the **Unreleased** section at the top of the changelog. Keeping the changelog up-to-date simplifies the release process for Maintainers. An example (with an associated PR #): ```markdown - Unreleased - ---------- + ## Unreleased - * `Update-Item` now supports `-FriendlyName` (#1234). + * `Update-Item` now supports `-FriendlyName` (#1234, @ExampleUser). ``` + Note: Please add `**Breaking Change**` to the front of the entry in the changelog if the change is [breaking.](#making-breaking-changes) * Please use the present tense and imperative mood when describing your changes: * Instead of "Adding support for Windows Server 2012 R2", write "Add support for Windows Server 2012 R2". diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 684606536ec..9556b6b5744 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,8 +1,14 @@ - +## PR Summary diff --git a/CHANGELOG.md b/CHANGELOG.md index cf08d92cb45..782e9616edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Update the contribution guideline to note that updating the changelog is required. (#5586) + ## v6.0.0-rc - 2017-11-16 ### Breaking changes