Skip to content

Commit

Permalink
Merge pull request #4257 from rolandwalker/convert_no_checksum_1
Browse files Browse the repository at this point in the history
transition docs/tests/messages to sha256 :no_check
  • Loading branch information
rolandwalker committed May 8, 2014
2 parents f002e39 + c436ddc commit 635cd7c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Fill in the following stanzas for your Cask:
| `url` | URL to the `.dmg`/`.zip`/`.tgz` file that contains the application (see also [URL Stanza Details](doc/CASK_LANGUAGE_REFERENCE.md#url-stanza-details))
| `homepage` | application homepage; used for the `brew cask home` command
| `version` | application version; give value of `'latest'` if versioned downloads are not offered
| `sha256` | SHA-256 checksum of the file downloaded from `url`, calculated by the command `shasum -a 256 <file>`. Can be omitted on unversioned downloads by substituting `no_checksum`. (see also [Checksum Stanza Details](doc/CASK_LANGUAGE_REFERENCE.md#checksum-stanza-details))
| `sha256` | SHA-256 checksum of the file downloaded from `url`, calculated by the command `shasum -a 256 <file>`. Can be suppressed for unversioned downloads by using the special value `:no_check`. (see also [Checksum Stanza Details](doc/CASK_LANGUAGE_REFERENCE.md#checksum-stanza-details))
| __artifact info__ | information about artifacts inside the Cask (can be specified multiple times)
| `link` | relative path to a file that should be linked into the `Applications` folder on installation (see also [Link Stanza Details](doc/CASK_LANGUAGE_REFERENCE.md#link-stanza-details))
| `install` | relative path to `pkg` that should be run to install the application (see also [Install Stanza Details](doc/CASK_LANGUAGE_REFERENCE.md#install-stanza-details))
Expand Down
8 changes: 3 additions & 5 deletions doc/CASK_LANGUAGE_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ paradigm.

Each of the following stanzas is required for every Cask.

Exception: currently `sha256` may be omitted if `no_checksum` is substituted.

| name | multiple occurrences allowed? | value |
| ------------------ |------------------------------ | ----------- |
| `url` | No | URL to the `.dmg`/`.zip`/`.tgz` file that contains the application (see also [URL Stanza Details](#url-stanza-details))
| `homepage` | No | application homepage; used for the `brew cask home` command
| `version` | No | application version; give value of `'latest'` if versioned downloads are not offered
| `sha256` | No | SHA-256 checksum of the file downloaded from `url`, calculated by the command `shasum -a 256 <file>`. Can be omitted on unversioned downloads by substituting `no_checksum`. (see also [Checksum Stanza Details](#checksum-stanza-details))
| `sha256` | No | SHA-256 checksum of the file downloaded from `url`, calculated by the command `shasum -a 256 <file>`. Can be suppressed for unversioned downloads by using the special value `:no_check`. (see also [Checksum Stanza Details](#checksum-stanza-details))


## At Least One Artifact Stanza Is Also Required
Expand Down Expand Up @@ -102,8 +100,8 @@ and slated for retirement.

| name | multiple occurrences allowed? | meaning |
| ------------------ |------------------------------ | ----------- |
| `md5` | No | an alternative to `sha256`
| `sha1` | No | an alternative to `sha256`
| `sha1` | No | an obsolete alternative to `sha256`
| `no_checksum` | No | an obsolete alternative to `sha256 :no_check`


## Conditional Statements
Expand Down
10 changes: 5 additions & 5 deletions lib/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(cask)
def run!(download = false)
_check_required_fields
_check_checksums
_check_no_checksums_if_latest
_check_sha256_no_check_if_latest
_check_sourceforge_download_url_format
_check_download(download) if download
return !(errors? or warnings?)
Expand All @@ -34,12 +34,12 @@ def _check_required_fields
def _check_checksums
odebug "Auditing checksums"
return if cask.sums == :no_check
add_error "could not find checksum or no_checksum" unless cask.sums.is_a?(Array) && cask.sums.length > 0
add_error "sha256 is required" unless cask.sums.is_a?(Array) && cask.sums.length > 0
end

def _check_no_checksums_if_latest
odebug "Verifying no_checkum with version 'latest'"
add_error "you should use no_checksum when version is latest" if cask.version == "latest" && cask.sums.is_a?(Array)
def _check_sha256_no_check_if_latest
odebug "Verifying sha256 :no_check with version 'latest'"
add_error "you should use sha256 :no_check when version is 'latest'" if cask.version == "latest" && cask.sums.is_a?(Array)
end

def _check_download(download)
Expand Down
3 changes: 3 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def hash_name(hash_type)
hash_type.to_s == 'sha2' ? 'sha256' : hash_type.to_s
end

# @@@ todo remove support for sha1 stanza
def sha1(sha1=nil)
if @sums == :no_check
raise CaskInvalidError.new(self.title, "'no_checksum' stanza conflicts with 'sha1'")
Expand All @@ -152,6 +153,7 @@ def sha1(sha1=nil)
end

def sha256(sha2=nil)
# @@@ todo remove this after deleting support for legacy no_checksum stanza
if @sums == :no_check
raise CaskInvalidError.new(self.title, "'no_checksum' stanza conflicts with 'sha256'")
end
Expand All @@ -163,6 +165,7 @@ def sha256(sha2=nil)
end
end

# @@@ todo remove support for no_checksum stanza
def no_checksum
unless @sums.nil? or @sums.empty?
raise CaskInvalidError.new(self.title, "'no_checksum' stanza conflicts with '#{hash_name(@sums.first.hash_type)}'")
Expand Down
2 changes: 1 addition & 1 deletion test/cask/audit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CaskVersionLatestWithChecksum < Cask
it "adds an error if version is latest and using sha256" do
audit = Cask::Audit.new(CaskVersionLatestWithChecksum.new)
audit.run!
audit.errors.must_include 'you should use no_checksum when version is latest'
audit.errors.must_include %q{you should use sha256 :no_check when version is 'latest'}
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ def caveats; <<-EOS.undent
err.message.must_include "'version' stanza may only appear once"
end

# @@@ todo this test can be removed when support for no_checksum is dropped
it "prevents defining conflicting checksums (first order)" do
err = lambda {
invalid_cask = Cask.load('invalid/invalid-checksum-conflict1')
}.must_raise(CaskInvalidError)
err.message.must_include "'no_checksum' stanza conflicts with"
end

# @@@ todo this test can be removed when support for no_checksum is dropped
it "prevents defining conflicting checksums (second order)" do
err = lambda {
invalid_cask = Cask.load('invalid/invalid-checksum-conflict2')
Expand Down
1 change: 1 addition & 0 deletions test/support/Casks/invalid/invalid-checksum-conflict1.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class InvalidChecksumConflict1 < TestCask
# @@@ todo this test cask can be removed when support for no_checksum is dropped
url TestHelper.local_binary('caffeine.zip')
homepage 'http://example.com/local-caffeine'
version '1.2.3'
Expand Down
1 change: 1 addition & 0 deletions test/support/Casks/invalid/invalid-checksum-conflict2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class InvalidChecksumConflict2 < TestCask
# @@@ todo this test cask can be removed when support for no_checksum is dropped
url TestHelper.local_binary('caffeine.zip')
homepage 'http://example.com/local-caffeine'
version '1.2.3'
Expand Down

0 comments on commit 635cd7c

Please sign in to comment.