PowerShell/test/tools/WebListener
Mark Kraus f41461825a 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
2017-09-08 07:53:04 +04:00
..
Controllers Replace httpbin.org/get tests With WebListener (#4738) 2017-09-08 07:53:04 +04:00
Models Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00
Views Replace httpbin.org/get tests With WebListener (#4738) 2017-09-08 07:53:04 +04:00
appsettings.Development.json Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00
appsettings.json Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00
Constants.cs Replace httpbin.org/get tests With WebListener (#4738) 2017-09-08 07:53:04 +04:00
Program.cs Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00
README.md Replace httpbin.org/get tests With WebListener (#4738) 2017-09-08 07:53:04 +04:00
Startup.cs Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00
WebListener.csproj Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) 2017-08-31 13:30:35 +04:00

WebListener App

ASP.NET Core 2.0 app for testing HTTP and HTTPS Requests.

Run with dotnet

dotnet restore
dotnet publish --output bin --configuration Release
cd bin
dotnet WebListener.dll ServerCert.pfx password 8083 8084

The test site can then be accessed via http://localhost:8083/ or https://localhost:8084/.

The WebListener.dll takes 4 arguments:

  • The path to the Server Certificate
  • The Server Certificate Password
  • The TCP Port to bind on for HTTP
  • The TCP Port to bind on for HTTPS

Run With WebListener Module

Import-Module .\build.psm1
Publish-PSTestTools
$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.

Response when certificate is provided in request:

{
  "Status": "OK",
  "IssuerName": "E=randd@adatum.com, CN=adatum.com, OU=R&D, O=A. Datum Corporation, L=Redmond, S=Washington, C=US",
  "SubjectName": "E=randd@adatum.com, CN=adatum.com, OU=R&D, O=A. Datum Corporation, L=Redmond, S=Washington, C=US",
  "NotAfter": "2044-12-26T12:16:46-06:00",
  "Issuer": "E=randd@adatum.com, CN=adatum.com, OU=R&D, O=A. Datum Corporation, L=Redmond, S=Washington, C=US",
  "Subject": "E=randd@adatum.com, CN=adatum.com, OU=R&D, O=A. Datum Corporation, L=Redmond, S=Washington, C=US",
  "NotBefore": "2017-08-10T13:16:46-05:00",
  "Thumbprint": "2DECF1348FF21B780F45D316A039B5EB4C6312F7"
}

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.

Invoke-WebRequest -Uri 'http://localhost:8083/Get/' -Body @{TestField = 'TestValue'}
{
  "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"
}