Skip to content
Merged
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 @@ -809,55 +809,61 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
#region SkipHeaderVerification Tests

It "Verifies Invoke-WebRequest default header handling with no errors" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "*"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8080/PowerShell?test=echo" -headers $headers
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers

$response.Error | Should BeNullOrEmpty
$response.Content.Headers -contains "If-Match" | Should Be $true
$response.Content.Headers."If-Match" | Should BeExactly "*"
}

It "Verifies Invoke-WebRequest default header handling reports an error is returned for an invalid If-Match header value" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "12345"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8080/PowerShell?test=echo" -headers $headers
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers

$response.Error | Should Not BeNullOrEmpty
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
$response.Error.Exception.Message | Should Be "The format of value '12345' is invalid."
}

It "Verifies Invoke-WebRequest header handling does not report an error when using -SkipHeaderValidation" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "12345"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8080/PowerShell?test=echo" -headers $headers -SkipHeaderValidation
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -SkipHeaderValidation

$response.Error | Should BeNullOrEmpty
$response.Content.Headers -contains "If-Match" | Should Be $true
$response.Content.Headers."If-Match" | Should BeExactly "12345"
}

It "Verifies Invoke-WebRequest default UserAgent handling with no errors" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8080/PowerShell?test=echo" -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest"

$response.Error | Should BeNullOrEmpty
$Pattern = [regex]::Escape($UserAgent)
$response.Content.UserAgent | Should Match $Pattern
$response.Content.Headers."User-Agent" | Should Match $Pattern
}

It "Verifies Invoke-WebRequest default UserAgent handling reports an error is returned for an invalid UserAgent value" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = 'Invalid:Agent'
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8080/PowerShell?test=echo" -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-WebRequest"

$response.Error | Should Not BeNullOrEmpty
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
$response.Error.Exception.Message | Should Be "The format of value 'Invalid:Agent' is invalid."
}

It "Verifies Invoke-WebRequest UserAgent handling does not report an error when using -SkipHeaderValidation" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = 'Invalid:Agent'
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8080/PowerShell?test=echo" -UserAgent $UserAgent -SkipHeaderValidation -Cmdlet "Invoke-WebRequest"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -SkipHeaderValidation -Cmdlet "Invoke-WebRequest"

$response.Error | Should BeNullOrEmpty
$Pattern = [regex]::Escape($UserAgent)
$response.Content.UserAgent | Should Match $Pattern
$response.Content.Headers."User-Agent" | Should Match $Pattern
}

#endregion SkipHeaderVerification Tests
Expand Down Expand Up @@ -1804,55 +1810,61 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
#region SkipHeaderVerification tests

It "Verifies Invoke-RestMethod default header handling with no errors" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "*"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8081/PowerShell?test=echo" -headers $headers -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -Cmdlet "Invoke-RestMethod"

$response.Error | Should BeNullOrEmpty
$response.Content.Headers -contains "If-Match" | Should Be $true
$response.Content.Headers."If-Match" | Should BeExactly "*"
}

It "Verifies Invoke-RestMethod default header handling reports an error is returned for an invalid If-Match header value" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "12345"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8081/PowerShell?test=echo" -headers $headers -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -Cmdlet "Invoke-RestMethod"

$response.Error | Should Not BeNullOrEmpty
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
$response.Error.Exception.Message | Should Be "The format of value '12345' is invalid."
}

It "Verifies Invoke-RestMethod header handling does not report an error when using -SkipHeaderValidation" {
$uri = Get-WebListenerUrl -Test 'Get'
$headers = @{"If-Match" = "12345"}
$response = ExecuteRequestWithCustomHeaders -Uri "http://localhost:8081/PowerShell?test=echo" -headers $headers -SkipHeaderValidation -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomHeaders -Uri $uri -headers $headers -SkipHeaderValidation -Cmdlet "Invoke-RestMethod"

$response.Error | Should BeNullOrEmpty
$response.Content.Headers -contains "If-Match" | Should Be $true
$response.Content.Headers."If-Match" | Should BeExactly "12345"
}

It "Verifies Invoke-RestMethod default UserAgent handling with no errors" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8081/PowerShell?test=echo" -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod"

$response.Error | Should BeNullOrEmpty
$Pattern = [regex]::Escape($UserAgent)
$response.Content.UserAgent | Should Match $Pattern
$response.Content.Headers."User-Agent" | Should Match $Pattern
}

It "Verifies Invoke-RestMethod default UserAgent handling reports an error is returned for an invalid UserAgent value" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = 'Invalid:Agent'
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8081/PowerShell?test=echo" -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -Cmdlet "Invoke-RestMethod"

$response.Error | Should Not BeNullOrEmpty
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
$response.Error.Exception.Message | Should Be "The format of value 'Invalid:Agent' is invalid."
}

It "Verifies Invoke-RestMethod UserAgent handling does not report an error when using -SkipHeaderValidation" {
$uri = Get-WebListenerUrl -Test 'Get'
$UserAgent = 'Invalid:Agent'
$response = ExecuteRequestWithCustomUserAgent -Uri "http://localhost:8081/PowerShell?test=echo" -UserAgent $UserAgent -SkipHeaderValidation -Cmdlet "Invoke-RestMethod"
$response = ExecuteRequestWithCustomUserAgent -Uri $uri -UserAgent $UserAgent -SkipHeaderValidation -Cmdlet "Invoke-RestMethod"

$response.Error | Should BeNullOrEmpty
$Pattern = [regex]::Escape($UserAgent)
$response.Content.UserAgent | Should Match $Pattern
$response.Content.Headers."User-Agent" | Should Match $Pattern
}

#endregion SkipHeaderVerification tests
Expand Down