From 7c11001976247bb03c92d664bdf20ed9878b9393 Mon Sep 17 00:00:00 2001 From: Lee Date: Mon, 13 Feb 2017 22:56:03 +0000 Subject: [PATCH 1/5] adds parameter sets to web cmdlets to allow for standard and non-standard method verbs --- .../Common/InvokeRestMethodCommand.Common.cs | 12 ++++++++- .../Common/WebRequestPSCmdlet.Common.cs | 26 +++++++++++++++++-- .../InvokeRestMethodCommand.FullClr.cs | 2 +- .../InvokeWebRequestCommand.FullClr.cs | 2 +- .../FullClr/WebRequestPSCmdlet.FullClr.cs | 20 +++++++++++--- .../WebCmdlets.Tests.ps1 | 17 ++++++++++++ 6 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index 0d1506c6f88..4d41be8beac 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -16,13 +16,23 @@ public partial class InvokeRestMethodCommand /// /// gets or sets the parameter Method /// - [Parameter] + [Parameter(ParameterSetName = "StandardMethod")] public override WebRequestMethod Method { get { return base.Method; } set { base.Method = value; } } + /// + /// gets or sets the parameter CustomMethod + /// + [Parameter(ParameterSetName = "CustomMethod")] + public override string CustomMethod + { + get { return base.CustomMethod; } + set { base.CustomMethod = value; } + } + #endregion Parameters #region Helper Methods 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 2eff4b1cb1f..fb6899c5d84 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 @@ -147,7 +147,7 @@ public virtual int MaximumRedirection /// /// gets or sets the Method property /// - [Parameter] + [Parameter(ParameterSetName = "StandardMethod")] public virtual WebRequestMethod Method { get { return _method; } @@ -155,6 +155,17 @@ public virtual WebRequestMethod Method } private WebRequestMethod _method = WebRequestMethod.Default; + /// + /// gets or sets the CustomMethod property + /// + [Parameter(ParameterSetName = "CustomMethod")] + public virtual string CustomMethod + { + get { return _customMethod; } + set { _customMethod = value; } + } + private string _customMethod; + #endregion #region Proxy @@ -547,7 +558,8 @@ private Uri PrepareUri(Uri uri) IDictionary bodyAsDictionary; LanguagePrimitives.TryConvertTo(Body, out bodyAsDictionary); if ((null != bodyAsDictionary) - && (Method == WebRequestMethod.Default || Method == WebRequestMethod.Get)) + && ((IsStandardMethodSet() && (Method == WebRequestMethod.Default || Method == WebRequestMethod.Get)) + || (IsCustomMethodSet() && (string.IsNullOrEmpty(CustomMethod) || CustomMethod.ToUpper() == "GET")))) { UriBuilder uriBuilder = new UriBuilder(uri); if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) @@ -626,6 +638,16 @@ private ErrorRecord GetValidationError(string msg, string errorId, params object return (error); } + private bool IsStandardMethodSet() + { + return (ParameterSetName == "StandardMethod"); + } + + private bool IsCustomMethodSet() + { + return (ParameterSetName == "CustomMethod"); + } + #endregion Helper Methods } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeRestMethodCommand.FullClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeRestMethodCommand.FullClr.cs index a723c3684c6..c07f151ab61 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeRestMethodCommand.FullClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeRestMethodCommand.FullClr.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands /// Intended to work against the wide spectrum of "RESTful" web services /// currently deployed across the web. /// - [Cmdlet(VerbsLifecycle.Invoke, "RestMethod", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217034")] + [Cmdlet(VerbsLifecycle.Invoke, "RestMethod", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217034", DefaultParameterSetName = "StandardMethod")] public partial class InvokeRestMethodCommand : WebRequestPSCmdlet { #region Virtual Method Overrides diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeWebRequestCommand.FullClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeWebRequestCommand.FullClr.cs index ed930f33116..cb5a5710783 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeWebRequestCommand.FullClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/InvokeWebRequestCommand.FullClr.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.Commands /// The Invoke-RestMethod command /// This command makes an HTTP or HTTPS request to a web server and returns the results. /// - [Cmdlet(VerbsLifecycle.Invoke, "WebRequest", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217035")] + [Cmdlet(VerbsLifecycle.Invoke, "WebRequest", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217035", DefaultParameterSetName = "StandardMethod")] public class InvokeWebRequestCommand : WebRequestPSCmdlet { #region Virtual Method Overrides diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs index 06ed7591218..504b7fa52e1 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs @@ -84,10 +84,22 @@ internal virtual WebRequest GetRequest(Uri uri) request.Proxy = WebSession.Proxy; } - // set the method if the parameter was provided - if (WebRequestMethod.Default != Method) + switch (ParameterSetName) { - request.Method = Method.ToString().ToUpperInvariant(); + case "StandardMethod": + if (WebRequestMethod.Default != Method) + { + // set the method if the parameter was provided + request.Method = Method.ToString().ToUpperInvariant(); + } + break; + case "CustomMethod": + // set the method if the parameter was provided + if (!string.IsNullOrEmpty(CustomMethod)) + { + request.Method = CustomMethod.ToUpperInvariant(); + } + break; } // pull in http specific properties @@ -248,7 +260,7 @@ internal virtual void FillRequestStream(WebRequest request) request.ContentType = ContentType; } // ContentType == null - else if (Method == WebRequestMethod.Post) + else if (Method == WebRequestMethod.Post || (!string.IsNullOrEmpty(CustomMethod) && CustomMethod.ToUpper() == "POST")) { // Win8:545310 Invoke-WebRequest does not properly set MIME type for POST if (String.IsNullOrEmpty(request.ContentType)) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 11529315a69..e29e10f6b28 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -399,6 +399,23 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result = ExecuteWebCommand -command $command $result.Error | Should BeNullOrEmpty } + + It "Validate StandardMethod and CustomMethod parameter sets" { + + #Validate that parameter sets are functioning correctly + $command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -Method GET -CustomMethod 'TEST'" + $result = ExecuteWebCommand -command $command + $result.Error | Should Not BeNullOrEmpty + } + + It "Validate CustomMethod parameter set method is passed" { + + #Validate that parameter sets are functioning correctly + $command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -CustomMethod 'TEST'" + $result = ExecuteWebCommand -command $command + $result.Error | Should BeNullOrEmpty + ($result.Output | ConvertFrom-Json).method | Should Be "TEST" + } } Describe "Invoke-RestMethod tests" -Tags "Feature" { From 8f25fd944058c616eae3cc4662f0f0c60f9a0e53 Mon Sep 17 00:00:00 2001 From: Lee Date: Thu, 16 Feb 2017 23:06:08 +0000 Subject: [PATCH 2/5] add CoreCLI implementation --- .../InvokeRestMethodCommand.CoreClr.cs | 2 +- .../InvokeWebRequestCommand.CoreClr.cs | 2 +- .../CoreCLR/WebRequestPSCmdlet.CoreClr.cs | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 4 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 efd3762cc58..7d0d6c2d3bf 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 @@ -18,7 +18,7 @@ namespace Microsoft.PowerShell.Commands /// Intended to work against the wide spectrum of "RESTful" web services /// currently deployed across the web. /// - [Cmdlet(VerbsLifecycle.Invoke, "RestMethod", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217034")] + [Cmdlet(VerbsLifecycle.Invoke, "RestMethod", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217034", DefaultParameterSetName = "StandardMethod")] public partial class InvokeRestMethodCommand : WebRequestPSCmdlet { #region Virtual Method Overrides diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs index 0506ac15001..3dbfbeaae80 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.Commands /// The Invoke-RestMethod command /// This command makes an HTTP or HTTPS request to a web server and returns the results. /// - [Cmdlet(VerbsLifecycle.Invoke, "WebRequest", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217035")] + [Cmdlet(VerbsLifecycle.Invoke, "WebRequest", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=217035", DefaultParameterSetName = "StandardMethod")] public class InvokeWebRequestCommand : WebRequestPSCmdlet { #region Virtual Method Overrides diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebRequestPSCmdlet.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebRequestPSCmdlet.CoreClr.cs index 2797f92cc59..4291757b87b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebRequestPSCmdlet.CoreClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebRequestPSCmdlet.CoreClr.cs @@ -133,7 +133,22 @@ internal virtual HttpClient GetHttpClient() internal virtual HttpRequestMessage GetRequest(Uri uri) { Uri requestUri = PrepareUri(uri); - HttpMethod httpMethod = GetHttpMethod(Method); + HttpMethod httpMethod = null; + + switch (ParameterSetName) + { + case "StandardMethod": + // set the method if the parameter was provided + httpMethod = GetHttpMethod(Method); + break; + case "CustomMethod": + if (!string.IsNullOrEmpty(CustomMethod)) + { + // set the method if the parameter was provided + httpMethod = new HttpMethod(CustomMethod.ToString().ToUpperInvariant()); + } + break; + } // create the base WebRequest object var request = new HttpRequestMessage(httpMethod, requestUri); @@ -208,7 +223,7 @@ internal virtual void FillRequestStream(HttpRequestMessage request) //request } // ContentType == null - else if (Method == WebRequestMethod.Post) + else if (Method == WebRequestMethod.Post || (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "POST")) { // Win8:545310 Invoke-WebRequest does not properly set MIME type for POST string contentType = null; From ecf7624a892f306ad0f1d15dfcddb912bca78fa4 Mon Sep 17 00:00:00 2001 From: Lee Date: Thu, 16 Feb 2017 23:36:29 +0000 Subject: [PATCH 3/5] Adds CM alias and notnullempty for CustomMethod parameter --- .../WebCmdlet/Common/InvokeRestMethodCommand.Common.cs | 2 ++ .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 4 +++- .../WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs | 8 +++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index 4d41be8beac..0614147443a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -27,6 +27,8 @@ public override WebRequestMethod Method /// gets or sets the parameter CustomMethod /// [Parameter(ParameterSetName = "CustomMethod")] + [Alias("CM")] + [ValidateNotNullOrEmpty] public override string CustomMethod { get { return base.CustomMethod; } 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 fb6899c5d84..560aa57a1e5 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 @@ -159,6 +159,8 @@ public virtual WebRequestMethod Method /// gets or sets the CustomMethod property /// [Parameter(ParameterSetName = "CustomMethod")] + [Alias("CM")] + [ValidateNotNullOrEmpty] public virtual string CustomMethod { get { return _customMethod; } @@ -559,7 +561,7 @@ private Uri PrepareUri(Uri uri) LanguagePrimitives.TryConvertTo(Body, out bodyAsDictionary); if ((null != bodyAsDictionary) && ((IsStandardMethodSet() && (Method == WebRequestMethod.Default || Method == WebRequestMethod.Get)) - || (IsCustomMethodSet() && (string.IsNullOrEmpty(CustomMethod) || CustomMethod.ToUpper() == "GET")))) + || (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "GET"))) { UriBuilder uriBuilder = new UriBuilder(uri); if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs index 504b7fa52e1..8922b9dd40a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FullClr/WebRequestPSCmdlet.FullClr.cs @@ -95,10 +95,7 @@ internal virtual WebRequest GetRequest(Uri uri) break; case "CustomMethod": // set the method if the parameter was provided - if (!string.IsNullOrEmpty(CustomMethod)) - { - request.Method = CustomMethod.ToUpperInvariant(); - } + request.Method = CustomMethod.ToUpperInvariant(); break; } @@ -260,7 +257,8 @@ internal virtual void FillRequestStream(WebRequest request) request.ContentType = ContentType; } // ContentType == null - else if (Method == WebRequestMethod.Post || (!string.IsNullOrEmpty(CustomMethod) && CustomMethod.ToUpper() == "POST")) + else if ((IsStandardMethodSet() && Method == WebRequestMethod.Post) + || (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "POST")) { // Win8:545310 Invoke-WebRequest does not properly set MIME type for POST if (String.IsNullOrEmpty(request.ContentType)) From 5d6763b7fa3f8e75d478a49de0a53bf6fecaf6aa Mon Sep 17 00:00:00 2001 From: Lee Date: Fri, 3 Mar 2017 23:33:10 +0000 Subject: [PATCH 4/5] Add tests for Invoke-[WebRequest|RestMethod] CustomMethod parameter --- .../WebCmdlets.Tests.ps1 | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 07c429b73d3..46dfb817bd8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -400,21 +400,33 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Error | Should BeNullOrEmpty } - It "Validate StandardMethod and CustomMethod parameter sets" { + It "Validate Invoke-WebRequest StandardMethod and CustomMethod parameter sets" { #Validate that parameter sets are functioning correctly - $command = "Invoke-RestMethod -Uri 'http://sandbox.lee.io/method.php' -Method GET -CustomMethod 'TEST'" - $result = ExecuteWebCommand -command $command - $result.Error | Should Not BeNullOrEmpty + $errorId = "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" + { Invoke-WebRequest -Uri 'http://http.lee.io/method' -Method GET -CustomMethod TEST } | ShouldBeErrorId $errorId } - It "Validate CustomMethod parameter set method is passed" { + It "Validate Invoke-WebRequest CustomMethod method is used" { - #Validate that custom method is used - $command = "Invoke-RestMethod -Uri 'http://http.lee.io/method' -CustomMethod 'TEST'" + $command = "Invoke-WebRequest -Uri 'http://http.lee.io/method' -CustomMethod TEST" $result = ExecuteWebCommand -command $command $result.Error | Should BeNullOrEmpty - $result.output.method | Should Be "TEST" + ($result.Output.Content | ConvertFrom-Json).output.method | Should Be "TEST" + } + + It "Validate Invoke-WebRequest default ContentType for CustomMethod POST" { + + $command = "Invoke-WebRequest -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'" + $result = ExecuteWebCommand -command $command + ($result.Output.Content | ConvertFrom-Json).headers.'Content-Type' | Should Be "application/x-www-form-urlencoded" + } + + It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET" { + + $command = "Invoke-WebRequest -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}" + $result = ExecuteWebCommand -command $command + ($result.Output.Content | ConvertFrom-Json).args.testparam | Should Be "testvalue" } It "Validate Invoke-WebRequest returns HTTP errors in exception" { @@ -666,6 +678,34 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Error | Should BeNullOrEmpty } + It "Validate Invoke-RestMethod StandardMethod and CustomMethod parameter sets" { + + $errorId = "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" + { Invoke-RestMethod -Uri 'http://http.lee.io/method' -Method GET -CustomMethod TEST } | ShouldBeErrorId $errorId + } + + It "Validate CustomMethod method is used" { + + $command = "Invoke-RestMethod -Uri 'http://http.lee.io/method' -CustomMethod TEST" + $result = ExecuteWebCommand -command $command + $result.Error | Should BeNullOrEmpty + $result.Output.output.method | Should Be "TEST" + } + + It "Validate Invoke-RestMethod default ContentType for CustomMethod POST" { + + $command = "Invoke-RestMethod -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'" + $result = ExecuteWebCommand -command $command + $result.Output.headers.'Content-Type' | Should Be "application/x-www-form-urlencoded" + } + + It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET" { + + $command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}" + $result = ExecuteWebCommand -command $command + $result.Output.args.testparam | Should Be "testvalue" + } + It "Invoke-RestMethod supports request that returns plain text response." { $command = "Invoke-RestMethod -Uri 'http://httpbin.org/encoding/utf8'" From f5db053820c8ec6716eca1755d8b150331034beb Mon Sep 17 00:00:00 2001 From: Lee Date: Sat, 4 Mar 2017 00:09:11 +0000 Subject: [PATCH 5/5] Fix webcmdlet tests - incorrect parameter name --- .../Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 46dfb817bd8..07e65489f60 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -419,12 +419,12 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $command = "Invoke-WebRequest -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'" $result = ExecuteWebCommand -command $command - ($result.Output.Content | ConvertFrom-Json).headers.'Content-Type' | Should Be "application/x-www-form-urlencoded" + ($result.Output.Content | ConvertFrom-Json).form.testparam | Should Be "testvalue" } It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET" { - $command = "Invoke-WebRequest -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}" + $command = "Invoke-WebRequest -Uri 'http://httpbin.org/get' -CustomMethod GET -Body @{'testparam'='testvalue'}" $result = ExecuteWebCommand -command $command ($result.Output.Content | ConvertFrom-Json).args.testparam | Should Be "testvalue" } @@ -696,12 +696,12 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $command = "Invoke-RestMethod -Uri 'http://httpbin.org/post' -CustomMethod POST -Body 'testparam=testvalue'" $result = ExecuteWebCommand -command $command - $result.Output.headers.'Content-Type' | Should Be "application/x-www-form-urlencoded" + $result.Output.form.testparam | Should Be "testvalue" } It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET" { - $command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -Method GET -Body @{'testparam'='testvalue'}" + $command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -CustomMethod GET -Body @{'testparam'='testvalue'}" $result = ExecuteWebCommand -command $command $result.Output.args.testparam | Should Be "testvalue" }