add `gpg` stanza to DSL
For forward compatibility. The stanza has no effect, and is intentionally left undocumented at this time. References: #4688
This commit is contained in:
parent
05a121e483
commit
33f8cc431a
|
@ -21,6 +21,7 @@ require 'cask/download_strategy'
|
|||
require 'cask/dsl'
|
||||
require 'cask/exceptions'
|
||||
require 'cask/fetcher'
|
||||
require 'cask/gpg'
|
||||
require 'cask/installer'
|
||||
require 'cask/link_checker'
|
||||
require 'cask/locations'
|
||||
|
|
|
@ -12,6 +12,8 @@ module Cask::DSL
|
|||
|
||||
def appcast; self.class.appcast; end
|
||||
|
||||
def gpg; self.class.gpg; end
|
||||
|
||||
def version; self.class.version; end
|
||||
|
||||
def depends_on_formula; self.class.depends_on_formula; end
|
||||
|
@ -50,6 +52,17 @@ module Cask::DSL
|
|||
end
|
||||
end
|
||||
|
||||
def gpg(*args)
|
||||
if @gpg and !args.empty?
|
||||
raise CaskInvalidError.new(self.title, "'gpg' stanza may only appear once")
|
||||
end
|
||||
@gpg ||= begin
|
||||
Cask::Gpg.new(*args) unless args.empty?
|
||||
rescue StandardError => e
|
||||
raise CaskInvalidError.new(self.title, e)
|
||||
end
|
||||
end
|
||||
|
||||
def container_type(type=nil)
|
||||
if @container_type and !type.nil?
|
||||
raise CaskInvalidError.new(self.title, "'container_type' stanza may only appear once")
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
class Cask::Gpg
|
||||
|
||||
VALID_TYPES = Set.new [
|
||||
:id, # first one is the default
|
||||
:url,
|
||||
]
|
||||
|
||||
REQUIRED_PARAMETERS = [
|
||||
:signature
|
||||
]
|
||||
|
||||
attr_reader :key, :parameters, :type, :signature
|
||||
|
||||
def initialize(key, parameters={})
|
||||
@parameters = parameters
|
||||
REQUIRED_PARAMETERS.each do |param|
|
||||
unless @parameters.key?(param) and not @parameters[param].nil?
|
||||
raise "gpg #{param.inspect} parameter is required"
|
||||
end
|
||||
end
|
||||
@key = key
|
||||
@signature = Cask::UnderscoreSupportingURI.parse(@parameters[:signature])
|
||||
@type = @parameters[:type]
|
||||
@type = VALID_TYPES.first if @type.nil?
|
||||
unless VALID_TYPES.include?(@type)
|
||||
raise "invalid gpg type: '#{@type.inspect}'"
|
||||
end
|
||||
if @type == :url
|
||||
@key = Cask::UnderscoreSupportingURI.parse(@key)
|
||||
end
|
||||
end
|
||||
|
||||
def to_yaml
|
||||
[@key, @parameters].to_yaml
|
||||
end
|
||||
|
||||
def to_s
|
||||
@key.to_s
|
||||
end
|
||||
end
|
|
@ -82,6 +82,7 @@ module Cask::Utils
|
|||
:caveats,
|
||||
:depends_on_formula,
|
||||
:container_type,
|
||||
:gpg,
|
||||
].each do |method|
|
||||
odebug "Cask instance method '#{method}':", self.send(method).to_yaml
|
||||
end
|
||||
|
|
|
@ -112,4 +112,36 @@ describe Cask::DSL do
|
|||
}.must_raise(CaskInvalidError)
|
||||
err.message.must_include "'version' stanza may only appear once"
|
||||
end
|
||||
|
||||
describe "gpg stanza" do
|
||||
it "allows gpg stanza to be specified" do
|
||||
cask = Cask.load('with-gpg')
|
||||
cask.gpg.to_s.must_match %r{\S}
|
||||
end
|
||||
|
||||
it "prevents specifying gpg multiple times" do
|
||||
err = lambda {
|
||||
invalid_cask = Cask.load('invalid/invalid-gpg-multiple')
|
||||
}.must_raise(CaskInvalidError)
|
||||
err.message.must_include "'gpg' stanza may only appear once"
|
||||
end
|
||||
|
||||
it "refuses to load invalid gpg signature URLs" do
|
||||
err = lambda {
|
||||
invalid_cask = Cask.load('invalid/invalid-gpg-signature-url')
|
||||
}.must_raise(CaskInvalidError)
|
||||
end
|
||||
|
||||
it "refuses to load invalid gpg key URLs" do
|
||||
err = lambda {
|
||||
invalid_cask = Cask.load('invalid/invalid-gpg-key-url')
|
||||
}.must_raise(CaskInvalidError)
|
||||
end
|
||||
|
||||
it "refuses to load if gpg :type is invalid" do
|
||||
err = lambda {
|
||||
invalid_cask = Cask.load('invalid/invalid-gpg-type')
|
||||
}.must_raise(CaskInvalidError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class InvalidGpgKeyUrl < TestCask
|
||||
url TestHelper.local_binary('caffeine.zip')
|
||||
homepage 'http://example.com/invalid-gpg-key-url'
|
||||
gpg 1, :type => :url,
|
||||
:signature => 'http://example.com/gpg-signature.asc'
|
||||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
|
||||
version '1.2.3'
|
||||
link 'Caffeine.app'
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class InvalidGpgMultiple < TestCask
|
||||
url TestHelper.local_binary('caffeine.zip')
|
||||
homepage 'http://example.com/invalid-gpg-multiple'
|
||||
gpg 'ID', :type => :id,
|
||||
:signature => 'http://example.com/gpg-signature.asc'
|
||||
gpg 'ID', :type => :id,
|
||||
:signature => 'http://example.com/gpg-signature.asc'
|
||||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
|
||||
version '1.2.3'
|
||||
link 'Caffeine.app'
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class InvalidGpgSignatureUrl < TestCask
|
||||
url TestHelper.local_binary('caffeine.zip')
|
||||
homepage 'http://example.com/invalid-gpg-signature-url'
|
||||
gpg 'ID', :type => :id,
|
||||
:signature => 1
|
||||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
|
||||
version '1.2.3'
|
||||
link 'Caffeine.app'
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class InvalidGpgType < TestCask
|
||||
url TestHelper.local_binary('caffeine.zip')
|
||||
homepage 'http://example.com/invalid-gpg-type'
|
||||
gpg 'ID', :type => :no_such_type,
|
||||
:signature => 'http://example.com/gpg-signature.asc'
|
||||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
|
||||
version '1.2.3'
|
||||
link 'Caffeine.app'
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class WithGpg < TestCask
|
||||
url TestHelper.local_binary('caffeine.zip')
|
||||
homepage 'http://example.com/with-gpg'
|
||||
gpg 'ID', :type => :id,
|
||||
:signature => 'http://example.com/gpg-signature.asc'
|
||||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
|
||||
version '1.2.3'
|
||||
link 'Caffeine.app'
|
||||
end
|
Loading…
Reference in New Issue