Class: Cask::Audit Private
- Includes:
- SystemCommand::Mixin, Utils::Curl, Utils::Output::Mixin
- Defined in:
- cask/audit.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Audit a cask for various problems.
Constant Summary collapse
- Error =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias do { message: T.nilable(String), location: T.nilable(Homebrew::SourceLocation), corrected: T::Boolean, } end
Instance Attribute Summary collapse
- #cask ⇒ Cask readonly private
- #download ⇒ Download? readonly private
- #livecheck_result ⇒ void writeonly private
Instance Method Summary collapse
- #add_error(message, location: nil, strict_only: false) ⇒ void private
- #audit_artifact_case ⇒ void private
- #audit_bitbucket_repository ⇒ void private
- #audit_cask_path ⇒ void private
- #audit_conflicts_with ⇒ void private
- #audit_denylist ⇒ void private
- #audit_deprecate_disable ⇒ void private
- #audit_description ⇒ void private
- #audit_download ⇒ void private
- #audit_download_url_format ⇒ void private
- #audit_download_url_is_osdn ⇒ void private
- #audit_forgejo_prerelease_version ⇒ void private
- #audit_forgejo_repository ⇒ void private
- #audit_forgejo_repository_archived ⇒ void private
- #audit_generic_artifacts ⇒ void private
- #audit_github_prerelease_version ⇒ void private
- #audit_github_repository ⇒ void private
- #audit_github_repository_archived ⇒ void private
- #audit_gitlab_prerelease_version ⇒ void private
- #audit_gitlab_repository ⇒ void private
- #audit_gitlab_repository_archived ⇒ void private
- #audit_homepage_https_availability ⇒ void private
- #audit_hosting_with_livecheck ⇒ void private
- #audit_languages ⇒ void private
- #audit_latest_with_auto_updates ⇒ void private
- #audit_latest_with_livecheck ⇒ void private
- #audit_livecheck_https_availability ⇒ void private
- #audit_livecheck_unneeded_long_version ⇒ void private
- #audit_livecheck_version ⇒ Boolean, ... private
- #audit_min_os ⇒ void private
- #audit_no_string_version_latest ⇒ void private
- #audit_required_stanzas ⇒ void private
- #audit_reverse_migration ⇒ void private
- #audit_rosetta ⇒ void private
- #audit_sha256_actually_256 ⇒ void private
- #audit_sha256_invalid ⇒ void private
- #audit_sha256_no_check_if_latest ⇒ void private
- #audit_sha256_no_check_if_unversioned ⇒ void private
- #audit_signing ⇒ void private
- #audit_single_pre_postflight ⇒ void private
- #audit_single_uninstall_zap ⇒ void private
- #audit_stanza_requires_uninstall ⇒ void private
- #audit_token ⇒ void private
- #audit_token_bad_words ⇒ void private
- #audit_token_conflicts ⇒ void private
- #audit_unnecessary_verified ⇒ void private
- #audit_untrusted_pkg ⇒ void private
- #audit_url_https_availability ⇒ void private
- #audit_version_special_characters ⇒ void private
- #errors ⇒ Array<Error> private
- #errors? ⇒ Boolean private
- #extract_artifacts(include_manual_installers: false, &_block) {|artifacts, @tmpdir| ... } ⇒ void private
- #initialize(cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, only: [], except: []) ⇒ void constructor private
- #new_cask? ⇒ Boolean private
- #normalize_min_os(min_os) ⇒ MacOSVersion? private
- #online? ⇒ Boolean private
- #result ⇒ String? private
- #run! ⇒ ::Cask::Audit private
- #signing? ⇒ Boolean private
- #strict? ⇒ Boolean private
- #success? ⇒ Boolean private
- #summary ⇒ String? private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from Utils::Curl
clear_path_cache, curl, curl_args, curl_check_http_content, curl_download, curl_executable, curl_headers, curl_http_content_headers_and_checksum, curl_output, curl_path, curl_response_follow_redirections, curl_response_last_location, curl_supports_fail_with_body?, curl_supports_tls13?, curl_version, curl_with_workarounds, http_status_ok?, https_redirect_curl_args, insecure_redirect?, no_insecure_redirect_curl_args, parse_curl_output, parse_curl_response, strip_progress_bar, url_protected_by_cloudflare?, url_protected_by_incapsula?
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Constructor Details
#initialize(cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, only: [], except: []) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'cask/audit.rb', line 49 def initialize( cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, only: [], except: [] ) # `new_cask` implies `online`, `strict` and `signing` online = new_cask if online.nil? strict = new_cask if strict.nil? signing = new_cask if signing.nil? # `online` and `signing` imply `download` download ||= online || signing @cask = cask @download = T.let(nil, T.nilable(Download)) @download = Download.new(cask) if download @online = online @strict = strict @signing = signing @new_cask = new_cask @only = only @except = except @livecheck_result = T.let(nil, T.nilable(T.any(T::Boolean, Symbol))) end |
Instance Attribute Details
#cask ⇒ Cask (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
34 35 36 |
# File 'cask/audit.rb', line 34 def cask @cask end |
#download ⇒ Download? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
37 38 39 |
# File 'cask/audit.rb', line 37 def download @download end |
#livecheck_result=(value) ⇒ void (writeonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
40 41 42 |
# File 'cask/audit.rb', line 40 def livecheck_result=(value) @livecheck_result = value end |
Instance Method Details
#add_error(message, location: nil, strict_only: false) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
129 130 131 132 133 134 |
# File 'cask/audit.rb', line 129 def add_error(, location: nil, strict_only: false) # Only raise non-critical audits if the user specified `--strict`. return if strict_only && !@strict errors << { message:, location:, corrected: false } end |
#audit_artifact_case ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'cask/audit.rb', line 706 def audit_artifact_case return if (url = cask.url).nil? return unless online? odebug "Auditing artifact case" extract_artifacts(include_manual_installers: true) do |artifacts, tmpdir| artifacts.each do |artifact| source = case artifact when Artifact::Pkg, Artifact::Installer artifact.path else artifact.source end source = if source.to_s.start_with?("#{cask.appdir}/") Pathname(source.to_s.delete_prefix("#{cask.appdir}/")) elsif source.absolute? source.relative_path_from(cask.staged_path) else source end components = source.each_filename.to_a current = tmpdir on_disk = [] components.each do |component| break unless current.directory? children = current.children.map { |child| child.basename.to_s } match = children.find { |name| name == component } || children.find { |name| name.casecmp?(component) } break if match.nil? on_disk << match current /= match end next if on_disk.length != components.length next if on_disk == components add_error "Artifact #{source} does not match the case of the extracted " \ "#{File.join(on_disk)}; this fails on case-sensitive filesystems.", location: url.location end end end |
#audit_bitbucket_repository ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'cask/audit.rb', line 1051 def audit_bitbucket_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://bitbucket\.org/([^/]+)/([^/]+)/?.*}) return if user.nil? || repo.nil? odebug "Auditing Bitbucket repo" self_submission = self_submission?(user) error = SharedAudits.bitbucket(user, repo, self_submission:) add_error error, location: url.location if error end |
#audit_cask_path ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'cask/audit.rb', line 1169 def audit_cask_path return unless (tap = cask.tap)&.core_cask_tap? expected_path = tap.new_cask_path(cask.token) return if cask.sourcefile_path.to_s.end_with?(expected_path.to_s) add_error "Cask should be located in '#{expected_path}'" end |
#audit_conflicts_with ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
# File 'cask/audit.rb', line 1081 def audit_conflicts_with return if !cask.tap&.official? || cask.conflicts_with.nil? Homebrew.with_no_api_env do nonexisting_conflicting_casks = cask.conflicts_with.fetch(:cask, Set.new) - core_cask_tokens nonexisting_conflicting_casks.each do |c| add_error("cask conflicts with non-existing cask `#{c}`") end end end |
#audit_denylist ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1093 1094 1095 1096 1097 1098 |
# File 'cask/audit.rb', line 1093 def audit_denylist return unless cask.tap&.official? return unless (reason = Denylist.reason(cask.token)) add_error "#{cask.token} is not allowed: #{reason}" end |
#audit_deprecate_disable ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1180 1181 1182 1183 |
# File 'cask/audit.rb', line 1180 def audit_deprecate_disable error = SharedAudits.check_deprecate_disable_reason(cask) add_error error if error end |
#audit_description ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
363 364 365 366 367 368 369 |
# File 'cask/audit.rb', line 363 def audit_description # Fonts seldom benefit from descriptions and requiring them disproportionately # increases the maintenance burden. return if cask.tap == "homebrew/cask" && cask.token.include?("font-") add_error("Cask should have a description. Please add a `desc` stanza.", strict_only: true) if cask.desc.blank? end |
#audit_download ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
575 576 577 578 579 580 581 582 583 |
# File 'cask/audit.rb', line 575 def audit_download return if (download = self.download).blank? || (url = cask.url).nil? begin download.fetch rescue => e add_error "download not possible: #{e}", location: url.location end end |
#audit_download_url_format ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
483 484 485 486 487 488 489 490 491 |
# File 'cask/audit.rb', line 483 def audit_download_url_format return if (url = cask.url).nil? odebug "Auditing URL format" return unless bad_sourceforge_url? add_error "SourceForge URL format incorrect. See #{Formatter.url(SOURCEFORGE_OSDN_REFERENCE_URL)}", location: url.location end |
#audit_download_url_is_osdn ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
494 495 496 497 498 499 |
# File 'cask/audit.rb', line 494 def audit_download_url_is_osdn return if (url = cask.url).nil? return unless bad_osdn_url? add_error "OSDN download urls are disabled.", location: url.location, strict_only: true end |
#audit_forgejo_prerelease_version ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
958 959 960 961 962 963 964 965 966 967 968 969 |
# File 'cask/audit.rb', line 958 def audit_forgejo_prerelease_version return if (url = cask.url).nil? odebug "Auditing Forgejo prerelease" user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? tag = SharedAudits.forgejo_tag_from_url(url.to_s) tag ||= cask.version error = SharedAudits.forgejo_release(user, repo, tag, cask:) add_error error, location: url.location if error end |
#audit_forgejo_repository ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
# File 'cask/audit.rb', line 1066 def audit_forgejo_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*}) return if user.nil? || repo.nil? odebug "Auditing Forgejo repo" self_submission = self_submission?(user) error = SharedAudits.forgejo(user, repo, self_submission:) add_error error, location: url.location if error end |
#audit_forgejo_repository_archived ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'cask/audit.rb', line 1004 def audit_forgejo_repository_archived return if cask.deprecated? || cask.disabled? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? = SharedAudits.forgejo_repo_data(user, repo) return if .nil? return unless ["archived"] add_error "Forgejo repository is archived since #{["archived_at"]}", location: url.location end |
#audit_generic_artifacts ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
511 512 513 514 515 516 517 |
# File 'cask/audit.rb', line 511 def audit_generic_artifacts cask.artifacts.grep(Artifact::Artifact).each do |artifact| unless artifact.target.absolute? add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}" end end end |
#audit_github_prerelease_version ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'cask/audit.rb', line 929 def audit_github_prerelease_version return if (url = cask.url).nil? odebug "Auditing GitHub prerelease" user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? tag = SharedAudits.github_tag_from_url(url.to_s) tag ||= cask.version error = SharedAudits.github_release(user, repo, tag, cask:) add_error error, location: url.location if error end |
#audit_github_repository ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'cask/audit.rb', line 1021 def audit_github_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) return if user.nil? || repo.nil? odebug "Auditing GitHub repo" self_submission = self_submission?(user) error = SharedAudits.github(user, repo, self_submission:) add_error error, location: url.location if error end |
#audit_github_repository_archived ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
972 973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'cask/audit.rb', line 972 def audit_github_repository_archived # Deprecated/disabled casks may have an archived repository. return if cask.deprecated? || cask.disabled? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? = SharedAudits.github_repo_data(user, repo) return if .nil? add_error "GitHub repo is archived", location: url.location if ["archived"] end |
#audit_gitlab_prerelease_version ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
943 944 945 946 947 948 949 950 951 952 953 954 955 |
# File 'cask/audit.rb', line 943 def audit_gitlab_prerelease_version return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? odebug "Auditing GitLab prerelease" tag = SharedAudits.gitlab_tag_from_url(url.to_s) tag ||= cask.version error = SharedAudits.gitlab_release(user, repo, tag, cask:) add_error error, location: url.location if error end |
#audit_gitlab_repository ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
# File 'cask/audit.rb', line 1036 def audit_gitlab_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) return if user.nil? || repo.nil? odebug "Auditing GitLab repo" self_submission = self_submission?(user) error = SharedAudits.gitlab(user, repo, self_submission:) add_error error, location: url.location if error end |
#audit_gitlab_repository_archived ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 |
# File 'cask/audit.rb', line 987 def audit_gitlab_repository_archived # Deprecated/disabled casks may have an archived repository. return if cask.deprecated? || cask.disabled? return if (url = cask.url).nil? user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online? return if user.nil? || repo.nil? odebug "Auditing GitLab repo archived" = SharedAudits.gitlab_repo_data(user, repo) return if .nil? add_error "GitLab repo is archived", location: url.location if ["archived"] end |
#audit_homepage_https_availability ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'cask/audit.rb', line 1110 def audit_homepage_https_availability return unless online? return unless (homepage = cask.homepage) return if SharedAudits.homepage_browsed_recently?(cask.homepage_browsed) user_agents = if cask.tap&.audit_exception(:simple_user_agent_for_homepage, cask.token) ["curl"] else [:browser, :default] end validate_url_for_https_availability( homepage, SharedAudits::URL_TYPE_HOMEPAGE, user_agents:, check_content: true, strict: strict? ) end |
#audit_hosting_with_livecheck ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'cask/audit.rb', line 458 def audit_hosting_with_livecheck return if cask.deprecated? || cask.disabled? return if cask.version&.latest? return if (url = cask.url).nil? return if cask.livecheck_defined? return if audit_livecheck_version == :auto_detected add_livecheck = "please add a livecheck. See #{Formatter.url(LIVECHECK_REFERENCE_URL)}" case url.to_s when %r{sourceforge.net/(\S+)} return unless online? add_error "Download is hosted on SourceForge, #{add_livecheck}", location: url.location when %r{dl.devmate.com/(\S+)} add_error "Download is hosted on DevMate, #{add_livecheck}", location: url.location when %r{rink.hockeyapp.net/(\S+)} add_error "Download is hosted on HockeyApp, #{add_livecheck}", location: url.location end end |
#audit_languages ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
520 521 522 523 524 525 526 |
# File 'cask/audit.rb', line 520 def audit_languages @cask.languages.each do |language| Locale.parse(language) rescue Locale::ParserError add_error "Locale '#{language}' is invalid." end end |
#audit_latest_with_auto_updates ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
447 448 449 450 451 452 |
# File 'cask/audit.rb', line 447 def audit_latest_with_auto_updates return unless cask.version&.latest? return unless cask.auto_updates add_error "Casks with `version :latest` should not use `auto_updates`." end |
#audit_latest_with_livecheck ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
438 439 440 441 442 443 444 |
# File 'cask/audit.rb', line 438 def audit_latest_with_livecheck return unless cask.version&.latest? return unless cask.livecheck_defined? return if cask.livecheck.skip? add_error "Casks with a `livecheck` should not use `version :latest`." end |
#audit_livecheck_https_availability ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
# File 'cask/audit.rb', line 1144 def audit_livecheck_https_availability return unless online? return unless cask.livecheck_defined? return unless (url = cask.livecheck.url) return if url.is_a?(Symbol) = cask.livecheck. return if .post_form || .post_json # Validating HTTPS availability is unnecessary if the check uses HTTPS # and does not fail. if url.start_with?("https:") && audit_livecheck_version != false odebug "Skipping livecheck_https_availability audit (working HTTPS livecheck)" return end odebug "Auditing livecheck HTTPS availability" validate_url_for_https_availability( url, "livecheck URL", check_content: true, user_agents: [:default, :browser] ) end |
#audit_livecheck_unneeded_long_version ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
586 587 588 589 590 591 592 593 594 595 596 |
# File 'cask/audit.rb', line 586 def audit_livecheck_unneeded_long_version return if cask.version.nil? || (url = cask.url).nil? return if cask.livecheck.strategy != :sparkle return unless cask.version.csv.second return if cask.url.to_s.include? cask.version.csv.second return if cask.version.csv.third.present? && cask.url.to_s.include?(cask.version.csv.third) add_error "Download does not require additional version components. Use `&:short_version` in the livecheck", location: url.location, strict_only: true end |
#audit_livecheck_version ⇒ Boolean, ...
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
# File 'cask/audit.rb', line 830 def audit_livecheck_version return @livecheck_result unless @livecheck_result.nil? return unless online? return unless cask.version odebug "Auditing livecheck version" referenced_cask, = Homebrew::Livecheck.resolve_livecheck_reference(cask) # Respect skip conditions for a referenced cask if referenced_cask skip_info = Homebrew::Livecheck::SkipConditions.referenced_skip_information( referenced_cask, Homebrew::Livecheck.package_or_resource_name(cask), ) end # Respect cask skip conditions (e.g. deprecated, disabled, latest, unversioned) skip_info ||= Homebrew::Livecheck::SkipConditions.skip_information(cask) if skip_info.present? @livecheck_result = :skip return @livecheck_result end result = Homebrew::Livecheck.latest_version( cask, referenced_formula_or_cask: referenced_cask, ) if result throttle = cask.livecheck.throttle throttle_days = cask.livecheck.throttle_days if referenced_cask throttle ||= referenced_cask.livecheck.throttle throttle_days ||= referenced_cask.livecheck.throttle_days end latest_version = (throttle || throttle_days) ? result[:latest_throttled] : result[:latest] end if latest_version && (cask.version.to_s == latest_version.to_s) @livecheck_result = :auto_detected return @livecheck_result end add_error "Version '#{cask.version}' differs from '#{latest_version}' retrieved by livecheck." @livecheck_result = false end |
#audit_min_os ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'cask/audit.rb', line 880 def audit_min_os return unless online? odebug "Auditing minimum macOS version" bundle_min_os = cask_bundle_min_os sparkle_min_os = cask_sparkle_min_os app_min_os = [bundle_min_os, sparkle_min_os].compact.max = [] << "from artifact: #{bundle_min_os.to_sym}" if bundle_min_os << "from upstream: #{sparkle_min_os.to_sym}" if sparkle_min_os odebug "Detected minimum macOS: #{app_min_os.to_sym} (#{.join(" | ")})" if app_min_os return if app_min_os.nil? || app_min_os <= HOMEBREW_MACOS_OLDEST_ALLOWED on_system_block_min_os = cask.on_system_block_min_os depends_on_min_os = cask.depends_on.macos&.minimum_version cask_min_os = [on_system_block_min_os, depends_on_min_os].compact.max = [] << "from on_system block: #{on_system_block_min_os.to_sym}" if on_system_block_min_os if depends_on_min_os && depends_on_min_os > HOMEBREW_MACOS_OLDEST_ALLOWED << "from depends_on stanza: #{depends_on_min_os.to_sym}" end odebug "Declared minimum macOS: #{cask_min_os&.to_sym} (#{.join(" | ").presence || "default"})" return if cask_min_os&.to_sym == app_min_os.to_sym # ignore declared minimum OS < 11.x when auditing as ARM a cask with arch-specific artifacts return if OnSystem.arch_condition_met?(:arm) && cask.on_system_blocks_exist? && cask_min_os.present? && app_min_os < MacOSVersion.new("11") && app_min_os < cask_min_os min_os_definition = if cask_min_os && cask_min_os > HOMEBREW_MACOS_OLDEST_ALLOWED definition = if T.must(on_system_block_min_os.to_s <=> depends_on_min_os.to_s).positive? "an on_system block" else "a depends_on stanza" end "#{definition} with a minimum macOS version of #{cask_min_os.to_sym.inspect}" else "no minimum macOS version" end source = T.must(bundle_min_os.to_s <=> sparkle_min_os.to_s).positive? ? "Artifact" : "Upstream" add_error "#{source} defined #{app_min_os.to_sym.inspect} as the minimum macOS version " \ "but the cask declared #{min_os_definition}" end |
#audit_no_string_version_latest ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
384 385 386 387 388 389 390 391 |
# File 'cask/audit.rb', line 384 def audit_no_string_version_latest return unless cask.version odebug "Auditing version :latest does not appear as a string ('latest')" return if cask.version.raw_version != "latest" add_error "you should use version :latest instead of version 'latest'" end |
#audit_required_stanzas ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'cask/audit.rb', line 341 def audit_required_stanzas odebug "Auditing required stanzas" [:version, :sha256, :url, :homepage].each do |sym| add_error "a #{sym} stanza is required" unless cask.public_send(sym) end add_error "at least one name stanza is required" if cask.name.empty? installable_artifact = if cask.on_system_blocks_exist? begin OnSystem::VALID_OS_ARCH_TAGS.any? do |tag| cask.refresh_for_tag(tag) { cask.installable_artifact? } end ensure cask.refresh end else cask.installable_artifact? end add_error "at least one installable artifact stanza is required" unless installable_artifact end |
#audit_reverse_migration ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1101 1102 1103 1104 1105 1106 1107 |
# File 'cask/audit.rb', line 1101 def audit_reverse_migration return unless new_cask? return unless cask.tap&.official? return unless cask.tap&.tap_migrations&.key?(cask.token) add_error "#{cask.token} is listed in tap_migrations.json" end |
#audit_rosetta ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
# File 'cask/audit.rb', line 755 def audit_rosetta return if (url = cask.url).nil? return unless online? # Rosetta 2 is only for ARM-capable macOS versions, which are Big Sur (11.x) and later return if Homebrew::SimulateSystem.current_arch != :arm return if MacOSVersion::SYMBOLS.fetch(Homebrew::SimulateSystem.current_os, "10") < "11" return if cask.depends_on.macos&.maximum_version.to_s < "11" odebug "Auditing Rosetta 2 requirement" extract_artifacts do |artifacts, tmpdir| is_container = artifacts.any? { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Pkg) } mentions_rosetta = cask.caveats_object.invoked?(:requires_rosetta) || cask.caveats.include?("requires Rosetta 2") requires_intel = cask.depends_on.arch&.any? { |arch| arch[:type] == :intel } artifacts_to_test = artifacts.filter do |artifact| next false if !artifact.is_a?(Artifact::App) && !artifact.is_a?(Artifact::Binary) next false if artifact.is_a?(Artifact::Binary) && is_container true end next if artifacts_to_test.blank? any_requires_rosetta = artifacts_to_test.any? do |artifact| artifact = T.cast(artifact, T.any(Artifact::App, Artifact::Binary)) path = tmpdir/artifact.source.relative_path_from(cask.staged_path) result = case artifact when Artifact::App files = Dir[path/"Contents/MacOS/*"].select do |f| File.executable?(f) && !File.directory?(f) && !f.end_with?(".dylib") end add_error "No binaries in App: #{artifact.source}", location: url.location if files.empty? main_binary = get_plist_main_binary(path) main_binary ||= files.fetch(0) system_command("lipo", args: ["-archs", main_binary], print_stderr: false) when Artifact::Binary binary_path = path.to_s.gsub(cask.appdir, tmpdir.to_s) system_command("lipo", args: ["-archs", binary_path], print_stderr: true) else T.absurd(artifact) end # binary stanza can contain shell scripts, so we just continue if lipo fails. next false unless result.success? odebug "Architectures: #{result.merged_output}" unless /arm64|x86_64/.match?(result.merged_output) add_error "Artifacts architecture is no longer supported by macOS!", location: url.location next end result.merged_output.exclude?("arm64") && result.merged_output.include?("x86_64") end if any_requires_rosetta if !mentions_rosetta && !requires_intel add_error "At least one artifact requires Rosetta 2 but this is not indicated by the caveats!", location: url.location end elsif mentions_rosetta add_error "No artifacts require Rosetta 2 but the caveats say otherwise!", location: url.location end end end |
#audit_sha256_actually_256 ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
416 417 418 419 420 421 422 423 424 |
# File 'cask/audit.rb', line 416 def audit_sha256_actually_256 return unless cask.sha256 odebug "Auditing sha256 string is a legal SHA-256 digest" return unless cask.sha256.is_a?(Checksum) return if cask.sha256.to_s.match?(/\A[0-9a-f]{64}\z/i) add_error "sha256 string must be of 64 hexadecimal characters" end |
#audit_sha256_invalid ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
427 428 429 430 431 432 433 434 435 |
# File 'cask/audit.rb', line 427 def audit_sha256_invalid return unless cask.sha256 odebug "Auditing sha256 is not a known invalid value" empty_sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" return if cask.sha256 != empty_sha256 add_error "cannot use the sha256 for an empty string: #{empty_sha256}" end |
#audit_sha256_no_check_if_latest ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
394 395 396 397 398 399 400 401 402 403 |
# File 'cask/audit.rb', line 394 def audit_sha256_no_check_if_latest return unless cask.sha256 return unless cask.version odebug "Auditing sha256 :no_check with version :latest" return unless cask.version.latest? return if cask.sha256 == :no_check add_error "you should use sha256 :no_check when version is :latest" end |
#audit_sha256_no_check_if_unversioned ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
406 407 408 409 410 411 412 413 |
# File 'cask/audit.rb', line 406 def audit_sha256_no_check_if_unversioned return unless cask.sha256 return if cask.sha256 == :no_check return unless cask.url&.unversioned? add_error "Use `sha256 :no_check` when URL is unversioned." end |
#audit_signing ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'cask/audit.rb', line 599 def audit_signing return if download.blank? url = cask.url return if url.nil? return if !cask.tap&.official? && !signing? return if cask.deprecated? && cask.deprecation_reason != :fails_gatekeeper_check unless Quarantine.available? odebug "Quarantine support is not available, skipping signing audit" return end odebug "Auditing signing" is_in_skiplist = cask.tap&.audit_exception(:signing_audit_skiplist, cask.token, Homebrew::SimulateSystem.current_arch.to_s) || cask.tap&.audit_exception(:signing_audit_skiplist, cask.token, "all") extract_artifacts(include_manual_installers: true) do |artifacts, tmpdir| is_container = artifacts.any? do |artifact| artifact.is_a?(Artifact::App) || artifact.is_a?(Artifact::Pkg) || (artifact.is_a?(Artifact::Installer) && [".app", ".pkg"].include?(artifact.path.extname.downcase)) end any_signing_failure = artifacts.any? do |artifact| next false if artifact.is_a?(Artifact::Binary) && is_container == true artifact_path = case artifact when Artifact::Pkg, Artifact::Installer artifact.path else artifact.source end artifact_path = artifact_path.relative_path_from(cask.staged_path) if artifact_path.absolute? path = tmpdir/artifact_path unless Quarantine.detect(path) odebug "#{path} does not have quarantine attributes, skipping signing audit" next false end result = case artifact when Artifact::Pkg system_command("spctl", args: ["--assess", "--type", "install", path], print_stderr: false) when Artifact::App next opoo "gktool not found, skipping app signing audit" unless which("gktool") system_command("gktool", args: ["scan", path], print_stderr: false) when Artifact::Installer if artifact.path.extname.downcase == ".app" next opoo "gktool not found, skipping app signing audit" unless which("gktool") system_command("gktool", args: ["scan", path], print_stderr: false) elsif artifact.path.extname.downcase == ".pkg" system_command("spctl", args: ["--assess", "--type", "install", path], print_stderr: false) else next false end when Artifact::Binary # Shell scripts cannot be signed, so we skip them next false if path.text_executable? system_command("codesign", args: ["--verify", "-R=notarized", "--check-notarization", path], print_stderr: false) else add_error "Unknown artifact type: #{artifact.class}", location: url.location next end next false if result.success? next true if cask.deprecated? && cask.deprecation_reason == :fails_gatekeeper_check next true if is_in_skiplist = <<~EOS Signature verification failed: #{result.merged_output} EOS if cask.tap&.official? += <<~EOS The homebrew/cask tap requires all casks to be signed and notarized by Apple. Please contact the upstream developer and ask them to sign and notarize their software. EOS end add_error true end return if any_signing_failure add_error "Cask is in the signing audit skiplist, but does not need to be skipped!" if is_in_skiplist return unless cask.deprecated? return if cask.deprecation_reason != :fails_gatekeeper_check add_error <<~EOS Cask is deprecated because it failed Gatekeeper checks but all artifacts now pass! Remove the deprecate/disable stanza or update the deprecate/disable reason. EOS end end |
#audit_single_pre_postflight ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'cask/audit.rb', line 301 def audit_single_pre_postflight odebug "Auditing preflight and postflight stanzas" if cask.artifacts.count { |k| k.is_a?(Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1 add_error "only a single preflight stanza is allowed" end count = cask.artifacts.count do |k| k.is_a?(Artifact::PostflightBlock) && k.directives.key?(:postflight) end return if count <= 1 add_error "only a single postflight stanza is allowed" end |
#audit_single_uninstall_zap ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'cask/audit.rb', line 318 def audit_single_uninstall_zap odebug "Auditing single uninstall_* and zap stanzas" count = cask.artifacts.count do |k| k.is_a?(Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) end add_error "only a single uninstall_preflight stanza is allowed" if count > 1 count = cask.artifacts.count do |k| k.is_a?(Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) end add_error "only a single uninstall_postflight stanza is allowed" if count > 1 return if cask.artifacts.count { |k| k.is_a?(Artifact::Zap) } <= 1 add_error "only a single zap stanza is allowed" end |
#audit_stanza_requires_uninstall ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
291 292 293 294 295 296 297 298 |
# File 'cask/audit.rb', line 291 def audit_stanza_requires_uninstall odebug "Auditing stanzas which require an uninstall" return if cask.artifacts.none? { |k| k.is_a?(Artifact::Pkg) || k.is_a?(Artifact::Installer) } return if cask.artifacts.any?(Artifact::Uninstall) add_error "installer and pkg stanzas require an uninstall stanza" end |
#audit_token ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
529 530 531 532 533 534 535 |
# File 'cask/audit.rb', line 529 def audit_token token_auditor = Homebrew::FormulaNameCaskTokenAuditor.new(cask.token) return if (errors = token_auditor.errors).none? add_error "Cask token '#{cask.token}' must not contain #{errors.to_sentence(two_words_connector: " or ", last_word_connector: " or ")}." end |
#audit_token_bad_words ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'cask/audit.rb', line 547 def audit_token_bad_words return unless new_cask? token = cask.token add_error "cask token contains .app" if token.end_with? ".app" match_data = /-(?<designation>alpha|beta|rc|release-candidate)$/.match(cask.token) if match_data && cask.tap&.official? add_error "cask token contains version designation '#{match_data[:designation]}'" end add_error("cask token mentions launcher", strict_only: true) if token.end_with? "launcher" add_error("cask token mentions desktop", strict_only: true) if token.end_with? "desktop" add_error("cask token mentions platform", strict_only: true) if token.end_with? "mac", "osx", "macos" add_error("cask token mentions architecture", strict_only: true) if token.end_with? "x86", "32_bit", "x86_64", "64_bit" frameworks = %w[cocoa qt gtk wx java] return if frameworks.include?(token) || !token.end_with?(*frameworks) add_error("cask token mentions framework", strict_only: true) end |
#audit_token_conflicts ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
538 539 540 541 542 543 544 |
# File 'cask/audit.rb', line 538 def audit_token_conflicts Homebrew.with_no_api_env do return unless core_formula_names.include?(cask.token) add_error("cask token conflicts with an existing homebrew/core formula: #{Formatter.url(core_formula_url)}") end end |
#audit_unnecessary_verified ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
502 503 504 505 506 507 508 |
# File 'cask/audit.rb', line 502 def audit_unnecessary_verified return unless new_cask? return unless cask.url return unless verified_present? add_error "the `verified` parameter has been deprecated; use the `url` stanza without it" end |
#audit_untrusted_pkg ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'cask/audit.rb', line 276 def audit_untrusted_pkg odebug "Auditing pkg stanza: allow_untrusted" return if @cask.sourcefile_path.nil? tap = @cask.tap return if tap.nil? return if tap.user != "Homebrew" return if cask.artifacts.none? { |k| k.is_a?(Artifact::Pkg) && k..key?(:allow_untrusted) } add_error "allow_untrusted is not permitted in the official homebrew/cask tap" end |
#audit_url_https_availability ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'cask/audit.rb', line 1130 def audit_url_https_availability return unless online? return unless (url = cask.url) return if url.using validate_url_for_https_availability( url, "binary URL", location: url.location, user_agents: [url.user_agent], referer: url.referer ) end |
#audit_version_special_characters ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
372 373 374 375 376 377 378 379 380 381 |
# File 'cask/audit.rb', line 372 def audit_version_special_characters return unless cask.version return if cask.version.latest? raw_version = cask.version.raw_version return if raw_version.exclude?(":") && raw_version.exclude?("/") add_error "version should not contain colons or slashes" end |
#errors ⇒ Array<Error>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
108 109 110 |
# File 'cask/audit.rb', line 108 def errors @errors ||= T.let([], T.nilable(T::Array[Error])) end |
#errors? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
113 114 115 |
# File 'cask/audit.rb', line 113 def errors? errors.any? end |
#extract_artifacts(include_manual_installers: false, &_block) {|artifacts, @tmpdir| ... } ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'cask/audit.rb', line 163 def extract_artifacts(include_manual_installers: false, &_block) return unless online? return if (download = self.download).nil? artifacts = cask.artifacts.select do |artifact| artifact.is_a?(Artifact::Pkg) || artifact.is_a?(Artifact::App) || artifact.is_a?(Artifact::Binary) || (include_manual_installers && artifact.is_a?(Artifact::Installer) && artifact.manual_install && [".app", ".pkg"].include?(artifact.path.extname.downcase)) end if @artifacts_extracted && @tmpdir yield artifacts, @tmpdir if block_given? return end return if artifacts.empty? @tmpdir ||= T.let(Pathname(Dir.mktmpdir("cask-audit", HOMEBREW_TEMP)), T.nilable(Pathname)) # Clean up tmp dir when @tmpdir object is destroyed ObjectSpace.define_finalizer( @tmpdir, proc { FileUtils.remove_entry(@tmpdir) }, ) ohai "Downloading and extracting artifacts" downloaded_path = download.fetch primary_container = UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true) return if primary_container.nil? # If the container has any dependencies we need to install them or unpacking will fail. if primary_container.dependencies.any? = { show_header: true, installed_on_request: false, verbose: false, }.compact Homebrew::Install.perform_preinstall_checks_once formula_installers = primary_container.dependencies.filter_map do |dep| next unless dep.is_a?(Formula) next if dep.linked? FormulaInstaller.new( dep, **, ) end valid_formula_installers = Homebrew::Install.fetch_formulae(formula_installers) formula_installers.each do |fi| next unless valid_formula_installers.include?(fi) fi.install fi.finish end end # Extract the container to the temporary directory. primary_container.extract_nestedly(to: @tmpdir, basename: downloaded_path.basename, verbose: false) if (nested_container = @cask.container&.nested) FileUtils.chmod_R "+rw", @tmpdir/nested_container, force: true, verbose: false UnpackStrategy.detect(@tmpdir/nested_container, merge_xattrs: true) .extract_nestedly(to: @tmpdir, verbose: false) end # Propagate quarantine attributes from the downloaded file to extracted contents. # This is necessary because some extraction tools (like 7zr) don't preserve xattrs. if Quarantine.available? && Quarantine.detect(downloaded_path) Quarantine.propagate(from: downloaded_path, to: @tmpdir) end # Process rename operations after extraction # Create a temporary installer to process renames in the audit directory temp_installer = Installer.new(@cask) temp_installer.process_rename_operations(target_dir: @tmpdir) # Set the flag to indicate that extraction has occurred. @artifacts_extracted = T.let(true, T.nilable(TrueClass)) # Yield the artifacts and temp directory to the block if provided. yield artifacts, @tmpdir if block_given? end |
#new_cask? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
76 |
# File 'cask/audit.rb', line 76 def new_cask? = !!@new_cask |
#normalize_min_os(min_os) ⇒ MacOSVersion?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'cask/audit.rb', line 256 def normalize_min_os(min_os) return if min_os.nil? return if min_os.is_a?(String) && min_os.blank? min_os = if min_os.is_a?(MacOSVersion) min_os.strip_patch else MacOSVersion.new(min_os).strip_patch end # Big Sur is sometimes identified as 10.16, so we override it to the # expected macOS version (11). min_os = MacOSVersion.new("11") if min_os == "10.16" min_os rescue MacOSVersion::Error nil end |
#online? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
79 |
# File 'cask/audit.rb', line 79 def online? =!!@online |
#result ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
137 138 139 |
# File 'cask/audit.rb', line 137 def result Formatter.error("failed") if errors? end |
#run! ⇒ ::Cask::Audit
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'cask/audit.rb', line 88 def run! only_audits = @only except_audits = @except public_methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| name = audit_method_name.delete_prefix("audit_") next if !only_audits.empty? && only_audits.exclude?(name) next if except_audits.include?(name) public_send(audit_method_name) end self rescue => e odebug e, ::Utils::Backtrace.clean(e) add_error "exception while auditing #{cask}: #{e.}" self end |
#signing? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
82 |
# File 'cask/audit.rb', line 82 def signing? = !!@signing |
#strict? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
85 |
# File 'cask/audit.rb', line 85 def strict? = !!@strict |
#success? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
118 119 120 |
# File 'cask/audit.rb', line 118 def success? !errors? end |
#summary ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
142 143 144 145 146 147 148 149 150 151 152 |
# File 'cask/audit.rb', line 142 def summary return if success? summary = ["audit for #{cask}: #{result}"] errors.each do |error| summary << " #{Formatter.error("-")} #{error[:message]}" end summary.join("\n") end |