Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify application of HOMEBREW_ARTIFACT_DOMAIN #13227

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. " \
"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, " \
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