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
- DOWNLOAD_TIMEOUT =
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.
600- GATEKEEPER_BUNDLE_ARTIFACTS =
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.let([ Artifact::App, Artifact::AudioUnitPlugin, Artifact::Colorpicker, Artifact::InputMethod, Artifact::InternetPlugin, Artifact::Mdimporter, Artifact::Prefpane, Artifact::ScreenSaver, Artifact::Service, Artifact::Vst3Plugin, Artifact::VstPlugin ].freeze, T::Array[T.class_of(Artifact::Moved)])
- 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, corrected: false) ⇒ void private
- #audit_appimage_versioned_target ⇒ 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_domain_age ⇒ 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_required ⇒ 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_self_submission ⇒ 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_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_url_https_availability ⇒ void private
- #audit_version_special_characters ⇒ void private
- #audit_zap_required ⇒ void private
- #cask_sparkle_min_os ⇒ MacOSVersion? private
- #errors ⇒ Array<Error> private
- #errors? ⇒ Boolean private
- #extract_artifacts(include_manual_installers: false, include_all_signable_artifacts: false, &_block) {|artifacts, @tmpdir| ... } ⇒ void private
- #fix? ⇒ Boolean private
- #initialize(cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, fix: 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_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #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
#command_sandbox, #system_command, #system_command!
Constructor Details
#initialize(cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, fix: 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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'cask/audit.rb', line 64 def initialize( cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, fix: 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 @download_failed = T.let(false, T::Boolean) @online = online @strict = strict @signing = signing @new_cask = new_cask @fix = fix @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.
48 49 50 |
# File 'cask/audit.rb', line 48 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.
51 52 53 |
# File 'cask/audit.rb', line 51 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.
54 55 56 |
# File 'cask/audit.rb', line 54 def livecheck_result=(value) @livecheck_result = value end |
Instance Method Details
#add_error(message, location: nil, strict_only: false, corrected: 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.
150 151 152 153 154 155 |
# File 'cask/audit.rb', line 150 def add_error(, location: nil, strict_only: false, corrected: false) # Only raise non-critical audits if the user specified `--strict`. return if strict_only && !@strict errors << { message:, location:, corrected: } end |
#audit_appimage_versioned_target ⇒ 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.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'cask/audit.rb', line 399 def audit_appimage_versioned_target # `app_image` artifacts live inside `on_linux` blocks, # so an audit running on another OS would not materialize them. # Evaluate every tag (restoring the default afterwards) # so the check runs regardless of the audit host. basenames = if cask.on_system_blocks_exist? begin OnSystem::VALID_OS_ARCH_TAGS.flat_map do |tag| cask.refresh_for_tag(tag) { appimage_target_basenames } || [] end ensure cask.refresh end else appimage_target_basenames end basenames.uniq.each do |basename| # electron-updater renames the AppImage on self-update # if its basename contains an `X.Y.Z` version, # which leaves the Caskroom back-symlink dangling. # A version-less target is overwritten in place instead. next unless basename.match?(/\d+\.\d+\.\d+/) add_error "app_image target '#{basename}' should not embed a version; " \ "use a version-less `target:` so self-updaters overwrite it in place" end 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.
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 |
# File 'cask/audit.rb', line 768 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 = "Artifact #{source} does not match the case of the extracted " \ "#{File.join(on_disk)}; this fails on case-sensitive filesystems" dsl_key = artifact.class.dsl_key fixed = correct_error("#{}; corrected the `#{dsl_key}` stanza", location: url.location) do |cask_ast| cask_ast.replace_stanza_value(dsl_key, source.to_s, File.join(on_disk)).positive? end next if fixed add_error "#{}.", 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.
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'cask/audit.rb', line 1133 def audit_bitbucket_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(SharedAudits::NOTABILITY_REPOSITORY_REGEXES.fetch(:bitbucket)) 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.
1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'cask/audit.rb', line 1281 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.
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 |
# File 'cask/audit.rb', line 1163 def audit_conflicts_with return if !cask.tap&.official? || cask.conflicts_with.nil? Homebrew::API.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.
1175 1176 1177 1178 1179 1180 |
# File 'cask/audit.rb', line 1175 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.
1292 1293 1294 1295 |
# File 'cask/audit.rb', line 1292 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.
378 379 380 381 382 383 384 |
# File 'cask/audit.rb', line 378 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.
611 612 613 |
# File 'cask/audit.rb', line 611 def audit_download fetch_download 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.
526 527 528 529 530 531 532 533 534 |
# File 'cask/audit.rb', line 526 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_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.
537 538 539 540 541 542 |
# File 'cask/audit.rb', line 537 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.
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'cask/audit.rb', line 1040 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.
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
# File 'cask/audit.rb', line 1148 def audit_forgejo_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(SharedAudits::NOTABILITY_REPOSITORY_REGEXES.fetch(:forgejo)) 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.
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 |
# File 'cask/audit.rb', line 1086 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.
545 546 547 548 549 550 551 |
# File 'cask/audit.rb', line 545 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.
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'cask/audit.rb', line 1011 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.
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 |
# File 'cask/audit.rb', line 1103 def audit_github_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(SharedAudits::NOTABILITY_REPOSITORY_REGEXES.fetch(:github)) 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.
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'cask/audit.rb', line 1054 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.
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'cask/audit.rb', line 1025 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.
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
# File 'cask/audit.rb', line 1118 def audit_gitlab_repository return unless new_cask? return if (url = cask.url).nil? user, repo = get_repo_data(SharedAudits::NOTABILITY_REPOSITORY_REGEXES.fetch(:gitlab)) 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.
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'cask/audit.rb', line 1069 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_domain_age ⇒ 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.
1212 1213 1214 1215 1216 1217 1218 1219 |
# File 'cask/audit.rb', line 1212 def audit_homepage_domain_age return unless new_cask? return unless cask.tap&.official? return unless (homepage = cask.homepage) new_domain_problem = SharedAudits.new_domain_problem(homepage) add_error new_domain_problem if new_domain_problem 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.
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'cask/audit.rb', line 1192 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.
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'cask/audit.rb', line 503 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.uri.host when /(?:\A|\.)sourceforge\.net\z/ return unless online? add_error "Download is hosted on SourceForge, #{add_livecheck}", location: url.location when "dl.devmate.com" add_error "Download is hosted on DevMate, #{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.
554 555 556 557 558 559 560 |
# File 'cask/audit.rb', line 554 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.
492 493 494 495 496 497 |
# File 'cask/audit.rb', line 492 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.
483 484 485 486 487 488 489 |
# File 'cask/audit.rb', line 483 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.
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 |
# File 'cask/audit.rb', line 1256 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_required ⇒ 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.
1232 1233 1234 1235 1236 1237 1238 1239 |
# File 'cask/audit.rb', line 1232 def audit_livecheck_required return unless new_cask? return unless cask.tap&.official? return if cask.version&.latest? livecheck_required_problem = SharedAudits.livecheck_required_problem(cask) add_error livecheck_required_problem if livecheck_required_problem 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.
616 617 618 619 620 621 622 623 624 625 626 |
# File 'cask/audit.rb', line 616 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.
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
# File 'cask/audit.rb', line 899 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.
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'cask/audit.rb', line 949 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 on_system_block_min_os.to_s > depends_on_min_os.to_s "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 = (bundle_min_os.to_s > sparkle_min_os.to_s) ? "Artifact" : "Upstream" = "#{source} defined #{app_min_os.to_sym.inspect} as the minimum macOS version " \ "but the cask declared #{min_os_definition}" # A cask with `on_system` blocks may have a different minimum per OS or # arch, so a top-level `depends_on macos:` stanza would be wrong. maximum_macos = cask.depends_on.maximum_macos&.maximum_version unsatisfiable_minimum = maximum_macos.present? && app_min_os > maximum_macos if !cask.on_system_blocks_exist? && !unsatisfiable_minimum fixed = correct_error("#{}; set `depends_on macos:` to #{app_min_os.to_sym.inspect}") do |cask_ast| cask_ast.update_depends_on_macos_minimum!(app_min_os.to_sym) end return if fixed end add_error 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.
429 430 431 432 433 434 435 436 |
# File 'cask/audit.rb', line 429 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.
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'cask/audit.rb', line 339 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.
1183 1184 1185 1186 1187 1188 1189 |
# File 'cask/audit.rb', line 1183 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.
824 825 826 827 828 829 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 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'cask/audit.rb', line 824 def audit_rosetta return if (url = cask.url).nil? return unless online? return unless Homebrew::SimulateSystem.simulating_or_running_on_macos? return if Homebrew::SimulateSystem.current_arch != :arm 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 new_cask? add_error "New casks must not require Rosetta 2!", location: url.location elsif !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_self_submission ⇒ 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.
1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'cask/audit.rb', line 1222 def audit_self_submission return unless new_cask? return unless online? return unless cask.tap&.official? self_submission_problem = SharedAudits.self_submission_problem(self_submission_urls) add_error self_submission_problem if self_submission_problem 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.
461 462 463 464 465 466 467 468 469 |
# File 'cask/audit.rb', line 461 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.
472 473 474 475 476 477 478 479 480 |
# File 'cask/audit.rb', line 472 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.
439 440 441 442 443 444 445 446 447 448 |
# File 'cask/audit.rb', line 439 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.
451 452 453 454 455 456 457 458 |
# File 'cask/audit.rb', line 451 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.
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 704 705 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 753 754 755 756 757 758 759 760 761 762 763 764 765 |
# File 'cask/audit.rb', line 629 def audit_signing return if download.blank? url = cask.url return if url.nil? return if !cask.tap&.official? && !signing? deprecated_or_disabled = cask.deprecated? || cask.disabled? deprecate_disable_reason = cask.disabled? ? cask.disable_reason : cask.deprecation_reason gatekeeper_failure_expected = deprecate_disable_reason == :fails_gatekeeper_check return if deprecated_or_disabled && !gatekeeper_failure_expected 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_all_signable_artifacts: 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 package_assessment(path) when Artifact::Installer if artifact.path.extname.downcase == ".app" gatekeeper_scan(path) elsif artifact.path.extname.downcase == ".pkg" package_assessment(path) elsif !artifact.manual_install && BinaryPathname.wrap(path).binary_executable? notarization_check(path) else next false end when Artifact::Binary # Shell scripts cannot be signed, so we skip them next false if ::Utils::Path.text_executable?(path) notarization_check(path) when Artifact::Suite, Artifact::Artifact bundle_extnames = %w[ .app .bundle .colorpicker .component .mdimporter .plugin .prefpane .saver .service .vst .vst3 ] # `gktool scan` fails any plain folder, so check the bundles and executables inside instead. failed_path, failed_result = path.find do |found| next if found.symlink? bundle = found.directory? && bundle_extnames.include?(found.extname.downcase) # Gatekeeper can reject quarantined resource-only bundles, so traverse them as plain folders. if bundle && found.extname.downcase == ".bundle" && !(found/"Contents/Info.plist").file? && !(found/"Info.plist").file? bundle = found.find.any? do |child| # The outer traversal assesses nested bundles separately. Find.prune if child != found && child.directory? && bundle_extnames.include?(child.extname.downcase) next false unless child.file? binary = BinaryPathname.wrap(child) binary.binary_executable? || binary.dylib? || binary.mach_o_bundle? end end found_result = if bundle gatekeeper_scan(found) elsif found.file? && found.executable? && BinaryPathname.wrap(found).binary_executable? notarization_check(found) end break found, found_result if found_result&.success? == false Find.prune if bundle end path = failed_path if failed_path failed_result when *GATEKEEPER_BUNDLE_ARTIFACTS gatekeeper_scan(path) else add_error "Unknown artifact type: #{artifact.class}", location: url.location next end next false if result.nil? || result.success? next true if gatekeeper_failure_expected next true if is_in_skiplist = <<~EOS Signature verification failed for #{path.relative_path_from(tmpdir)}: #{result.merged_output.gsub(%r{\r?Progress: \d+/\d+\n?}, "")} 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 gatekeeper_failure_expected add_error <<~EOS Cask is deprecated/disabled 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_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.
331 332 333 334 335 336 |
# File 'cask/audit.rb', line 331 def audit_single_zap odebug "Auditing single zap stanzas" 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.
321 322 323 324 325 326 327 328 |
# File 'cask/audit.rb', line 321 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.
563 564 565 566 567 568 569 |
# File 'cask/audit.rb', line 563 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 " \ "#{::Utils::Text.to_sentence(errors, conjunction: "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.
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'cask/audit.rb', line 583 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.
572 573 574 575 576 577 578 579 580 |
# File 'cask/audit.rb', line 572 def audit_token_conflicts return unless strict? Homebrew::API.with_no_api_env_if_needed(core_tap.installed?) 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_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.
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 |
# File 'cask/audit.rb', line 1242 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&.to_s ) 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.
387 388 389 390 391 392 393 394 395 396 |
# File 'cask/audit.rb', line 387 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 |
#audit_zap_required ⇒ 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.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'cask/audit.rb', line 361 def audit_zap_required return unless cask.tap&.official? return if cask.deprecated? || cask.disabled? return if cask.artifacts.any?(Artifact::Zap) zap_suggestion = if Homebrew::SimulateSystem.simulating_or_running_on_linux? "Add one" else # `brew generate-zap` only scans macOS paths. "Generate one with `brew generate-zap #{cask.token}`" end add_error "Casks must have a `zap` stanza for every OS and architecture they support. " \ "#{zap_suggestion} or use `zap :not_required` only if there is nothing to zap. " \ "See #{Formatter.url("https://docs.brew.sh/Cask-Cookbook#stanza-zap")}" end |
#cask_sparkle_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.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'cask/audit.rb', line 290 def cask_sparkle_min_os return unless online? return unless cask.livecheck_defined? return if (livecheck = cask.livecheck).strategy != :sparkle return unless (livecheck_url = livecheck.url) # `Sparkle` strategy blocks that use the `items` argument (instead of # `item`) contain arbitrary logic that ignores/overrides the strategy's # sorting, so we can't identify which item would be first/newest here. return if livecheck.strategy_block.present? && livecheck.strategy_block.parameters[0] == [:opt, :items] url = Homebrew::Livecheck.livecheck_url_to_string(livecheck_url, cask) content = Homebrew::Livecheck::Strategy.page_content(url, options: livecheck.)[:content] return if content.blank? begin items = Homebrew::Livecheck::Strategy::Sparkle.sort_items( Homebrew::Livecheck::Strategy::Sparkle.filter_items( Homebrew::Livecheck::Strategy::Sparkle.items_from_content(content), ), ) rescue return end return if items.blank? normalize_min_os(items.fetch(0).minimum_system_version) 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.
128 129 130 |
# File 'cask/audit.rb', line 128 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.
133 134 135 |
# File 'cask/audit.rb', line 133 def errors? errors.any? end |
#extract_artifacts(include_manual_installers: false, include_all_signable_artifacts: 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.
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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'cask/audit.rb', line 185 def extract_artifacts(include_manual_installers: false, include_all_signable_artifacts: false, &_block) return unless online? return if download.nil? || @download_failed 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)) || (include_all_signable_artifacts && [Artifact::Installer, Artifact::Suite, Artifact::Artifact, *GATEKEEPER_BUNDLE_ARTIFACTS] .any? { artifact.is_a?(it) }) 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" return unless (downloaded_path = fetch_download) 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. Quarantine.propagate(from: downloaded_path, to: @tmpdir) # 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 |
#fix? ⇒ 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.
105 |
# File 'cask/audit.rb', line 105 def fix? = !!@fix |
#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.
93 |
# File 'cask/audit.rb', line 93 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.
279 280 281 282 283 284 285 286 287 |
# File 'cask/audit.rb', line 279 def normalize_min_os(min_os) return if min_os.nil? return if min_os.is_a?(String) && min_os.blank? min_os = MacOSVersion.new(min_os) unless min_os.is_a?(MacOSVersion) MacOSVersion.new(min_os.release_version) 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.
96 |
# File 'cask/audit.rb', line 96 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.
158 159 160 |
# File 'cask/audit.rb', line 158 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.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'cask/audit.rb', line 108 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.
99 |
# File 'cask/audit.rb', line 99 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.
102 |
# File 'cask/audit.rb', line 102 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.
138 139 140 |
# File 'cask/audit.rb', line 138 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.
163 164 165 166 167 168 169 170 171 172 173 |
# File 'cask/audit.rb', line 163 def summary return if success? summary = ["audit for #{cask}: #{result}"] errors.each do |error| summary << " #{Formatter.error("-")} #{error[:message]}" end summary.join("\n") end |