Skip to content

Commit

Permalink
Fix webcmdlets to properly construct URI from body when using -NoProxy (
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT authored and adityapatwardhan committed Mar 8, 2021
1 parent 1b1b7d6 commit a5d47ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ private ErrorRecord GetValidationError(string msg, string errorId, params object

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!"
Expand Down Expand Up @@ -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!!!"
Expand Down
1 change: 1 addition & 0 deletions test/tools/WebListener/Controllers/GetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};

Expand Down

0 comments on commit a5d47ed

Please sign in to comment.