Replace httpbin.org/get tests With WebListener (#4738)

* Adds the /Get/ functionality to Weblistener
* Replaces the tests that rely on httpbin.org/get with WebListener


* [Feature] Move HttpBin/Get Tests to WebListener

* [Feature] update .spelling

* [Feature] Address PR Feedback

* [Feature] Add and document Home & /

* Readme Update

* [Feature] Should Match -> Should Be

Rerun CI

* [Feature] Rebase and Rerun CI
This commit is contained in:
Mark Kraus
2017-09-08 07:53:04 +04:00
committed by Ilya
parent 3c597367ba
commit f41461825a
7 changed files with 111 additions and 26 deletions
+1
View File
@@ -56,6 +56,7 @@ hashtable
hashtables
homebrew
hotfix
HttpBin's
init
Invoke-RestMethod
Invoke-WebRequest
@@ -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"
}
@@ -112,6 +112,12 @@ function Get-WebListenerUrl {
[OutputType([Uri])]
param (
[switch]$Https,
[ValidateSet(
'Cert',
'Get',
'Home',
'/'
)]
[String]$Test
)
process {
+9
View File
@@ -0,0 +1,9 @@
using System;
namespace mvc.Controllers
{
internal static class Constants
{
public const string HeaderSeparator = ", ";
}
}
@@ -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 });
}
}
}
+29 -1
View File
@@ -1,6 +1,6 @@
# WebListener App
ASP.NET Core 2.0 app for testing HTTP and HTTPS Requests. The default page will return a list of available tests.
ASP.NET Core 2.0 app for testing HTTP and HTTPS Requests.
# Run with `dotnet`
@@ -30,6 +30,10 @@ $Listener = Start-WebListener -HttpPort 8083 -HttpsPort 8084
# Tests
## / or /Home/
Returns a static HTML page containing links and descriptions of the available tests in WebListener. This can be used as a default or general test where no specific test functionality or return data is required.
## /Cert/
Returns a JSON object containing the details of the Client Certificate if one is provided in the request.
@@ -54,3 +58,27 @@ Response when certificate is not provided in request:
"Status": "FAILED"
}
```
## /Get/
Returns a JSON object containing the Request URL, Request Headers, GET Query Fields and Values, and Origin IP. This emulates the functionality of [HttpBin's get test](https://httpbin.org/get).
```powershell
Invoke-WebRequest -Uri 'http://localhost:8083/Get/' -Body @{TestField = 'TestValue'}
```
```json
{
"url": "http://localhost:8083/Get/?TestField=TestValue",
"args": {
"TestField": "TestValue"
},
"headers": {
"Connection": "Keep-Alive",
"User-Agent": "Mozilla/5.0 (Windows NT; Microsoft Windows 10.0.15063 ; en-US) WindowsPowerShell/6.0.0",
"Host": "localhost:8083"
},
"origin": "127.0.0.1"
}
```
@@ -2,4 +2,5 @@
<ul>
<li><a href="/">/</a> - This page</li>
<li><a href="/Cert/">/Cert/</a> - Client Certificate Details</li>
<li><a href="/Get/">/Get/</a> - Emulates functionality of https://httpbin.org/get by returning GET headers, Arguments, and Request URL</li>
</ul>