From 4737ebae2048c2bad7c819f736ac1682a18851ce Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 8 May 2018 09:15:49 +0500 Subject: [PATCH] Remove web cmdlet tests using proxy env variables (#6808) --- .../WebCmdlets.Tests.ps1 | 120 +----------------- 1 file changed, 4 insertions(+), 116 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index a954656afb..8c19d77aa1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -505,8 +505,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } $testCase = @( - @{ proxy_address = (Get-WebListenerUrl).Authority; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = (Get-WebListenerUrl -https).Authority; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = (Get-WebListenerUrl).Authority; name = 'HTTP proxy'; protocol = 'http' } + @{ proxy_address = (Get-WebListenerUrl -https).Authority; name = 'HTTPS proxy'; protocol = 'https' } ) It "Validate Invoke-WebRequest with -Proxy option set - ''" -TestCases $testCase { @@ -520,37 +520,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $result.Output.Content | Should -BeExactly $expectedResult.Output.Content } - It "Validate Invoke-WebRequest with environment proxy set - ''" -Skip:$IsWindows -TestCases $testCase { - param($proxy_address, $name, $protocol) - - # Configure the environment variable. - New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force > $null - - # use external url, but with proxy the external url should not actually be called - $command = "Invoke-WebRequest -Uri ${protocol}://httpbin.org -SkipCertificateCheck" - $result = ExecuteWebCommand -command $command - $command = "Invoke-WebRequest -Uri '${protocol}://${proxy_address}' -NoProxy" - $expectedResult = ExecuteWebCommand -command $command - $result.Output.Content | Should -BeExactly $expectedResult.Output.Content - } - - It "Validate Invoke-WebRequest returns User-Agent where -NoProxy with envirionment proxy set - ''" -TestCases $testCase { - param($proxy_address, $name, $protocol) - - # Configure the environment variable. - New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force - - $uri = Get-WebListenerUrl -Test 'Get' -Https:$($protocol -eq 'https') - $command = "Invoke-WebRequest -Uri '$uri' -NoProxy -SkipCertificateCheck" - - $result = ExecuteWebCommand -command $command - ValidateResponse -response $result - - # Validate response content - $jsonContent = $result.Output.Content | ConvertFrom-Json - $jsonContent.headers.Host | Should -Be $uri.Authority - } - # Perform the following operation for Invoke-WebRequest # gzip Returns gzip-encoded data. # deflate Returns deflate-encoded data. @@ -1750,32 +1719,6 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { $response.Headers.'Content-Range'[0] | Should -BeExactly "bytes */$referenceFileSize" } } - - BeforeEach { - if ($env:http_proxy) { - $savedHttpProxy = $env:http_proxy - $copiedHttpProxy = $true - } - - if ($env:https_proxy) { - $savedHttpsProxy = $env:https_proxy - $copiedHttpsProxy = $true - } - } - - AfterEach { - if ($copiedHttpProxy) { - $env:http_proxy = $savedHttpProxy - } else { - $env:http_proxy = $null - } - - if ($copiedHttpsProxy) { - $env:https_proxy = $savedHttpsProxy - } else { - $env:https_proxy = $null - } - } } Describe "Invoke-RestMethod tests" -Tags "Feature" { @@ -1879,8 +1822,8 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { } $testCase = @( - @{ proxy_address = (Get-WebListenerUrl).Authority; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = (Get-WebListenerUrl -https).Authority; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = (Get-WebListenerUrl).Authority; name = 'HTTP proxy'; protocol = 'http' } + @{ proxy_address = (Get-WebListenerUrl -https).Authority; name = 'HTTPS proxy'; protocol = 'https' } ) It "Validate Invoke-RestMethod with -Proxy option - ''" -TestCases $testCase { @@ -1894,35 +1837,6 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $result.Output | Should -BeExactly $expectedResult.Output } - It "Validate Invoke-RestMethod with environment proxy set - ''" -Skip:$IsWindows -TestCases $testCase { - param($proxy_address, $name, $protocol) - - # Configure the environment variable. - New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force - - $uri = Get-WebListenerUrl -Test Get - $command = "Invoke-RestMethod -Uri ${protocol}://httpbin.org" - $result = ExecuteWebCommand -command $command - $command = "Invoke-RestMethod -Uri '${protocol}://${proxy_address}' -NoProxy" - $expectedResult = ExecuteWebCommand -command $command - $result.Output | Should -BeExactly $expectedResult.Output - } - - It "Validate Invoke-RestMethod returns User-Agent with option -NoProxy when environment proxy set - ''" -TestCases $testCase { - param($proxy_address, $name, $protocol) - - # Configure the environment variable. - New-Item -Name ${name} -Value ${proxy_address} -ItemType Variable -Path Env: -Force - - $uri = Get-WebListenerUrl -Test 'Get' -Https:$($protocol -eq 'https') - $command = "Invoke-RestMethod -Uri '$uri' -NoProxy -SkipCertificateCheck" - - $result = ExecuteWebCommand -command $command - - # Validate response - $result.Output.headers.'User-Agent' | Should -MatchExactly '(?