Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,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