Second check for github repos as private homepages
This commit is contained in:
		
							parent
							
								
									a6aab4b349
								
							
						
					
					
						commit
						d490123d74
					
				@ -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?)
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -290,9 +290,27 @@ module Utils
 | 
			
		||||
          url_protected_by_cloudflare?(response) || url_protected_by_incapsula?(response)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        # 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/(?<user>[^/]+)/(?<repo>[^/]+)/?.*})
 | 
			
		||||
        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? &&
 | 
			
		||||
         (details[:final_url].present? && !details[:final_url].start_with?("https://"))
 | 
			
		||||
        return "The #{url_type} #{url} redirects back to HTTP"
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user