-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5975 from rolandwalker/gpg_dsl_revise
Revise gpg stanza order and parameters
- Loading branch information
Showing
12 changed files
with
99 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,36 @@ | ||
class Cask::DSL::Gpg | ||
|
||
VALID_TYPES = Set.new [ | ||
:id, # first one is the default | ||
:url, | ||
] | ||
KEY_PARAMETERS = Set.new [ | ||
:key_id, | ||
:key_url, | ||
] | ||
|
||
REQUIRED_PARAMETERS = [ | ||
:signature | ||
] | ||
VALID_PARAMETERS = Set.new [ ] | ||
VALID_PARAMETERS.merge KEY_PARAMETERS | ||
|
||
attr_reader :key, :parameters, :type, :signature | ||
attr_accessor *VALID_PARAMETERS | ||
attr_accessor :signature | ||
|
||
def initialize(key, parameters={}) | ||
def initialize(signature, 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 | ||
@signature = Cask::UnderscoreSupportingURI.parse(signature) | ||
parameters.each do |hkey, hvalue| | ||
raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey) | ||
writer_method = "#{hkey}=".to_sym | ||
hvalue = Cask::UnderscoreSupportingURI.parse(hvalue) if hkey == :key_url | ||
send(writer_method, hvalue) | ||
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) | ||
unless KEY_PARAMETERS.intersection(parameters.keys).length == 1 | ||
raise "'gpg' stanza must include exactly one of: '#{KEY_PARAMETERS.to_a}'" | ||
end | ||
end | ||
|
||
def to_yaml | ||
[@key, @parameters].to_yaml | ||
# bug, :key_url value is not represented as an instance of Cask::UnderscoreSupportingURI | ||
[@signature, @parameters].to_yaml | ||
end | ||
|
||
def to_s | ||
@key.to_s | ||
@signature.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/support/Casks/invalid/invalid-gpg-conflicting-keys.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class InvalidGpgConflictingKeys < TestCask | ||
url TestHelper.local_binary('caffeine.zip') | ||
homepage 'http://example.com/invalid-gpg-conflicting-keys' | ||
gpg 'http://example.com/gpg-signature.asc', | ||
:key_id => 'ID', | ||
:key_url => 'http://example.com/gpg-key-url' | ||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' | ||
version '1.2.3' | ||
link 'Caffeine.app' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class InvalidGpgMissingKeys < TestCask | ||
url TestHelper.local_binary('caffeine.zip') | ||
homepage 'http://example.com/invalid-gpg-missing-keys' | ||
gpg 'http://example.com/gpg-signature.asc' | ||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' | ||
version '1.2.3' | ||
link 'Caffeine.app' | ||
end |
11 changes: 11 additions & 0 deletions
11
test/support/Casks/invalid/invalid-gpg-multiple-stanzas.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class InvalidGpgMultipleStanzas < TestCask | ||
url TestHelper.local_binary('caffeine.zip') | ||
homepage 'http://example.com/invalid-gpg-multiple-stanzas' | ||
gpg 'http://example.com/gpg-signature.asc', | ||
:key_id => 'ID' | ||
gpg 'http://example.com/gpg-signature.asc', | ||
:key_id => 'ID' | ||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' | ||
version '1.2.3' | ||
link 'Caffeine.app' | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class InvalidGpgParameter < TestCask | ||
url TestHelper.local_binary('caffeine.zip') | ||
homepage 'http://example.com/invalid-gpg-type' | ||
gpg 'http://example.com/gpg-signature.asc', | ||
:no_such_parameter => :value | ||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' | ||
version '1.2.3' | ||
link 'Caffeine.app' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class WithGpgKeyUrl < TestCask | ||
url TestHelper.local_binary('caffeine.zip') | ||
homepage 'http://example.com/with-gpg-key-url' | ||
gpg 'http://example.com/gpg-signature.asc', | ||
:key_url => 'http://example.com/gpg-key-url' | ||
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' | ||
version '1.2.3' | ||
link 'Caffeine.app' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters