diff options
| author | Markus Reiter | 2017-05-19 20:48:35 +0200 |
|---|---|---|
| committer | GitHub | 2017-05-19 20:48:35 +0200 |
| commit | 3139383fe6f642889313bd01d90554fb71400c90 (patch) | |
| tree | 492a53155e18ba64a6bf921dbb4e389591b9abf7 | |
| parent | 78296ab62b4fc7363dd2c7e237eb6787d730f54e (diff) | |
| parent | 61db2a58a5232fe67b7f0850d1421af0d38fdb29 (diff) | |
| download | brew-3139383fe6f642889313bd01d90554fb71400c90.tar.bz2 | |
Merge pull request #2623 from rednoah/master
Support GPG (signed data) container in Homebrew Cask
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container/gpg.rb | 41 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/installer_spec.rb | 13 | ||||
| -rw-r--r-- | Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb | 12 | ||||
| -rw-r--r-- | Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg | bin | 0 -> 813 bytes |
5 files changed, 68 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index 961e31968..93e825e03 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -6,6 +6,7 @@ require "hbc/container/criteria" require "hbc/container/dmg" require "hbc/container/executable" require "hbc/container/generic_unar" +require "hbc/container/gpg" require "hbc/container/gzip" require "hbc/container/lzma" require "hbc/container/naked" @@ -40,6 +41,7 @@ module Hbc Gzip, # pure gzip Lzma, # pure lzma Xz, # pure xz + Gpg, # GnuPG signed data Executable, ] # for explicit use only (never autodetected): diff --git a/Library/Homebrew/cask/lib/hbc/container/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb new file mode 100644 index 000000000..3f37b5aa6 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -0,0 +1,41 @@ +require "tmpdir" + +require "hbc/container/base" + +module Hbc + class Container + class Gpg < Base + def self.me?(criteria) + criteria.extension(/^(gpg)$/) + end + + def import_key + if @cask.gpg.nil? + raise CaskError, "Expected to find gpg public key in formula. Cask '#{@cask}' must add: 'gpg :embedded, key_id: [Public Key ID]' or 'gpg :embedded, key_url: [Public Key URL]'" + end + + args = if @cask.gpg.key_id + ["--recv-keys", @cask.gpg.key_id] + elsif @cask.gpg.key_url + ["--fetch-key", @cask.gpg.key_url.to_s] + end + + @command.run!("gpg", args: args) + end + + def extract + if (gpg = which("gpg")).nil? + raise CaskError, "Expected to find gpg executable. Cask '#{@cask}' must add: depends_on formula: 'gpg'" + end + + import_key + + Dir.mktmpdir do |unpack_dir| + @command.run!(gpg, args: ["--batch", "--yes", "--output", Pathname(unpack_dir).join(@path.basename(".gpg")), "--decrypt", @path]) + + extract_nested_inside(unpack_dir) + end + end + end + end +end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 59d61bbdd..0ae7c14a5 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -161,6 +161,19 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container-lzma--#{asset.version}")).to be_a_file end + it "works with gpg-based Casks" do + skip("gpg not installed") if which("gpg").nil? + asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gpg.rb") + + allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) + shutup do + Hbc::Installer.new(asset).install + end + + expect(Hbc.caskroom.join("container-gpg", asset.version)).to be_a_directory + expect(Hbc.appdir.join("container")).to be_a_file + end + it "blows up on a bad checksum" do bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") expect { diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb new file mode 100644 index 000000000..630527ce2 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb @@ -0,0 +1,12 @@ +cask 'container-gpg' do + version '1.2.3' + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.xz.gpg" + gpg :embedded, key_id: 'B0976E51E5C047AD0FD051294E402EBF7C3C6A71' + + homepage 'https://example.com/container-gpg' + depends_on formula: 'gpg' + + app 'container' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg b/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg Binary files differnew file mode 100644 index 000000000..be250e851 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg |
