GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move WebCmdlets HTTPS tests to WebListener by markekraus · Pull Request #4733 · PowerShell/PowerShell

Move WebCmdlets HTTPS tests to WebListener #4733

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.

Sign up for GitHub

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

Merged
Ilya (iSazonov) merged 5 commits into PowerShell:master from markekraus:HttpsLocalTests
Sep 1, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

Move WebCmdlets HTTPS tests to WebListener #4733

Changes from 4 commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
ddb0e07
Move HTTPS tests to WebListener
markekraus Aug 31, 2017
4b2a915
Move Invoke-WebRequest HTTPS Tests to Context
markekraus Aug 31, 2017
00cae5b
[Feature] Move Invoke-RestMethod HTTPS Tests to Context
markekraus Aug 31, 2017
e68c95f
[feature] Address PR Feedback
markekraus Sep 1, 2017
e41d1dd
[feature] Mark Cert Auth Tests Pending
markekraus Sep 1, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

173 changes: 85 additions & 88 deletions 173 test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -683,19 +683,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell"
}

It "Validate Invoke-WebRequest -SkipCertificateCheck" {

# validate that exception is thrown for URI with expired certificate
$command = "Invoke-WebRequest -Uri 'https://expired.badssl.com'"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"

# validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option
$command = "Invoke-WebRequest -Uri 'https://expired.badssl.com' -SkipCertificateCheck"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
}

