Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce a valid minimum DSL version in headers #7530

Merged
merged 1 commit into from
Nov 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/cask/source/path_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ def load
# munge text
cask_string.sub!(%r{\A(\s*\#[^\n]*\n)+}, '');
if %r{\A\s*cask\s+:v([\d_]+)(test)?\s+=>\s+([\'\"])(\S+?)\3(?:\s*,\s*|\s+)do\s*\n}.match(cask_string)
dsl_version = $1
dsl_version_string = $1
test_cask = ! $2.nil?
header_name = $4
dsl_version = Gem::Version.new(dsl_version_string.gsub('_','.'))
superclass_name = test_cask ? 'TestCask' : 'Cask'
cask_string.sub!(%r{\A[^\n]+\n}, "class #{cask_class_name} < #{superclass_name}\n")
# todo enforce valid DSL version
# todo the minimum DSL version should be defined globally elsewhere
minimum_dsl_version = Gem::Version.new('1.0')
unless dsl_version >= minimum_dsl_version
raise CaskInvalidError.new(cask_name, "Bad header line: 'v#{dsl_version_string}' is less than required minimum version '#{minimum_dsl_version}'")
end
if header_name != cask_name
raise CaskInvalidError.new(cask_name, "Bad header line: '#{header_name}' does not match file name")
end
Expand Down
10 changes: 10 additions & 0 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
end
end

describe "header line" do
it "requires a valid minimum DSL version in the header" do
err = lambda {
invalid_cask = Cask.load('invalid/invalid-header-version')
}.must_raise(CaskInvalidError)
err.message.must_include 'Bad header line'
err.message.must_include 'is less than required minimum version'
end
end

describe "sha256 stanza" do
it "lets you set checksum via sha256" do
ChecksumCask = Class.new(Cask)
Expand Down
9 changes: 9 additions & 0 deletions test/support/Casks/invalid/invalid-header-version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cask :v0_9test => 'invalid-header-version' do
version '1.2.3'
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'

url TestHelper.local_binary_url('caffeine.zip')
homepage 'http://example.com/local-caffeine'

app 'Caffeine.app'
end