diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 08728a43ae..b44c9b0645 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -23,7 +23,12 @@ module Homebrew description: "Prefix all download URLs, including those for bottles, with this value. " \ "For example, `HOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080` will cause a " \ "formula with the URL `https://example.com/foo.tar.gz` to instead download from " \ - "`http://localhost:8080/example.com/foo.tar.gz`.", + "`http://localhost:8080/https://example.com/foo.tar.gz`. " \ + "Bottle URLs however, have their domain replaced with this prefix. " \ + "Using the same value for example, would cause data hosted under " \ + "`https://ghcr.io/v2/homebrew/core/gettext/manifests/0.21` " \ + "to be instead downloaded from " \ + "`http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`", }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ diff --git a/Library/Homebrew/test/download_strategies/curl_spec.rb b/Library/Homebrew/test/download_strategies/curl_spec.rb index 31fd493d2e..f25d03d0bc 100644 --- a/Library/Homebrew/test/download_strategies/curl_spec.rb +++ b/Library/Homebrew/test/download_strategies/curl_spec.rb @@ -10,6 +10,7 @@ describe CurlDownloadStrategy do let(:url) { "https://example.com/foo.tar.gz" } let(:version) { "1.2.3" } let(:specs) { { user: "download:123456" } } + let(:artifact_domain) { nil } it "parses the opts and sets the corresponding args" do expect(strategy.send(:_curl_args)).to eq(["--user", "download:123456"]) @@ -17,6 +18,8 @@ describe CurlDownloadStrategy do describe "#fetch" do before do + allow(Homebrew::EnvConfig).to receive(:artifact_domain).and_return(artifact_domain) + strategy.temporary_path.dirname.mkpath FileUtils.touch strategy.temporary_path end @@ -123,6 +126,59 @@ describe CurlDownloadStrategy do strategy.fetch end end + + context "with artifact_domain set" do + let(:artifact_domain) { "https://mirror.example.com/oci" } + + context "with an asset hosted under example.com" do + let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } + + it "prefixes the URL unchanged" do + expect(strategy).to receive(:system_command).with( + /curl/, + hash_including(args: array_including_cons("#{artifact_domain}/#{url}")), + ) + .at_least(:once) + .and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: [])) + + strategy.fetch + end + end + + context "with an asset hosted under #{GitHubPackages::URL_DOMAIN} (HTTP)" do + let(:resource_path) { "v2/homebrew/core/spec/manifests/0.0" } + let(:url) { "http://#{GitHubPackages::URL_DOMAIN}/#{resource_path}" } + let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } + + it "rewrites the URL correctly" do + expect(strategy).to receive(:system_command).with( + /curl/, + hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), + ) + .at_least(:once) + .and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: [])) + + strategy.fetch + end + end + + context "with an asset hosted under #{GitHubPackages::URL_DOMAIN} (HTTPS)" do + let(:resource_path) { "v2/homebrew/core/spec/manifests/0.0" } + let(:url) { "https://#{GitHubPackages::URL_DOMAIN}/#{resource_path}" } + let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } + + it "rewrites the URL correctly" do + expect(strategy).to receive(:system_command).with( + /curl/, + hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), + ) + .at_least(:once) + .and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: [])) + + strategy.fetch + end + end + end end describe "#cached_location" do