- remove cask/cmd/audit
- repair cmd/audit
This commit is contained in:
parent
df14a969d0
commit
4999639140
@ -10,7 +10,6 @@ require "extend/optparse"
|
|||||||
require "cask/config"
|
require "cask/config"
|
||||||
|
|
||||||
require "cask/cmd/abstract_command"
|
require "cask/cmd/abstract_command"
|
||||||
require "cask/cmd/audit"
|
|
||||||
require "cask/cmd/install"
|
require "cask/cmd/install"
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
|
|||||||
@ -1,110 +0,0 @@
|
|||||||
# typed: false
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "utils/github/actions"
|
|
||||||
|
|
||||||
module Cask
|
|
||||||
class Cmd
|
|
||||||
# Cask implementation of the `brew audit` command.
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
class Audit < AbstractCommand
|
|
||||||
extend T::Sig
|
|
||||||
|
|
||||||
def self.parser
|
|
||||||
super do
|
|
||||||
switch "--[no-]download",
|
|
||||||
description: "Audit the downloaded file"
|
|
||||||
switch "--[no-]appcast",
|
|
||||||
description: "Audit the appcast",
|
|
||||||
replacement: false
|
|
||||||
switch "--[no-]token-conflicts",
|
|
||||||
description: "Audit for token conflicts"
|
|
||||||
switch "--[no-]signing",
|
|
||||||
description: "Audit for signed apps, which is required on ARM"
|
|
||||||
switch "--[no-]strict",
|
|
||||||
description: "Run additional, stricter style checks"
|
|
||||||
switch "--[no-]online",
|
|
||||||
description: "Run additional, slower style checks that require a network connection"
|
|
||||||
switch "--new-cask",
|
|
||||||
description: "Run various additional style checks to determine if a new cask is eligible " \
|
|
||||||
"for Homebrew. This should be used when creating new casks and implies " \
|
|
||||||
"`--strict` and `--online`"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def run
|
|
||||||
casks = args.named.flat_map do |name|
|
|
||||||
next name if File.exist?(name)
|
|
||||||
next Tap.fetch(name).cask_files if name.count("/") == 1
|
|
||||||
|
|
||||||
name
|
|
||||||
end
|
|
||||||
casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) }
|
|
||||||
any_named_args = casks.any?
|
|
||||||
casks = Cask.to_a if casks.empty?
|
|
||||||
|
|
||||||
results = self.class.audit_casks(
|
|
||||||
*casks,
|
|
||||||
download: args.download?,
|
|
||||||
online: args.online?,
|
|
||||||
strict: args.strict?,
|
|
||||||
signing: args.signing?,
|
|
||||||
new_cask: args.new_cask?,
|
|
||||||
token_conflicts: args.token_conflicts?,
|
|
||||||
quarantine: args.quarantine?,
|
|
||||||
any_named_args: any_named_args,
|
|
||||||
language: args.language,
|
|
||||||
only: [],
|
|
||||||
except: [],
|
|
||||||
)
|
|
||||||
|
|
||||||
failed_casks = results.reject { |_, result| result[:errors].empty? }.map(&:first)
|
|
||||||
return if failed_casks.empty?
|
|
||||||
|
|
||||||
raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.audit_casks(
|
|
||||||
*casks,
|
|
||||||
download:,
|
|
||||||
online:,
|
|
||||||
strict:,
|
|
||||||
signing:,
|
|
||||||
new_cask:,
|
|
||||||
token_conflicts:,
|
|
||||||
quarantine:,
|
|
||||||
any_named_args:,
|
|
||||||
language:,
|
|
||||||
only:,
|
|
||||||
except:
|
|
||||||
)
|
|
||||||
options = {
|
|
||||||
audit_download: download,
|
|
||||||
audit_online: online,
|
|
||||||
audit_strict: strict,
|
|
||||||
audit_signing: signing,
|
|
||||||
audit_new_cask: new_cask,
|
|
||||||
audit_token_conflicts: token_conflicts,
|
|
||||||
quarantine: quarantine,
|
|
||||||
language: language,
|
|
||||||
any_named_args: any_named_args,
|
|
||||||
only: only,
|
|
||||||
except: except,
|
|
||||||
}.compact
|
|
||||||
|
|
||||||
options[:quarantine] = true if options[:quarantine].nil?
|
|
||||||
|
|
||||||
Homebrew.auditing = true
|
|
||||||
|
|
||||||
require "cask/auditor"
|
|
||||||
|
|
||||||
casks.to_h do |cask|
|
|
||||||
odebug "Auditing Cask #{cask}"
|
|
||||||
[cask.sourcefile_path, { errors: Auditor.audit(cask, **options), warnings: [] }]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -237,8 +237,6 @@ module Homebrew
|
|||||||
cask_results = if audit_casks.empty?
|
cask_results = if audit_casks.empty?
|
||||||
{}
|
{}
|
||||||
else
|
else
|
||||||
require "cask/cmd/abstract_command"
|
|
||||||
require "cask/cmd/audit"
|
|
||||||
|
|
||||||
if args.display_failures_only?
|
if args.display_failures_only?
|
||||||
odeprecated "`brew audit <cask> --display-failures-only`", "`brew audit <cask>` without the argument"
|
odeprecated "`brew audit <cask> --display-failures-only`", "`brew audit <cask>` without the argument"
|
||||||
@ -246,21 +244,31 @@ module Homebrew
|
|||||||
|
|
||||||
# For switches, we add `|| nil` so that `nil` will be passed instead of `false` if they aren't set.
|
# For switches, we add `|| nil` so that `nil` will be passed instead of `false` if they aren't set.
|
||||||
# This way, we can distinguish between "not set" and "set to false".
|
# This way, we can distinguish between "not set" and "set to false".
|
||||||
Cask::Cmd::Audit.audit_casks(
|
options = {
|
||||||
*audit_casks,
|
audit_download: nil,
|
||||||
download: nil,
|
|
||||||
# No need for `|| nil` for `--[no-]signing` because boolean switches are already `nil` if not passed
|
# No need for `|| nil` for `--[no-]signing` because boolean switches are already `nil` if not passed
|
||||||
signing: args.signing?,
|
audit_online: (args.online? || nil),
|
||||||
online: args.online? || nil,
|
audit_strict: (args.strict? || nil),
|
||||||
strict: args.strict? || nil,
|
audit_signing: args.signing?,
|
||||||
new_cask: args.new_cask? || nil,
|
audit_new_cask: (args.new_cask? || nil),
|
||||||
token_conflicts: args.token_conflicts? || nil,
|
audit_token_conflicts: (args.token_conflicts? || nil),
|
||||||
quarantine: nil,
|
quarantine: nil,
|
||||||
any_named_args: !no_named_args,
|
|
||||||
language: nil,
|
language: nil,
|
||||||
|
any_named_args: !no_named_args,
|
||||||
only: args.only,
|
only: args.only,
|
||||||
except: args.except,
|
except: args.except,
|
||||||
)
|
}.compact
|
||||||
|
|
||||||
|
options[:quarantine] = true if options[:quarantine].nil?
|
||||||
|
|
||||||
|
Homebrew.auditing = true
|
||||||
|
|
||||||
|
require "cask/auditor"
|
||||||
|
|
||||||
|
audit_casks.to_h do |cask|
|
||||||
|
odebug "Auditing Cask #{cask}"
|
||||||
|
[cask.sourcefile_path, { errors: Cask::Auditor.audit(cask, **options), warnings: [] }]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
failed_casks = cask_results.reject { |_, result| result[:errors].empty? }
|
failed_casks = cask_results.reject { |_, result| result[:errors].empty? }
|
||||||
|
|||||||
@ -1,161 +0,0 @@
|
|||||||
# typed: false
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "cask/auditor"
|
|
||||||
|
|
||||||
describe Cask::Cmd::Audit, :cask do
|
|
||||||
let(:cask) { Cask::Cask.new("cask") }
|
|
||||||
let(:cask_with_many_languages) { Cask::CaskLoader.load(cask_path("with-many-languages")) }
|
|
||||||
let(:result) { Set.new }
|
|
||||||
|
|
||||||
describe "selection of Casks to audit" do
|
|
||||||
it "audits all Casks if no tokens are given" do
|
|
||||||
allow(Cask::Cask).to receive(:to_a).and_return([cask, cask])
|
|
||||||
|
|
||||||
expect(Cask::Auditor).to receive(:audit).twice.and_return(result)
|
|
||||||
|
|
||||||
described_class.run
|
|
||||||
end
|
|
||||||
|
|
||||||
it "audits specified Casks if tokens are given" do
|
|
||||||
cask_token = "nice-app"
|
|
||||||
expect(Cask::CaskLoader).to receive(:load).with(cask_token, any_args).and_return(cask)
|
|
||||||
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run(cask_token)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not pass anything if no flags are specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `audit_download` if the `--download` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_download: true, audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--download")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `audit_token_conflicts` if the `--token-conflicts` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_token_conflicts: true, audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--token-conflicts")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `audit_strict` if the `--strict` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_strict: true, audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--strict")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `audit_online` if the `--online` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_online: true, audit_new_cask: false, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--online")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `audit_new_cask` if the `--new-cask` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: true, quarantine: true, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--new-cask")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `language` if the `--language` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: false, quarantine: true, language: ["de-AT"], any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--language=de-AT")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `quarantine` if the `--no-quarantine` flag is specified" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: false, quarantine: false, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken", "--no-quarantine")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "passes `quarantine` if the `--no-quarantine` flag is in HOMEBREW_CASK_OPTS" do
|
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--no-quarantine"
|
|
||||||
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
|
|
||||||
expect(Cask::Auditor).to receive(:audit)
|
|
||||||
.with(
|
|
||||||
cask,
|
|
||||||
audit_new_cask: false, quarantine: false, any_named_args: true,
|
|
||||||
only: [], except: []
|
|
||||||
)
|
|
||||||
.and_return(result)
|
|
||||||
|
|
||||||
described_class.run("casktoken")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "audits a sample of language when cask contains more than 10 languages" do
|
|
||||||
allow(Cask::CaskLoader).to receive(:load).and_return(cask_with_many_languages)
|
|
||||||
expect do
|
|
||||||
described_class.run("with-many-languages")
|
|
||||||
end.to output(/==> auditing a sample of available languages/im).to_stdout
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
# typed: false
|
# typed: false
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cask/cmd/audit"
|
|
||||||
require "cask/cmd/install"
|
require "cask/cmd/install"
|
||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
require "cask/download"
|
require "cask/download"
|
||||||
@ -36,17 +35,6 @@ describe Cask::Quarantine, :cask do
|
|||||||
expect(cached_location).to be_quarantined
|
expect(cached_location).to be_quarantined
|
||||||
end
|
end
|
||||||
|
|
||||||
it "quarantines Cask audits" do
|
|
||||||
expect do
|
|
||||||
Cask::Cmd::Audit.run("local-transmission", "--download")
|
|
||||||
end.to not_raise_error.and not_to_output.to_stderr
|
|
||||||
|
|
||||||
local_transmission = Cask::CaskLoader.load(cask_path("local-transmission"))
|
|
||||||
cached_location = Cask::Download.new(local_transmission).fetch
|
|
||||||
|
|
||||||
expect(cached_location).to be_quarantined
|
|
||||||
end
|
|
||||||
|
|
||||||
it "quarantines Cask installs even if the fetch was not" do
|
it "quarantines Cask installs even if the fetch was not" do
|
||||||
download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: false)
|
download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: false)
|
||||||
download.fetch
|
download.fetch
|
||||||
@ -151,17 +139,6 @@ describe Cask::Quarantine, :cask do
|
|||||||
expect(cached_location).not_to be_quarantined
|
expect(cached_location).not_to be_quarantined
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not quarantine Cask audits" do
|
|
||||||
expect do
|
|
||||||
Cask::Cmd::Audit.run("local-transmission", "--download", "--no-quarantine")
|
|
||||||
end.to not_raise_error.and not_to_output.to_stderr
|
|
||||||
|
|
||||||
local_transmission = Cask::CaskLoader.load(cask_path("local-transmission"))
|
|
||||||
cached_location = Cask::Download.new(local_transmission).fetch
|
|
||||||
|
|
||||||
expect(cached_location).not_to be_quarantined
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not quarantine Cask installs even if the fetch was" do
|
it "does not quarantine Cask installs even if the fetch was" do
|
||||||
download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: true)
|
download = Cask::Download.new(Cask::CaskLoader.load("local-transmission"), quarantine: true)
|
||||||
download.fetch
|
download.fetch
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user