|
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
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.
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.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
$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
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.
|
|
|
$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
|
|