From d490123d7425ef7321caed5c7a149beb52848d86 Mon Sep 17 00:00:00 2001 From: Troy McCabe Date: Sun, 18 Sep 2022 23:29:15 -0500 Subject: [PATCH 1/2] Second check for github repos as private homepages --- Library/Homebrew/cask/audit.rb | 2 +- Library/Homebrew/formula_auditor.rb | 2 +- Library/Homebrew/utils/curl.rb | 20 +++++++++++++++++++- Library/Homebrew/utils/shared_audits.rb | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index a8ad81cdfa..840cfff921 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -716,7 +716,7 @@ module Cask return unless cask.homepage - validate_url_for_https_availability(cask.homepage, "homepage URL", cask.token, cask.tap, + validate_url_for_https_availability(cask.homepage, SharedAudits::URL_TYPE_HOMEPAGE, cask.token, cask.tap, user_agents: [:browser, :default], check_content: true, strict: strict?) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index df955690dc..705d18fa78 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -498,7 +498,7 @@ module Homebrew end if (http_content_problem = curl_check_http_content(homepage, - "homepage URL", + SharedAudits::URL_TYPE_HOMEPAGE, user_agents: [:browser, :default], check_content: true, strict: @strict, diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 6d49e01abe..eb413d8689 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -290,7 +290,25 @@ module Utils url_protected_by_cloudflare?(response) || url_protected_by_incapsula?(response) end - return "The #{url_type} #{url} is not reachable (HTTP status code #{details[:status_code]})" + # https://github.com/Homebrew/brew/issues/13789 + # If the `:homepage` of a formula is private, it will fail an `audit` + # since there's no way to specify a `strategy` with `using:` and + # Github does not authorize access to the web ui using token + # + # Strategy: + # If the `:homepage` 404s, it's a github link, and we have a token-- + # check the API for the repository existing (which does use tokens) + repo_details = url.match(%r{https?://github\.com/(?[^/]+)/(?[^/]+)/?.*}) + check_github_api = url_type == SharedAudits::URL_TYPE_HOMEPAGE && + details[:status_code] == "404" && + repo_details && + Homebrew::EnvConfig.github_api_token + + unless check_github_api + return "The #{url_type} #{url} is not reachable (HTTP status code #{details[:status_code]})" + end + + "Unable to find homepage" if SharedAudits.github_repo_data(repo_details[:user], repo_details[:repo]).nil? end if url.start_with?("https://") && Homebrew::EnvConfig.no_insecure_redirect? && diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index 6845336faf..de1ec69c95 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -10,6 +10,8 @@ module SharedAudits include Utils::Curl extend Utils::Curl + URL_TYPE_HOMEPAGE = "homepage URL" + module_function def github_repo_data(user, repo) From 359b3c6d361cb57959ca5cde885ab58d10faad8f Mon Sep 17 00:00:00 2001 From: Troy McCabe Date: Wed, 21 Sep 2022 07:35:42 -0500 Subject: [PATCH 2/2] Addresses PR comments --- Library/Homebrew/utils/curl.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index eb413d8689..bd2634557f 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -293,11 +293,11 @@ module Utils # https://github.com/Homebrew/brew/issues/13789 # If the `:homepage` of a formula is private, it will fail an `audit` # since there's no way to specify a `strategy` with `using:` and - # Github does not authorize access to the web ui using token + # GitHub does not authorize access to the web UI using token # # Strategy: - # If the `:homepage` 404s, it's a github link, and we have a token-- - # check the API for the repository existing (which does use tokens) + # If the `:homepage` 404s, it's a GitHub link, and we have a token then + # check the API (which does use tokens) for the repository repo_details = url.match(%r{https?://github\.com/(?[^/]+)/(?[^/]+)/?.*}) check_github_api = url_type == SharedAudits::URL_TYPE_HOMEPAGE && details[:status_code] == "404" &&