cask/audit: Pass a URL's referer
through to cURL
- Some casks have URL arguments like "referer" (spelled wrong, that's intentional in the HTTP spec). - The audit for one such cask, `iThoughtsX`, was failing because the "referer" wasn't getting passed through to cURL so the access would 404. ---- Before: ``` ❯ brew audit --cask --online --appcast --signing 'ithoughtsx' [...] audit for ithoughtsx: failed - The binary URL https://cdn.toketaware.com?download=iThoughtsX.zip is not reachable (HTTP status code 404) - Version '9.2.0' differs from '9.3.0' retrieved by livecheck. - Version '9.2.0' differs from '9.3.0' retrieved by livecheck. Error: 2 problems in 1 cask detected ``` After: ``` ❯ brew audit --cask --online --appcast --signing 'ithoughtsx' [...] audit for ithoughtsx: failed - Version '9.2.0' differs from '9.3.0' retrieved by livecheck. - Version '9.2.0' differs from '9.3.0' retrieved by livecheck. Error: 1 problem in 1 cask detected ```
This commit is contained in:
parent
0d5e291fe1
commit
0701ea42fa
@ -805,7 +805,7 @@ module Cask
|
|||||||
|
|
||||||
if cask.url && !cask.url.using
|
if cask.url && !cask.url.using
|
||||||
validate_url_for_https_availability(cask.url, "binary URL", cask.token, cask.tap,
|
validate_url_for_https_availability(cask.url, "binary URL", cask.token, cask.tap,
|
||||||
user_agents: [cask.url.user_agent])
|
user_agents: [cask.url.user_agent], referer: cask.url&.referer)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cask.appcast && appcast?
|
if cask.appcast && appcast?
|
||||||
|
@ -371,6 +371,14 @@ describe "Utils::Curl" do
|
|||||||
expect { curl_args(*args, retry_max_time: "test") }.to raise_error(TypeError)
|
expect { curl_args(*args, retry_max_time: "test") }.to raise_error(TypeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "uses `--referer` when :referer is present" do
|
||||||
|
expect(curl_args(*args, referer: "https://brew.sh").join(" ")).to include("--referer https://brew.sh")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't use `--referer` when :referer is nil" do
|
||||||
|
expect(curl_args(*args, referer: nil).join(" ")).not_to include("--referer")
|
||||||
|
end
|
||||||
|
|
||||||
it "uses HOMEBREW_USER_AGENT_FAKE_SAFARI when `:user_agent` is `:browser` or `:fake`" do
|
it "uses HOMEBREW_USER_AGENT_FAKE_SAFARI when `:user_agent` is `:browser` or `:fake`" do
|
||||||
expect(curl_args(*args, user_agent: :browser).join(" "))
|
expect(curl_args(*args, user_agent: :browser).join(" "))
|
||||||
.to include("--user-agent #{HOMEBREW_USER_AGENT_FAKE_SAFARI}")
|
.to include("--user-agent #{HOMEBREW_USER_AGENT_FAKE_SAFARI}")
|
||||||
|
@ -56,6 +56,7 @@ module Utils
|
|||||||
show_output: T.nilable(T::Boolean),
|
show_output: T.nilable(T::Boolean),
|
||||||
show_error: T.nilable(T::Boolean),
|
show_error: T.nilable(T::Boolean),
|
||||||
user_agent: T.any(String, Symbol, NilClass),
|
user_agent: T.any(String, Symbol, NilClass),
|
||||||
|
referer: T.nilable(String),
|
||||||
).returns(T::Array[T.untyped])
|
).returns(T::Array[T.untyped])
|
||||||
}
|
}
|
||||||
def curl_args(
|
def curl_args(
|
||||||
@ -66,7 +67,8 @@ module Utils
|
|||||||
retry_max_time: nil,
|
retry_max_time: nil,
|
||||||
show_output: false,
|
show_output: false,
|
||||||
show_error: true,
|
show_error: true,
|
||||||
user_agent: nil
|
user_agent: nil,
|
||||||
|
referer: nil
|
||||||
)
|
)
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
@ -108,6 +110,8 @@ module Utils
|
|||||||
|
|
||||||
args << "--retry-max-time" << retry_max_time.round if retry_max_time.present?
|
args << "--retry-max-time" << retry_max_time.round if retry_max_time.present?
|
||||||
|
|
||||||
|
args << "--referer" << referer if referer.present?
|
||||||
|
|
||||||
args + extra_args
|
args + extra_args
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -238,7 +242,7 @@ module Utils
|
|||||||
set_cookie_header.compact.any? { |cookie| cookie.match?(/^(visid_incap|incap_ses)_/i) }
|
set_cookie_header.compact.any? { |cookie| cookie.match?(/^(visid_incap|incap_ses)_/i) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default],
|
def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default], referer: nil,
|
||||||
check_content: false, strict: false, use_homebrew_curl: false)
|
check_content: false, strict: false, use_homebrew_curl: false)
|
||||||
return unless url.start_with? "http"
|
return unless url.start_with? "http"
|
||||||
|
|
||||||
@ -254,6 +258,7 @@ module Utils
|
|||||||
hash_needed: true,
|
hash_needed: true,
|
||||||
use_homebrew_curl: use_homebrew_curl,
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
user_agent: user_agent,
|
user_agent: user_agent,
|
||||||
|
referer: referer,
|
||||||
)
|
)
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
next
|
next
|
||||||
@ -276,6 +281,7 @@ module Utils
|
|||||||
hash_needed: hash_needed,
|
hash_needed: hash_needed,
|
||||||
use_homebrew_curl: use_homebrew_curl,
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
user_agent: user_agent,
|
user_agent: user_agent,
|
||||||
|
referer: referer,
|
||||||
)
|
)
|
||||||
break if http_status_ok?(details[:status_code])
|
break if http_status_ok?(details[:status_code])
|
||||||
end
|
end
|
||||||
@ -364,7 +370,7 @@ module Utils
|
|||||||
|
|
||||||
def curl_http_content_headers_and_checksum(
|
def curl_http_content_headers_and_checksum(
|
||||||
url, specs: {}, hash_needed: false,
|
url, specs: {}, hash_needed: false,
|
||||||
use_homebrew_curl: false, user_agent: :default
|
use_homebrew_curl: false, user_agent: :default, referer: nil
|
||||||
)
|
)
|
||||||
file = Tempfile.new.tap(&:close)
|
file = Tempfile.new.tap(&:close)
|
||||||
|
|
||||||
@ -385,7 +391,8 @@ module Utils
|
|||||||
connect_timeout: 15,
|
connect_timeout: 15,
|
||||||
max_time: max_time,
|
max_time: max_time,
|
||||||
retry_max_time: max_time,
|
retry_max_time: max_time,
|
||||||
user_agent: user_agent
|
user_agent: user_agent,
|
||||||
|
referer: referer
|
||||||
)
|
)
|
||||||
|
|
||||||
parsed_output = parse_curl_output(output)
|
parsed_output = parse_curl_output(output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user