Skip to content

Commit

Permalink
Merge pull request #13227 from UiP9AV6Y/bugfix_artifact_domain_manpage
Browse files Browse the repository at this point in the history
docs: clarify application of HOMEBREW_ARTIFACT_DOMAIN
  • Loading branch information
MikeMcQuaid authored May 23, 2022
2 parents 0667aa6 + 6a1d899 commit 7a79da2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ module EnvConfig
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. " \
"This results in e.g. " \
"`https://ghcr.io/v2/homebrew/core/gettext/manifests/0.21` " \
"to instead be 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, " \
Expand Down
56 changes: 56 additions & 0 deletions Library/Homebrew/test/download_strategies/curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
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"])
end

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
Expand Down Expand Up @@ -123,6 +126,59 @@
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
Expand Down

0 comments on commit 7a79da2

Please sign in to comment.