-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Replace httpbin.org/get tests With WebListener #4738
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
Changes from all commits
bd7f2d4
fbec6f8
2118551
5c9ab0b
4f7f796
2aa18fd
02265ca
a35adde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ hashtable | |
| hashtables | ||
| homebrew | ||
| hotfix | ||
| HttpBin's | ||
| init | ||
| Invoke-RestMethod | ||
| Invoke-WebRequest | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ function ExecuteRequestWithOutFile | |
| [string] | ||
| $cmdletName, | ||
| [string] | ||
| $uri = "http://httpbin.org/get" | ||
| $uri = (Get-WebListenerUrl -Test 'Get') | ||
| ) | ||
|
|
||
| $result = [PSObject]@{Output = $null; Error = $null} | ||
|
|
@@ -82,7 +82,7 @@ function ExecuteRequestWithHeaders | |
| [string] | ||
| $cmdletName, | ||
| [string] | ||
| $uri = "http://httpbin.org/get" | ||
| $uri = (Get-WebListenerUrl -Test 'Get') | ||
|
||
| ) | ||
|
|
||
| $result = [PSObject]@{Output = $null; Error = $null} | ||
|
|
@@ -442,13 +442,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
| It "Validate Invoke-WebRequest -DisableKeepAlive" { | ||
|
|
||
| # Operation options | ||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $command = "Invoke-WebRequest -Uri $uri -TimeoutSec 5 -DisableKeepAlive" | ||
|
|
||
| $result = ExecuteWebCommand -command $command | ||
| ValidateResponse -response $result | ||
|
|
||
| $result.Output.Headers["Connection"] | Should Be "Close" | ||
| $result.Output.Headers.Connection | Should Be "Close" | ||
| } | ||
|
|
||
| It "Validate Invoke-WebRequest -MaximumRedirection" { | ||
|
|
@@ -641,10 +641,10 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
|
|
||
| It "Validate Invoke-WebRequest -Headers --> Set KeepAlive to false via headers" { | ||
|
|
||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $result = ExecuteRequestWithHeaders -cmdletName Invoke-WebRequest -uri $uri | ||
| ValidateResponse -response $result | ||
| $result.Output.Headers["Connection"] | Should Be "Close" | ||
| $result.Output.Headers.Connection | Should Be "Close" | ||
| } | ||
|
|
||
| # Validate all available user agents for Invoke-WebRequest | ||
|
|
@@ -658,7 +658,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
| foreach ($agentName in $agents.Keys) | ||
| { | ||
| $expectedAgent = $agents[$agentName] | ||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $userAgent = "[Microsoft.PowerShell.Commands.PSUserAgent]::$agentName" | ||
| $command = "Invoke-WebRequest -Uri $uri -UserAgent ($userAgent) -TimeoutSec 5" | ||
|
|
||
|
|
@@ -669,17 +669,17 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
|
|
||
| # Validate response content | ||
| $jsonContent = $result.Output.Content | ConvertFrom-Json | ||
| $jsonContent.headers.Host | Should Match "httpbin.org" | ||
| $jsonContent.headers.Host | Should Be $uri.Authority | ||
| $jsonContent.headers.'User-Agent' | Should Match $expectedAgent | ||
| } | ||
| } | ||
|
|
||
| It "Validate Invoke-WebRequest -OutFile" { | ||
|
|
||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $result = ExecuteRequestWithOutFile -cmdletName "Invoke-WebRequest" -uri $uri | ||
| $jsonContent = $result.Output | ConvertFrom-Json | ||
| $jsonContent.headers.Host | Should Match "httpbin.org" | ||
| $jsonContent.headers.Host | Should Be $uri.Authority | ||
| $jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell" | ||
| } | ||
|
|
||
|
|
@@ -715,7 +715,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { | |
|
|
||
| It "Validate Invoke-WebRequest body is converted to query params for CustomMethod GET" { | ||
|
|
||
| $command = "Invoke-WebRequest -Uri 'http://httpbin.org/get' -CustomMethod GET -Body @{'testparam'='testvalue'}" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $command = "Invoke-WebRequest -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'}" | ||
|
||
| $result = ExecuteWebCommand -command $command | ||
| ($result.Output.Content | ConvertFrom-Json).args.testparam | Should Be "testvalue" | ||
| } | ||
|
|
@@ -1262,16 +1263,15 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |
| It "Validate Invoke-RestMethod -DisableKeepAlive" { | ||
|
|
||
| # Operation options | ||
| $command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -TimeoutSec 5 -DisableKeepAlive" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 5 -DisableKeepAlive" | ||
|
||
|
|
||
| $result = ExecuteWebCommand -command $command | ||
|
|
||
| # Validate response | ||
| $result.Output.headers.Host | Should Match "httpbin.org" | ||
| $result.Output.headers.Host | Should Be $uri.Authority | ||
| $result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | ||
|
|
||
| # Unfortunately, the connection information is not display in the output of Invoke-RestMethod | ||
| #$result.Output.Headers["Connection"] | Should Be "Close" | ||
| $result.Output.Headers.Connection | Should Be "Close" | ||
| } | ||
|
|
||
| It "Validate Invoke-RestMethod -MaximumRedirection" { | ||
|
|
@@ -1445,15 +1445,13 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |
|
|
||
| It "Validate Invoke-RestMethod -Headers --> Set KeepAlive to false via headers" { | ||
|
|
||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $result = ExecuteRequestWithHeaders -cmdletName Invoke-RestMethod -uri $uri | ||
|
|
||
| # Validate response | ||
| $result.Output.url | Should Match $uri | ||
| $result.Output.headers.'User-Agent' | Should Match "WindowsPowerShell" | ||
|
|
||
| # Unfortunately, the connection information is not display in the output of Invoke-RestMethod | ||
| #$result.Output.Headers["Connection"] | Should Be "Close" | ||
| $result.Output.Headers.Connection | Should Be "Close" | ||
| } | ||
|
|
||
| # Validate all available user agents for Invoke-RestMethod | ||
|
|
@@ -1467,7 +1465,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |
| foreach ($agentName in $agents.Keys) | ||
| { | ||
| $expectedAgent = $agents[$agentName] | ||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $userAgent = "[Microsoft.PowerShell.Commands.PSUserAgent]::$agentName" | ||
| $command = "Invoke-RestMethod -Uri $uri -UserAgent ($userAgent) -TimeoutSec 5" | ||
|
|
||
|
|
@@ -1476,17 +1474,17 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |
| $result = ExecuteWebCommand -command $command | ||
|
|
||
| # Validate response | ||
| $result.Output.headers.Host | Should Match "httpbin.org" | ||
| $result.Output.headers.Host | Should Be $uri.Authority | ||
| $result.Output.headers.'User-Agent' | Should Match $expectedAgent | ||
| } | ||
| } | ||
|
|
||
| It "Validate Invoke-RestMethod -OutFile" { | ||
|
|
||
| $uri = "http://httpbin.org/get" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $result = ExecuteRequestWithOutFile -cmdletName "Invoke-RestMethod" -uri $uri | ||
| $jsonContent = $result.Output | ConvertFrom-Json | ||
| $jsonContent.headers.Host | Should Match "httpbin.org" | ||
| $jsonContent.headers.Host | Should Be $uri.Authority | ||
| $jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell" | ||
| } | ||
|
|
||
|
|
@@ -1521,7 +1519,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { | |
|
|
||
| It "Validate Invoke-RestMethod body is converted to query params for CustomMethod GET" { | ||
|
|
||
| $command = "Invoke-RestMethod -Uri 'http://httpbin.org/get' -CustomMethod GET -Body @{'testparam'='testvalue'}" | ||
| $uri = Get-WebListenerUrl -Test 'Get' | ||
| $command = "Invoke-RestMethod -Uri '$uri' -CustomMethod GET -Body @{'testparam'='testvalue'}" | ||
| $result = ExecuteWebCommand -command $command | ||
| $result.Output.args.testparam | Should Be "testvalue" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System; | ||
|
|
||
| namespace mvc.Controllers | ||
| { | ||
| internal static class Constants | ||
| { | ||
| public const string HeaderSeparator = ", "; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Http.Extensions; | ||
| using mvc.Models; | ||
|
|
||
| namespace mvc.Controllers | ||
| { | ||
| public class GetController : Controller | ||
| { | ||
| public JsonResult Index() | ||
| { | ||
| Hashtable args = new Hashtable(); | ||
| foreach (var key in Request.Query.Keys) | ||
| { | ||
| args.Add(key, String.Join(Constants.HeaderSeparator, Request.Query[key])); | ||
| } | ||
| Hashtable headers = new Hashtable(); | ||
| foreach (var key in Request.Headers.Keys) | ||
| { | ||
| headers.Add(key, String.Join(Constants.HeaderSeparator, Request.Headers[key])); | ||
| } | ||
| Hashtable output = new Hashtable | ||
| { | ||
| {"args" , args}, | ||
| {"headers", headers}, | ||
| {"origin" , Request.HttpContext.Connection.RemoteIpAddress.ToString()}, | ||
| {"url" , UriHelper.GetDisplayUrl(Request)} | ||
| }; | ||
| return Json(output); | ||
| } | ||
| public IActionResult Error() | ||
| { | ||
| return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove parentheses.
We use this many times - can we move the line to BeforeAll?
It seems the time has come to add
ValidateSet()toGet-WebListenerUrlparameters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm mistaken, the Parens are required when assign a default value with a statement in a Param block. At your suggestion I tried removing them but I get all kinds of errors.
As for moving this to the BeforeAll block, I don't think that makes sense in this context since this is part of the
ExecuteRequestWithOutFilefunction.For the more general concern, we could create a variable, but, as we move the other tests over you will see that it will get less possible to do so in the
BeforeAllBlock without losing meaning in theItblocks (in the case where there will be a query string required as well). I would prefer we keep the URL generation to eachItblock for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry - My thoughts was about many
Get-WebListenerUrl -Test 'Get'in the file - I see only 10 times so I think we can keep it as is.