8000 Move WebCmdlets HTTPS tests to WebListener by markekraus · Pull Request #4733 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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.

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
merged 5 commits into from
Sep 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to 8000
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Certif 8000 icate Authentication Successful with -Certificate" -Pending:$IsOSX {
$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" -Pending:$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
}
}

#endregion Client Certificate Authentication

#region charset encoding tests

Context "Invoke-RestMethod Encoding tests with BasicHtmlWebResponseObject response" {
Expand Down
0