diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index b0c88aa11c..c7957457db 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -89,7 +89,6 @@ public static void SetupConfiguration(IList args, ChocolateyConfiguratio SetGlobalOptions(args, config, container); SetEnvironmentOptions(config); EnvironmentSettings.SetEnvironmentVariables(config); - SetProxyOptions(config, container); // must be done last for overrides SetLicensedOptions(config, license, configFileSettings); // save all changes if there are any @@ -464,53 +463,6 @@ private static void SetGlobalOptions(IList args, ChocolateyConfiguration }); } - private static void SetProxyOptions(ChocolateyConfiguration config, Container container) - { - // Evaluation order of Proxy settings: System Set -> Environment Variable Set -> Chocolatey Configuration File Set -> CLI Passed in Argument - var proxyAlreadySet = !string.IsNullOrWhiteSpace(config.Proxy.Location); - var onWindows = Platform.GetPlatform() == PlatformType.Windows; - - // Only Windows has a registry provider, if it's already set, or we're not on Windows we don't need to continue. - if (proxyAlreadySet || !onWindows) - { - return; - } - - // We don't yet have a Proxy Location, check if the system has one configured in the registry - var registryService = container.GetInstance(); - var internetSettingsRegKey = registryService.GetKey(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); - - if (!internetSettingsRegKey.GetValue("ProxyEnable").ToStringSafe().IsEqualTo("1")) - { - return; - } - - var proxySetting = internetSettingsRegKey.GetValue("ProxyServer").ToStringSafe(); - - if (string.IsNullOrWhiteSpace(proxySetting)) - { - return; - } - - if (proxySetting.IndexOf(';') != -1) - { - var allProxies = proxySetting.Split(';'); - proxySetting = allProxies.FirstOrDefault(s => s.TrimSafe().StartsWith("https=")); - - if (string.IsNullOrWhiteSpace(proxySetting)) - { - proxySetting = allProxies.FirstOrDefault(s => s.TrimSafe().StartsWith("http=")); - } - } - - if (proxySetting?.IndexOf('=') != -1 && !proxySetting.StartsWith("http")) - { - return; - } - - config.Proxy.Location = proxySetting.Split('=').LastOrDefault(); - } - private static void SetEnvironmentOptions(ChocolateyConfiguration config) { config.Information.PlatformType = Platform.GetPlatform(); diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 9e863e3840..05f2f41e07 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -124,7 +124,10 @@ public static IEnumerable GetRemoteRepositories(ChocolateyConf } else { - ProxyCache.Instance.Override(new System.Net.WebProxy()); + // We need to override the proxy so that we don't use the NuGet configuration. + // We must however also be able to use the system proxy. + // Our changes to ProxyCache test for a null overridden proxy and get the system proxy if it's null. + ProxyCache.Instance.Override(proxy: null); } IEnumerable sources = configuration.Sources.ToStringSafe().Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries); diff --git a/tests/chocolatey-tests/chocolatey.Tests.ps1 b/tests/chocolatey-tests/chocolatey.Tests.ps1 index 3e73940b1d..ee1a485d66 100644 --- a/tests/chocolatey-tests/chocolatey.Tests.ps1 +++ b/tests/chocolatey-tests/chocolatey.Tests.ps1 @@ -170,7 +170,9 @@ Describe "Ensuring Chocolatey is correctly installed" -Tag Environment, Chocolat # These tests are not a true test of PowerShell v2 compatibility as -Version 2 does not guarantee that things run exactly as in a PowerShell 2 instance, but it is as close as we can get in a testing environment. # Full proper testing on v2 would require a VM with only v2 installed. # This is skipped when not run in CI because it modifies the local system. - Context "PowerShell v2 compatibility" -Skip:(-not $env:TEST_KITCHEN) { + # These are skipped on Proxy tests because the proxy server we use doesn't allow + # the Windows updates access this needs to install PowerShell 2 support + Context "PowerShell v2 compatibility" -Skip:(-not $env:TEST_KITCHEN) -Tag ProxySkip { BeforeAll { # TODO: This doesn't work on client OSes (might be Install-WindowsOptionalFeature). Make sure this works on both server and client. Install-WindowsFeature powershell-v2 diff --git a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 index 14190788b4..e0664cff38 100644 --- a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 @@ -1806,6 +1806,63 @@ To install a local, or remote file, you may use: } } + # Tagged as Internal since this package is only available internally and downloads from internal infrastructure. + Context 'Installing package with Open Source Get-ChocolateyWebFile, Get-WebFileName and Get-WebHeaders' -Tag Internal, FossOnly { + BeforeAll { + $paths = New-ChocolateyInstallSnapshot + + # Cache directory is set here to prevent assertion failures + $Output = Invoke-Choco install get-chocolateywebfile "--cache-location=$($paths.PackagesPath)" --confirm + } + + AfterAll { + $null = Invoke-Choco uninstall get-chocolateywebfile --confirm + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Runs under background Service' -Tag Background { + $Output.Lines | Should -Contain 'Running in background mode' -Because $Output.String + } + + It 'Outputs name of remote file' { + $Output.Lines | Should -Contain 'FileName: ChocolateyGUI.msi' -Because $Output.String + } + + # We only get an output of System.Collections.Hashtable here, + # but that is enough for us to assert against the call to + # Get-WebHeaders + It 'Outputs information from web headers' { + $Output.Lines | Should -Contain 'System.Collections.Hashtable' -Because $Output.String + } + + It 'Outputs downloading software' { + $Output.Lines | Should -Contain 'Downloading get-chocolateywebfile' -Because $Output.String + } + + It 'Outputs download completed' { + $Output.Lines | Should -Contain "Download of ChocolateyGUI.msi (16.23 MB) completed." -Because $Output.String + } + + It 'Outputs path to msi executable' { + $Output.Lines | Should -Contain "Path: $env:ChocolateyInstall\lib\get-chocolateywebfile\tools\ChocolateyGUI.msi" -Because $Output.String + } + + It 'Outputs installing msi executable' { + $Output.Lines | Should -Contain 'Installing get-chocolateywebfile...' -Because $Output.String + } + + It 'Outputs installation was successful' { + $Output.Lines | Should -Contain 'get-chocolateywebfile has been installed.' -Because $Output.String + } + + It 'Installs software to expected directory' { + "${env:ProgramFiles(x86)}\Chocolatey GUI\ChocolateyGui.exe" | Should -Exist + } + } + # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. # Any tests after this block are expected to generate the configuration as they're explicitly using the NuGet CLI Test-NuGetPaths diff --git a/tests/chocolatey-tests/features/Proxy.Tests.ps1 b/tests/chocolatey-tests/features/Proxy.Tests.ps1 index 08926f0dcd..d69bb7a495 100644 --- a/tests/chocolatey-tests/features/Proxy.Tests.ps1 +++ b/tests/chocolatey-tests/features/Proxy.Tests.ps1 @@ -221,11 +221,6 @@ Describe "Proxy configuration ()" -Tag Proxy, ProxySkip -ForEach $TestCase continue } - $ConfigurationsToTest.System { - $Output.String | Should -MatchExactly "Proxy\.Location='$SystemSet'" - continue - } - default { $Output.String | Should -Not -Match "Proxy\.Location" $Output.String | Should -Not -Match "Proxy\.BypassList" @@ -234,33 +229,3 @@ Describe "Proxy configuration ()" -Tag Proxy, ProxySkip -ForEach $TestCase } } } - -Describe "Multi-Protocol Proxy configuration" -Tag Proxy, ProxySkip -Skip:(-not $env:TEST_KITCHEN) { - BeforeAll { - Initialize-ChocolateyTestInstall - New-ChocolateyInstallSnapshot - $arguments = $null - - $SystemSet = "SystemSetProxy" - Set-ItemProperty -Path 'HKCU:/Software/Microsoft/Windows/CurrentVersion/Internet Settings' -Name ProxyServer -Value "ftp=something;socks=another" - Set-ItemProperty -Path 'HKCU:/Software/Microsoft/Windows/CurrentVersion/Internet Settings' -Name ProxyEnable -Value 1 - } - - AfterAll { - Remove-ChocolateyTestInstall - Remove-ItemProperty -Path 'HKCU:/Software/Microsoft/Windows/CurrentVersion/Internet Settings' -Name ProxyServer -ErrorAction Ignore - Remove-ItemProperty -Path 'HKCU:/Software/Microsoft/Windows/CurrentVersion/Internet Settings' -Name ProxyEnable -ErrorAction Ignore - $env:https_proxy = $null - } - - Context "Configured for command ()" -ForEach $CommandsToTest { - BeforeAll { - $Output = Invoke-Choco $Command @arguments @ExtraArguments --debug --verbose --noop - } - - It "Should output the correct Proxy setting" { - $Output.String | Should -Not -MatchExactly "Proxy\.Location='$SystemSet'" - $Output.String | Should -Not -MatchExactly "Proxy\.Location" - } - } -}