diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index b453da9246..b0e22b9b92 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -327,10 +327,14 @@ RSpec.describe Cask::Installer, :cask do describe "#forbidden_tap_check" do before do + allow(Tap).to receive(:allowed_taps).and_return(allowed_taps_set) allow(Tap).to receive(:forbidden_taps).and_return(forbidden_taps_set) end let(:homebrew_forbidden) { Tap.fetch("homebrew/forbidden") } + let(:allowed_third_party) { Tap.fetch("nothomebrew/allowed") } + let(:disallowed_third_party) { Tap.fetch("nothomebrew/notallowed") } + let(:allowed_taps_set) { Set.new([allowed_third_party]) } let(:forbidden_taps_set) { Set.new([homebrew_forbidden]) } it "raises on forbidden tap on cask" do @@ -343,6 +347,24 @@ RSpec.describe Cask::Installer, :cask do end.to raise_error(Cask::CaskCannotBeInstalledError, /has the tap #{homebrew_forbidden}/) end + it "raises on not allowed third-party tap on cask" do + cask = Cask::Cask.new("homebrew-not-allowed-tap", tap: disallowed_third_party) do + url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.gz" + end + + expect do + described_class.new(cask).forbidden_tap_check + end.to raise_error(Cask::CaskCannotBeInstalledError, /has the tap #{disallowed_third_party}/) + end + + it "does not raise on allowed tap on cask" do + cask = Cask::Cask.new("third-party-allowed-tap", tap: allowed_third_party) do + url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.gz" + end + + expect { described_class.new(cask).forbidden_tap_check }.not_to raise_error + end + it "raises on forbidden tap on dependency" do dep_tap = homebrew_forbidden dep_name = "homebrew-forbidden-dependency-tap" diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index 611a5546b5..d0878a3e3c 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -259,10 +259,14 @@ RSpec.describe FormulaInstaller do describe "#forbidden_tap_check" do before do + allow(Tap).to receive(:allowed_taps).and_return(allowed_taps_set) allow(Tap).to receive(:forbidden_taps).and_return(forbidden_taps_set) end let(:homebrew_forbidden) { Tap.fetch("homebrew/forbidden") } + let(:allowed_third_party) { Tap.fetch("nothomebrew/allowed") } + let(:disallowed_third_party) { Tap.fetch("nothomebrew/notallowed") } + let(:allowed_taps_set) { Set.new([allowed_third_party]) } let(:forbidden_taps_set) { Set.new([homebrew_forbidden]) } it "raises on forbidden tap on formula" do @@ -288,6 +292,50 @@ RSpec.describe FormulaInstaller do f_path.parent.parent.rmtree end + it "raises on not allowed third-party tap on formula" do + f_tap = disallowed_third_party + f_name = "homebrew-not-allowed-tap" + f_path = disallowed_third_party.new_formula_path(f_name) + f_path.parent.mkpath + f_path.write <<~RUBY + class #{Formulary.class_s(f_name)} < Formula + url "foo" + version "0.1" + end + RUBY + Formulary.cache.delete(f_path) + + f = Formulary.factory("#{f_tap}/#{f_name}") + fi = described_class.new(f) + + expect do + fi.forbidden_tap_check + end.to raise_error(CannotInstallFormulaError, /has the tap #{f_tap}/) + ensure + f_path.parent.parent.parent.rmtree + end + + it "does not raise on allowed tap on formula" do + f_tap = allowed_third_party + f_name = "homebrew-allowed-tap" + f_path = allowed_third_party.new_formula_path(f_name) + f_path.parent.mkpath + f_path.write <<~RUBY + class #{Formulary.class_s(f_name)} < Formula + url "foo" + version "0.1" + end + RUBY + Formulary.cache.delete(f_path) + + f = Formulary.factory("#{f_tap}/#{f_name}") + fi = described_class.new(f) + + expect { fi.forbidden_tap_check }.not_to raise_error + ensure + f_path.parent.parent.parent.rmtree + end + it "raises on forbidden tap on dependency" do dep_tap = homebrew_forbidden dep_name = "homebrew-forbidden-dependency-tap"