From ccb14e5cb47c06b3ce77608af414febd26db1dc7 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 27 Jan 2021 11:53:30 -0800 Subject: [PATCH 1/3] Fix webcmdlets to properly construct URI from body when using -NoProxy --- .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 1cef94d1685..3d1d5fc6ffc 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -815,7 +815,7 @@ private ErrorRecord GetValidationError(string msg, string errorId, params object private bool IsStandardMethodSet() { - return (ParameterSetName == "StandardMethod"); + return (ParameterSetName == "StandardMethod" || ParameterSetName == "StandardMethodNoProxy"); } private bool IsCustomMethodSet() From bc6586255a2464c83bfd63d17cd1d3d75e29553f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 27 Jan 2021 12:31:39 -0800 Subject: [PATCH 2/3] add test --- .../WebCmdlets.Tests.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index f63f3be140f..f8cc9e8b583 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -688,6 +688,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" { ($result.Output.Content | ConvertFrom-Json).args.testparam | Should -Be "testvalue" } + It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET and -NoProxy" { + $uri = Get-WebListenerUrl -Test 'Get' + $command = "Invoke-WebRequest -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" + $result = ExecuteWebCommand -command $command + ($result.Output.Content | ConvertFrom-Json).args.testparam | Should -Be "testvalue" + } + It "Validate Invoke-WebRequest returns HTTP errors in exception" { $query = @{ body = "I am a teapot!!!" @@ -2269,6 +2276,13 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { $result.Output.args.testparam | Should -Be "testvalue" } + It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET and -NoProxy" { + $uri = Get-WebListenerUrl -Test 'Get' + $command = "Invoke-RestMethod -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" + $result = ExecuteWebCommand -command $command + $result.Output.args.testparam | Should -Be "testvalue" + } + It "Validate Invoke-RestMethod returns HTTP errors in exception" { $query = @{ body = "I am a teapot!!!" From 02ba2e6e292b5560335220152a3d4c9fa45a082a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 27 Jan 2021 14:55:43 -0800 Subject: [PATCH 3/3] Update weblistener to return query string, fix test to use, fix cmdlet to handle CustomMethodNoProxy case --- .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 2 +- .../Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 | 4 ++-- test/tools/WebListener/Controllers/GetController.cs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index 3d1d5fc6ffc..841f6a60c72 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -820,7 +820,7 @@ private bool IsStandardMethodSet() private bool IsCustomMethodSet() { - return (ParameterSetName == "CustomMethod"); + return (ParameterSetName == "CustomMethod" || ParameterSetName == "CustomMethodNoProxy"); } private string GetBasicAuthorizationHeader() diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index f8cc9e8b583..5f4f5c7728e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -692,7 +692,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" { $uri = Get-WebListenerUrl -Test 'Get' $command = "Invoke-WebRequest -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" $result = ExecuteWebCommand -command $command - ($result.Output.Content | ConvertFrom-Json).args.testparam | Should -Be "testvalue" + ($result.Output.Content | ConvertFrom-Json).query | Should -Be "?testparam=testvalue" } It "Validate Invoke-WebRequest returns HTTP errors in exception" { @@ -2280,7 +2280,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { $uri = Get-WebListenerUrl -Test 'Get' $command = "Invoke-RestMethod -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'} -NoProxy" $result = ExecuteWebCommand -command $command - $result.Output.args.testparam | Should -Be "testvalue" + $result.Output.Query | Should -Be "?testparam=testvalue" } It "Validate Invoke-RestMethod returns HTTP errors in exception" { diff --git a/test/tools/WebListener/Controllers/GetController.cs b/test/tools/WebListener/Controllers/GetController.cs index cadb34725a8..68ce98fb78f 100644 --- a/test/tools/WebListener/Controllers/GetController.cs +++ b/test/tools/WebListener/Controllers/GetController.cs @@ -36,6 +36,7 @@ public JsonResult Index() {"headers", headers}, {"origin" , Request.HttpContext.Connection.RemoteIpAddress.ToString()}, {"url" , UriHelper.GetDisplayUrl(Request)}, + {"query" , Request.QueryString.ToUriComponent()}, {"method" , Request.Method} };