Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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 @@ -494,7 +494,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {

It "Validate Invoke-WebRequest -MaximumRedirection" {

$uri = Get-WebListenerUrl -Test 'Redirect/3'
$uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3'
$command = "Invoke-WebRequest -Uri '$uri' -MaximumRedirection 4"

$result = ExecuteWebCommand -command $command
Expand All @@ -508,7 +508,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {

It "Validate Invoke-WebRequest error for -MaximumRedirection" {

$uri = Get-WebListenerUrl -Test 'Redirect/3'
$uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3'
$command = "Invoke-WebRequest -Uri '$uri' -MaximumRedirection 2"

$result = ExecuteWebCommand -command $command
Expand All @@ -517,7 +517,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {

It "Invoke-WebRequest supports request that returns page containing UTF-8 data." {

$uri = Get-WebListenerUrl -Test 'Encoding/Utf8'
$uri = Get-WebListenerUrl -Test 'Encoding' -TestValue 'Utf8'
$command = "Invoke-WebRequest -Uri '$uri'"

$result = ExecuteWebCommand -command $command
Expand All @@ -529,15 +529,17 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {

It "Invoke-WebRequest validate timeout option" {

$command = "Invoke-WebRequest -Uri http://httpbin.org/delay/:5 -TimeoutSec 5"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5'
$command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 5"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" {

$command = "Invoke-WebRequest -Uri http://httpbin.org/delay/:10 -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10'
$command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
Expand All @@ -551,10 +553,11 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
It "Validate Invoke-WebRequest error with -Proxy option set - '<name>'" -TestCases $testCase {
param($proxy_address, $name, $protocol)

$command = "Invoke-WebRequest -Uri '${protocol}://httpbin.org/delay/:5' -TimeoutSec 5 -Proxy '${proxy_address}'"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https')
$command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 5 -Proxy '${proxy_address}' -SkipCertificateCheck"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

It "Validate Invoke-WebRequest error with environment proxy set - '<name>'" -TestCases $testCase {
Expand All @@ -563,10 +566,11 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
# Configure the environment variable.
New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force

$command = "Invoke-WebRequest -Uri '${protocol}://httpbin.org/delay/:5' -TimeoutSec 5"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https')
$command = "Invoke-WebRequest -Uri '$uri' -TimeoutSec 5 -SkipCertificateCheck"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

It "Validate Invoke-WebRequest returns User-Agent where -NoProxy with envirionment proxy set - '<name>'" -TestCases $testCase {
Expand All @@ -587,14 +591,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell"
}

It "Invoke-WebRequest validate timeout option" {

$command = "Invoke-WebRequest -Uri http://httpbin.org/delay/:5 -TimeoutSec 10"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

# Perform the following operation for Invoke-WebRequest
# gzip Returns gzip-encoded data.
# deflate Returns deflate-encoded data.
Expand Down Expand Up @@ -1353,7 +1349,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {

It "Validate Invoke-RestMethod -MaximumRedirection" {

$uri = Get-WebListenerUrl -Test 'Redirect/3'
$uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3'
$command = "Invoke-RestMethod -Uri '$uri' -MaximumRedirection 4"

$result = ExecuteWebCommand -command $command
Expand All @@ -1365,7 +1361,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {

It "Validate Invoke-RestMethod error for -MaximumRedirection" {

$uri = Get-WebListenerUrl -Test 'Redirect/3'
$uri = Get-WebListenerUrl -Test 'Redirect' -TestValue '3'
$command = "Invoke-RestMethod -Uri '$uri' -MaximumRedirection 2"

$result = ExecuteWebCommand -command $command
Expand All @@ -1374,7 +1370,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {

It "Invoke-RestMethod supports request that returns page containing UTF-8 data." {

$uri = Get-WebListenerUrl -Test 'Encoding/Utf8'
$uri = Get-WebListenerUrl -Test 'Encoding' -TestValue 'Utf8'
$command = "Invoke-RestMethod -Uri '$uri'"

$result = ExecuteWebCommand -command $command
Expand All @@ -1383,15 +1379,17 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {

It "Invoke-RestMethod validate timeout option" {

$command = "Invoke-RestMethod -Uri http://httpbin.org/delay/:5 -TimeoutSec 2"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5'
$command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 2"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" {

$command = "Invoke-RestMethod -Uri http://httpbin.org/delay/:10 -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10'
$command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
Expand All @@ -1417,10 +1415,11 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
# Configure the environment variable.
New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force

$command = "Invoke-RestMethod -Uri '${protocol}://httpbin.org/delay/:5' -TimeoutSec 5"
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' -Https:$($protocol -eq 'https')
$command = "Invoke-RestMethod -Uri '$uri' -TimeoutSec 5 -SkipCertificateCheck"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Validate Invoke-RestMethod returns User-Agent with option -NoProxy when environment proxy set - '<name>'" -TestCases $testCase {
Expand Down
11 changes: 7 additions & 4 deletions 11 test/tools/Modules/WebListener/WebListener.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ function Get-WebListenerUrl {
[switch]$Https,
[ValidateSet(
'Cert',
'Encoding/Utf8',
'Delay',
'Encoding',
'Get',
'Home',
'Multipart',
'Redirect/3',
'Redirect',
'/'
)]
[String]$Test
[String]$Test,

[String]$TestValue
)
process {
$runningListener = Get-WebListener
Expand All @@ -138,7 +141,7 @@ function Get-WebListenerUrl {
$Uri.Port = $runningListener.HttpsPort
$Uri.Scheme = 'Https'
}
$Uri.Path = $Test
$Uri.Path = '{0}/{1}' -f $Test, $TestValue
return [Uri]$Uri.ToString()
}
}
32 changes: 32 additions & 0 deletions 32 test/tools/WebListener/Controllers/DelayController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http.Extensions;
using mvc.Models;

namespace mvc.Controllers
{
public class DelayController : Controller
{
public JsonResult Index(int seconds)
{
if (seconds > 0){
int milliseconds = seconds * 1000;
Thread.Sleep(milliseconds);
}
var getController = new GetController();
getController.ControllerContext = this.ControllerContext;
return getController.Index();
}

public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
24 changes: 24 additions & 0 deletions 24 test/tools/WebListener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ Response when certificate is not provided in request:
}
```

## /Delay/

Returns the same results as the Get test. If a number is supplied, the server will wait that many seconds before returning a response. This can be used to test timeouts.

```powershell
Invoke-WebRequest -Uri 'http://localhost:8083/Delay/5'

@dantraMSFT dantraMSFT Sep 25, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the tests are using the Get-WebListenerUrl function. Suggest adding an example for that as well.

$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '5' #Closed

@markekraus markekraus Sep 25, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add those on the next iteration. Created #4918 to track. (pull was merged before i could update). #Closed

```

After 5 Seconds:

```json
{
"args": {

},
"origin": "127.0.0.1",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.15063.608",
"Host": "localhost:8083"
},
"url": "http://localhost:8083/Delay/5"
}
```

## /Encoding/Utf8/

Returns page containing UTF-8 data.
Expand Down
5 changes: 5 additions & 0 deletions 5 test/tools/WebListener/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
template: "Redirect/{count?}",
defaults: new {controller = "Redirect", action = "Index"}
);
routes.MapRoute(
name: "delay",
template: "Delay/{seconds?}",
defaults: new {controller = "Delay", action = "Index"}
);
});
}
}
Expand Down
1 change: 1 addition & 0 deletions 1 test/tools/WebListener/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ul>
<li><a href="/">/</a> - This page</li>
<li><a href="/Cert/">/Cert/</a> - Client Certificate Details</li>
<li><a href="/Delay/">/Delay/{seconds}</a> - Delays response for <i>seconds</i> seconds.</li>
<li><a href="/Encoding/Utf8/">/Encoding/Utf8/</a> - Returns page containing UTF-8 data.</li>
<li><a href="/Get/">/Get/</a> - Emulates functionality of https://httpbin.org/get by returning GET headers, Arguments, and Request URL</li>
<li><a href="/Multipart/">/Multipart/</a> - Multipart/form-data submission testing</li>
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.