[Feature] Replace HttpListener Echo Tests with WebListener (#5840)
This commit is contained in:
parent
211ee632dc
commit
c8ccb376b4
1 changed files with 32 additions and 20 deletions
|
@ -807,16 +807,18 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
|
||||||
#region SkipHeaderVerification Tests
|
#region SkipHeaderVerification Tests
|
||||||
|
|
||||||
It "Verifies Invoke-WebRequest default header handling with no errors" {
|
It "Verifies Invoke-WebRequest default header handling with no errors" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$headers = @{"If-Match" = "*"}
|
$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.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" {
|
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"}
|
$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 | Should Not BeNullOrEmpty
|
||||||
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
|
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
|
||||||
|
@ -824,25 +826,28 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Verifies Invoke-WebRequest header handling does not report an error when using -SkipHeaderValidation" {
|
It "Verifies Invoke-WebRequest header handling does not report an error when using -SkipHeaderValidation" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$headers = @{"If-Match" = "12345"}
|
$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.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" {
|
It "Verifies Invoke-WebRequest default UserAgent handling with no errors" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
|
$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
|
$response.Error | Should BeNullOrEmpty
|
||||||
$Pattern = [regex]::Escape($UserAgent)
|
$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" {
|
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'
|
$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 | Should Not BeNullOrEmpty
|
||||||
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
|
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
|
||||||
|
@ -850,12 +855,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Verifies Invoke-WebRequest UserAgent handling does not report an error when using -SkipHeaderValidation" {
|
It "Verifies Invoke-WebRequest UserAgent handling does not report an error when using -SkipHeaderValidation" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$UserAgent = 'Invalid:Agent'
|
$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
|
$response.Error | Should BeNullOrEmpty
|
||||||
$Pattern = [regex]::Escape($UserAgent)
|
$Pattern = [regex]::Escape($UserAgent)
|
||||||
$response.Content.UserAgent | Should Match $Pattern
|
$response.Content.Headers."User-Agent" | Should Match $Pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion SkipHeaderVerification Tests
|
#endregion SkipHeaderVerification Tests
|
||||||
|
@ -1802,16 +1808,18 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
|
||||||
#region SkipHeaderVerification tests
|
#region SkipHeaderVerification tests
|
||||||
|
|
||||||
It "Verifies Invoke-RestMethod default header handling with no errors" {
|
It "Verifies Invoke-RestMethod default header handling with no errors" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$headers = @{"If-Match" = "*"}
|
$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.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" {
|
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"}
|
$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 | Should Not BeNullOrEmpty
|
||||||
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
|
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
|
||||||
|
@ -1819,25 +1827,28 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Verifies Invoke-RestMethod header handling does not report an error when using -SkipHeaderValidation" {
|
It "Verifies Invoke-RestMethod header handling does not report an error when using -SkipHeaderValidation" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$headers = @{"If-Match" = "12345"}
|
$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.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" {
|
It "Verifies Invoke-RestMethod default UserAgent handling with no errors" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
|
$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
|
$response.Error | Should BeNullOrEmpty
|
||||||
$Pattern = [regex]::Escape($UserAgent)
|
$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" {
|
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'
|
$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 | Should Not BeNullOrEmpty
|
||||||
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
|
$response.Error.FullyQualifiedErrorId | Should Be "System.FormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
|
||||||
|
@ -1845,12 +1856,13 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Verifies Invoke-RestMethod UserAgent handling does not report an error when using -SkipHeaderValidation" {
|
It "Verifies Invoke-RestMethod UserAgent handling does not report an error when using -SkipHeaderValidation" {
|
||||||
|
$uri = Get-WebListenerUrl -Test 'Get'
|
||||||
$UserAgent = 'Invalid:Agent'
|
$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
|
$response.Error | Should BeNullOrEmpty
|
||||||
$Pattern = [regex]::Escape($UserAgent)
|
$Pattern = [regex]::Escape($UserAgent)
|
||||||
$response.Content.UserAgent | Should Match $Pattern
|
$response.Content.Headers."User-Agent" | Should Match $Pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion SkipHeaderVerification tests
|
#endregion SkipHeaderVerification tests
|
||||||
|
|
Loading…
Reference in a new issue