It "Validate Invoke-WebRequest handles missing Content-Type in response header" {

#Validate that exception is not thrown when response headers are missing Content-Type.
Expand Down Expand Up @@ -746,16 +733,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

It "Validate Invoke-WebRequest returns native HTTPS error message in exception" {

$command = "Invoke-WebRequest -Uri https://incomplete.chain.badssl.com"
$result = ExecuteWebCommand -command $command

# need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same
$result.Error.ErrorDetails.Message | Should Match $result.Error.Exception.InnerException.Message
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

It "Validate Invoke-WebRequest returns empty RelationLink property if there is no Link Header" {

$command = "Invoke-WebRequest -Uri http://localhost:8080/PowerShell?test=response"
Expand Down Expand Up @@ -1174,32 +1151,54 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {

#endregion Content Header Inclusion

#region Client Certificate Authentication

It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$result = Invoke-WebRequest -Uri $uri -SkipCertificateCheck |
Select-Object -ExpandProperty Content |
ConvertFrom-Json
Context "HTTPS Tests" {
It "Validate Invoke-WebRequest -SkipCertificateCheck" {
# validate that exception is thrown for URI with expired certificate
$Uri = Get-WebListenerUrl -Https
$command = "Invoke-WebRequest -Uri '$Uri'"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"

# validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option
$Uri = Get-WebListenerUrl -Https
$command = "Invoke-WebRequest -Uri '$Uri' -SkipCertificateCheck"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
}

$result.Status | Should Be 'FAILED'
}

# Test skipped on macOS pending support for Client Certificate Authentication
# https://github.com/PowerShell/PowerShell/issues/4650
It "Verifies Invoke-WebRequest Certificate Authentication Successful with -Certificate" -skip:$IsOSX {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$certificate = Get-WebListenerClientCertificate
$result = Invoke-WebRequest -Uri $uri -Certificate $certificate -SkipCertificateCheck |
Select-Object -ExpandProperty Content |
ConvertFrom-Json
It "Validate Invoke-WebRequest returns native HTTPS error message in exception" {
$uri = Get-WebListenerUrl -Https
$command = "Invoke-WebRequest -Uri '$uri'"
$result = ExecuteWebCommand -command $command

# need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same
$result.Error.ErrorDetails.Message | Should Match $result.Error.Exception.InnerException.Message
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}

$result.Status | Should Be 'OK'
$result.Thumbprint | Should Be $certificate.Thumbprint
It "Verifies Invoke-WebRequest Certificate Authentication Fails without -Certificate" {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$result = Invoke-WebRequest -Uri $uri -SkipCertificateCheck |
Select-Object -ExpandProperty Content |
ConvertFrom-Json

$result.Status | Should Be 'FAILED'
}

# Test skipped on macOS pending support for Client Certificate Authentication
# https://github.com/PowerShell/PowerShell/issues/4650
It "Verifies Invoke-WebRequest Certificate Authentication Successful with -Certificate" -skip:$IsOSX {
Comment thread Outdated

@JamesWTruher James Truher (JamesWTruher) Sep 1, 2017

Copy link
Copy Markdown
Collaborator

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.

if this is eventually going to be run on mac, could you make this -pending:$IsOSX? we track pending tests more closely than skipped tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markekraus Mark Kraus (markekraus) Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

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.

I will switch them to pending. I was asked to "skip" them but perhaps they didn't mean literally to use -skip

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Sep 1, 2017

Copy link
Copy Markdown
Collaborator

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, my bad.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$certificate = Get-WebListenerClientCertificate
$result = Invoke-WebRequest -Uri $uri -Certificate $certificate -SkipCertificateCheck |
Select-Object -ExpandProperty Content |
ConvertFrom-Json

$result.Status | Should Be 'OK'
$result.Thumbprint | Should Be $certificate.Thumbprint
}
}

#endregion Client Certificate Authentication

BeforeEach {
if ($env:http_proxy) {
$savedHttpProxy = $env:http_proxy
Expand Down Expand Up @@ -1491,20 +1490,6 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
$jsonContent.headers.'User-Agent' | Should Match "WindowsPowerShell"
}

It "Validate Invoke-RestMethod -SkipCertificateCheck" {

# HTTP method HEAD must be used to not retrieve an unparsable HTTP body
# validate that exception is thrown for URI with expired certificate
$command = "Invoke-RestMethod -Uri 'https://expired.badssl.com' -Method HEAD"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"

# validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option
$command = "Invoke-RestMethod -Uri 'https://expired.badssl.com' -SkipCertificateCheck -Method HEAD"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
}

It "Validate Invoke-RestMethod handles missing Content-Type in response header" {

#Validate that exception is not thrown when response headers are missing Content-Type.
Expand Down Expand Up @@ -1561,16 +1546,6 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Validate Invoke-RestMethod returns native HTTPS error message in exception" {

$command = "Invoke-RestMethod -Uri https://incomplete.chain.badssl.com"
$result = ExecuteWebCommand -command $command

# need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same
$result.Error.ErrorDetails.Message | Should Match $result.Error.Exception.InnerException.Message
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Validate Invoke-RestMethod -FollowRelLink doesn't fail if no Link Header is present" {

$command = "Invoke-RestMethod -Uri 'http://localhost:8081/PowerShell?test=response&output=foo' -FollowRelLink"
Expand Down Expand Up @@ -1719,28 +1694,50 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {

#endregion SkipHeaderVerification tests

#region Client Certificate Authentication

It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$result = Invoke-RestMethod -Uri $uri -SkipCertificateCheck
Context "HTTPS Tests" {
It "Validate Invoke-RestMethod -SkipCertificateCheck" {
# HTTP method HEAD must be used to not retrieve an unparsable HTTP body
# validate that exception is thrown for URI with expired certificate
$uri= Get-WebListenerUrl -Https
$command = "Invoke-RestMethod -Uri '$uri' -Method HEAD"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"

# validate that no exception is thrown for URI with expired certificate when using -SkipCertificateCheck option
$command = "Invoke-RestMethod -Uri '$uri' -SkipCertificateCheck -Method HEAD"
$result = ExecuteWebCommand -command $command
$result.Error | Should BeNullOrEmpty
}

$result.Status | Should Be 'FAILED'
}

# Test skipped on macOS pending support for Client Certificate Authentication
# https://github.com/PowerShell/PowerShell/issues/4650
It "Verifies Invoke-RestMethod Certificate Authentication Successful with -Certificate" -skip:$IsOSX {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$certificate = Get-WebListenerClientCertificate
$result = Invoke-RestMethod -uri $uri -Certificate $certificate -SkipCertificateCheck

$result.Status | Should Be 'OK'
$result.Thumbprint | Should Be $certificate.Thumbprint
It "Validate Invoke-RestMethod returns native HTTPS error message in exception" {
$uri = Get-WebListenerUrl -Https
$command = "Invoke-RestMethod -Uri '$uri'"
$result = ExecuteWebCommand -command $command

# need to check against inner exception since Linux and Windows uses different HTTP client libraries so errors aren't the same
$result.Error.ErrorDetails.Message | Should Match $result.Error.Exception.InnerException.Message
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Verifies Invoke-RestMethod Certificate Authentication Fails without -Certificate" {
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$result = Invoke-RestMethod -Uri $uri -SkipCertificateCheck

$result.Status | Should Be 'FAILED'
}

# Test skipped on macOS pending support for Client Certificate Authentication
# https://github.com/PowerShell/PowerShell/issues/4650
It "Verifies Invoke-RestMethod Certificate Authentication Successful with -Certificate" -skip:$IsOSX {
Comment thread Outdated

@JamesWTruher James Truher (JamesWTruher) Sep 1, 2017

Copy link
Copy Markdown
Collaborator

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.

same as above - not sure whether this should be -pending rather than -skip

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
$uri = Get-WebListenerUrl -Https -Test 'Cert'
$certificate = Get-WebListenerClientCertificate
$result = Invoke-RestMethod -uri $uri -Certificate $certificate -SkipCertificateCheck

$result.Status | Should Be 'OK'
$result.Thumbprint | Should Be $certificate.Thumbprint
}
}

#endregion Client Certificate Authentication

#region charset encoding tests

Context "Invoke-RestMethod Encoding tests with BasicHtmlWebResponseObject response" {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.