Change Web Cmdlet Tests to Use 127.0.0.1 not Localhost (#6069)

Change Web Cmdlets Tests to Use 127.0.0.1 instead of localhost due to dotnet/corefx#24104
This provides a decent speed boost to the WebCmdlet tests (Faster in dozens of times).
This commit is contained in:
Mark Kraus
2018-02-01 08:26:05 +04:00
committed by Ilya
parent 05ca36463a
commit 7d003f4f67
2 changed files with 8 additions and 7 deletions
@@ -496,15 +496,15 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" {
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10'
$command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"
$command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand"
}
$testCase = @(
@{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' }
@{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' }
)
It "Validate Invoke-WebRequest error with -Proxy option set - '<name>'" -TestCases $testCase {
@@ -1632,15 +1632,15 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" {
$uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10'
$command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2"
$command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2"
$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}
$testCase = @(
@{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' }
@{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' }
)
It "Validate Invoke-RestMethod error with -Proxy option - '<name>'" -TestCases $testCase {
@@ -174,7 +174,8 @@ function Get-WebListenerUrl {
return $null
}
$Uri = [System.UriBuilder]::new()
$Uri.Host = 'localhost'
# Use 127.0.0.1 and not localhost due to https://github.com/dotnet/corefx/issues/24104
$Uri.Host = '127.0.0.1'
$Uri.Port = $runningListener.HttpPort
$Uri.Scheme = 'Http'