From 365d06d9c6ef5daeb7f9463cc5574279c9d9da0f Mon Sep 17 00:00:00 2001 From: Dan Travison Date: Mon, 28 Aug 2017 15:32:00 -0700 Subject: [PATCH 1/3] [Feature] Add explicit ContentType detection to Invoke-RestMethod --- .../InvokeRestMethodCommand.CoreClr.cs | 19 +- .../utility/WebCmdlet/StreamHelper.cs | 2 +- .../WebCmdlets.Tests.ps1 | 291 +++++++++++++++++- 3 files changed, 304 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs index 8be7c98342a..23c9c0a44f7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs @@ -45,13 +45,28 @@ internal override void ProcessResponse(HttpResponseMessage response) { // determine the response type RestReturnType returnType = CheckReturnType(response); - // get the response encoding - Encoding encoding = ContentHelper.GetEncoding(response); + + // Try to get the response encoding from the ContentType header. + Encoding encoding = null; + string charSet = response.Content.Headers.ContentType?.CharSet; + if (!string.IsNullOrEmpty(charSet)) + { + // NOTE: Don't use ContentHelper.GetEncoding; it returns a + // default which bypasses checking for a meta charset value. + StreamHelper.TryGetEncoding(charSet, out encoding); + } object obj = null; Exception ex = null; string str = StreamHelper.DecodeStream(responseStream, ref encoding); + // NOTE: Tests use this verbose output to verify the encoding. + WriteVerbose(string.Format + ( + System.Globalization.CultureInfo.InvariantCulture, + "Content encoding: {0}", + string.IsNullOrEmpty(encoding.HeaderName) ? encoding.EncodingName : encoding.HeaderName) + ); bool convertSuccess = false; // On CoreCLR, we need to explicitly load Json.NET diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index cc4f0cacfcd..f4486c8771c 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -450,7 +450,7 @@ internal static string DecodeStream(Stream stream, string characterSet, out Enco return DecodeStream(stream, ref encoding); } - static bool TryGetEncoding(string characterSet, out Encoding encoding) + internal static bool TryGetEncoding(string characterSet, out Encoding encoding) { bool result = false; try diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 4d0ca9c0fa2..314f63affb6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -296,8 +296,71 @@ function ExecuteWebRequest return $result } +[string] $verboseEncodingPrefix = 'Content encoding: ' +# This function calls Invoke-WebRequest with the given uri and +# parses the verbose output to determine the encoding used for the content. +function ExecuteRestMethod +{ + param + ( + [Parameter(Mandatory)] + [string] + $Uri, + + [switch] $UseBasicParsing + ) + $result = [PSObject]@{Output = $null; Error = $null; Encoding = $null; Content = $null} + $verbosePreferenceSave = $VerbosePreference + $VerbosePreference = 'Continue' + try + { + + $verboseFile = Join-Path $TestDrive -ChildPath ExecuteRestMethod.verbose.txt + $result.Output = Invoke-RestMethod -Uri $Uri -TimeoutSec 5 -UseBasicParsing:$UseBasicParsing.IsPresent -Verbose 4>$verboseFile + $result.Content = $result.Output + + if (Test-Path -Path $verboseFile) + { + $result.Verbose = Get-Content -Path $verboseFile + foreach ($item in $result.Verbose) + { + $line = $item.Trim() + if ($line.StartsWith($verboseEncodingPrefix)) + { + $encodingName = $item.SubString($verboseEncodingPrefix.Length).Trim() + $result.Encoding = [System.Text.Encoding]::GetEncoding($encodingName) + break + } + } + if ($result.Encoding -eq $null) + { + throw "Encoding not found in verbose output. Lines: $($result).Verbose.Count Content:$($result.Verbose)" + } + } + + if ($result.Verbose -eq $null) + { + throw "No verbose output was found" + } + } + catch + { + $result.Error = $_ | select-object * | Out-String + } + finally + { + $VerbosePreference = $verbosePreferenceSave + if (Test-Path -Path $verboseFile) + { + Remove-Item -Path $verboseFile -ErrorAction Ignore + } + } + + return $result +} + function GetSelfSignedCert { - <# + <# .NOTES This certificate is not issued for any specific Key Usage It cannot be used for any service that requires a specific key usage @@ -921,7 +984,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { #region Certificate Authentication Tests - # Test pending creation of native test solution + # Test pending creation of native test solution # https://github.com/PowerShell/PowerShell/issues/4609 It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" -Pending { $command = 'Invoke-WebRequest https://prod.idrix.eu/secure/' @@ -931,7 +994,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Output | Should Match ([regex]::Escape('Error: No SSL client certificate presented')) } - # Test pending creation of native test solution + # Test pending creation of native test solution # https://github.com/PowerShell/PowerShell/issues/4609 It "Verifies Invoke-WebRequest Certificate Authentication Successful with -Certificate" -Pending { $Certificate = GetSelfSignedCert @@ -1744,7 +1807,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { #region Certificate Authentication Tests - # Test pending creation of native test solution + # Test pending creation of native test solution # https://github.com/PowerShell/PowerShell/issues/4609 It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" -Pending { $command = 'Invoke-RestMethod https://prod.idrix.eu/secure/' @@ -1753,7 +1816,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Output | Should Match ([regex]::Escape('Error: No SSL client certificate presented')) } - # Test pending creation of native test solution + # Test pending creation of native test solution # https://github.com/PowerShell/PowerShell/issues/4609 It "Verifies Invoke-RestMethod Certificate Authentication Successful with -Certificate" -Pending { $Certificate = GetSelfSignedCert @@ -1765,6 +1828,224 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { #endregion Certificate Authentication Tests + #region charset encoding tests + + 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 = '' + $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') + $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -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 = @' + + + + + +'@ + $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') + $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -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 = '' + $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') + $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -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 = @' + + + + +'@ + $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') + $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -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 = @' + + + + +'@ + $expectedEncoding = [System.Text.Encoding]::GetEncoding('Unicode') + $response = ExecuteRestMethod -Uri "http://localhost:8081/PowerShell?test=response&output=$output" -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 = '' + # 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.Error | Should BeNullOrEmpty + $response.Encoding.EncodingName | Should Be $expectedEncoding.EncodingName + } + + It "Verifies Invoke-RestMethod honors non-utf8 charsets in the Content-Type header" { + $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" -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 = '' + $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 + } + + 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 = @' + + + + +'@ + $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 + } + } + + #endregion charset encoding tests + BeforeEach { if ($env:http_proxy) { $savedHttpProxy = $env:http_proxy From 2fb6c6760bb38f21eeda57ceabd6fea60040cb9a Mon Sep 17 00:00:00 2001 From: Dan Travison Date: Tue, 29 Aug 2017 10:16:14 -0700 Subject: [PATCH 2/3] Address code review feedback. --- .../Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 314f63affb6..89ab4730a6a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -309,7 +309,7 @@ function ExecuteRestMethod [switch] $UseBasicParsing ) - $result = [PSObject]@{Output = $null; Error = $null; Encoding = $null; Content = $null} + $result = @{Output = $null; Error = $null; Encoding = $null; Content = $null} $verbosePreferenceSave = $VerbosePreference $VerbosePreference = 'Continue' try @@ -334,7 +334,7 @@ function ExecuteRestMethod } if ($result.Encoding -eq $null) { - throw "Encoding not found in verbose output. Lines: $($result).Verbose.Count Content:$($result.Verbose)" + throw "Encoding not found in verbose output. Lines: $($result.Verbose.Count) Content:$($result.Verbose)" } } @@ -352,7 +352,7 @@ function ExecuteRestMethod $VerbosePreference = $verbosePreferenceSave if (Test-Path -Path $verboseFile) { - Remove-Item -Path $verboseFile -ErrorAction Ignore + Remove-Item -Path $verboseFile -ErrorAction SilentlyContinue } } From 7be9fc59ad284b96fa325c1cf93f36a574e00ae4 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 31 Aug 2017 09:57:56 -0700 Subject: [PATCH 3/3] Resolve conflict issues --- .../WebCmdlets.Tests.ps1 | 114 ------------------ 1 file changed, 114 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index c111cd40bda..7074c70cc75 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -359,95 +359,6 @@ function ExecuteRestMethod return $result } -function GetSelfSignedCert { - <# - .NOTES - This certificate is not issued for any specific Key Usage - It cannot be used for any service that requires a specific key usage - It can be used for SSL/TLS Client Authentication - #> - $PfxBase64 = @' -MIIQwQIBAzCCEIcGCSqGSIb3DQEHAaCCEHgEghB0MIIQcDCCBqcGCSqGSIb3DQEHBqCCBpgwggaU -AgEAMIIGjQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIfGLU4iludG8CAggA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eI0SdA3sNe4DlTVA4cZ4Y8vMtsFJStPMU0ca15L9Ii2yVr -YJX20neZhIGnsT36bd8e38Mj+7hrVhvV/G2x0aS+lB2lD0HIvRNW02+UxRsZ+S+TtBXnlTHFLAm5 -+IBnXcKWBVnaEvBjwyMIo/bI8C0fhFOt+W88XyoIuPeRYSKVRmg2vjyqMSUwIwYJKoZIhvcNAQkV -MRYEFC3s8TSP8ht4D0XTFqA5tetMYxL3MDEwITAJBgUrDgMCGgUABBS39FfrA3N6RIvd2k2XO1rY -hqPP3QQIlSXpfTECuB4CAggA -'@ - $Bytes = [System.Convert]::FromBase64String($PfxBase64) - [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($Bytes) -} - <# Defines the list of redirect codes to test as well as the expected Method when the redirection is handled. @@ -983,31 +894,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { #endregion SkipHeaderVerification Tests - #region Certificate Authentication Tests - - # Test pending creation of native test solution - # https://github.com/PowerShell/PowerShell/issues/4609 - It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" -Pending { - $command = 'Invoke-WebRequest https://prod.idrix.eu/secure/' - $result = ExecuteWebCommand -command $command - ValidateResponse -response $result - - $result.Output | Should Match ([regex]::Escape('Error: No SSL client certificate presented')) - } - - # Test pending creation of native test solution - # https://github.com/PowerShell/PowerShell/issues/4609 - It "Verifies Invoke-WebRequest Certificate Authentication Successful with -Certificate" -Pending { - $Certificate = GetSelfSignedCert - $command = 'Invoke-WebRequest https://prod.idrix.eu/secure/ -Certificate $Certificate' - $result = ExecuteWebCommand -command $command - ValidateResponse -response $result - - $result.Output.Content | Should Match ([regex]::Escape('SSL Authentication OK!')) - } - - #endregion Certificate Authentication Tests - #region charset encoding tests Context "BasicHtmlWebResponseObject Encoding tests" {