Fix webcmdlets to properly construct URI from body when using -NoProxy (#14673)

This commit is contained in:
Steve Lee
2021-02-05 08:06:04 +05:00
committed by GitHub
parent e3369e4c48
commit c3fa70380c
3 changed files with 17 additions and 2 deletions
@@ -815,12 +815,12 @@ namespace Microsoft.PowerShell.Commands
private bool IsStandardMethodSet()
{
return (ParameterSetName == "StandardMethod");
return (ParameterSetName == "StandardMethod" || ParameterSetName == "StandardMethodNoProxy");
}
private bool IsCustomMethodSet()
{
return (ParameterSetName == "CustomMethod");
return (ParameterSetName == "CustomMethod" || ParameterSetName == "CustomMethodNoProxy");
}
private string GetBasicAuthorizationHeader()
@@ -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).query | Should -Be "?testparam=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.Query | Should -Be "?testparam=testvalue"
}
It "Validate Invoke-RestMethod returns HTTP errors in exception" {
$query = @{
body = "I am a teapot!!!"
@@ -36,6 +36,7 @@ namespace mvc.Controllers
{"headers", headers},
{"origin" , Request.HttpContext.Connection.RemoteIpAddress.ToString()},
{"url" , UriHelper.GetDisplayUrl(Request)},
{"query" , Request.QueryString.ToUriComponent()},
{"method" , Request.Method}
};