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

Cask: complete Git-Jiro's HTTPS audit check #5033

Merged
merged 9 commits into from
Nov 24, 2018
16 changes: 16 additions & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "cask/checkable"
require "cask/download"
require "digest"
require "utils/curl"
require "utils/git"

module Cask
Expand Down Expand Up @@ -30,6 +31,7 @@ def run!
check_generic_artifacts
check_token_conflicts
check_download
check_https_availability
check_single_pre_postflight
check_single_uninstall_zap
check_untrusted_pkg
Expand Down Expand Up @@ -317,5 +319,19 @@ def check_download
rescue => e
add_error "download not possible: #{e.message}"
end

def check_https_availability
return unless download
if !cask.url.blank? && !cask.url.using
check_url_for_https_availability(cask.url, user_agents: [cask.url.user_agent])
end
check_url_for_https_availability(cask.appcast) unless cask.appcast.blank?
check_url_for_https_availability(cask.homepage) unless cask.homepage.blank?
end

def check_url_for_https_availability(url_to_check, user_agents: [:default])
problem = curl_check_http_content(url_to_check.to_s, user_agents: user_agents)
add_error problem if problem
end
end
end
6 changes: 3 additions & 3 deletions Library/Homebrew/test/cask/cmd/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
it_behaves_like "a command that handles invalid options"

it "opens the homepage for the specified Cask" do
expect(described_class).to receive(:open_url).with("https://example.com/local-caffeine")
expect(described_class).to receive(:open_url).with("https://example.com")
described_class.run("local-caffeine")
end

it "works for multiple Casks" do
expect(described_class).to receive(:open_url).with("https://example.com/local-caffeine")
expect(described_class).to receive(:open_url).with("https://example.com/local-transmission")
expect(described_class).to receive(:open_url).with("https://example.com")
expect(described_class).to receive(:open_url).with("https://example.com")
described_class.run("local-caffeine", "local-transmission")
end

Expand Down
14 changes: 7 additions & 7 deletions Library/Homebrew/test/cask/cmd/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
described_class.run("local-caffeine")
}.to output(<<~EOS).to_stdout
local-caffeine: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name
Expand Down Expand Up @@ -39,15 +39,15 @@
let(:expected_output) {
<<~EOS
local-caffeine: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name
None
==> Artifacts
Caffeine.app (App)
local-transmission: 2.61
https://example.com/local-transmission
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-transmission.rb
==> Name
Expand All @@ -69,7 +69,7 @@
described_class.run("with-caveats")
}.to output(<<~EOS).to_stdout
with-caveats: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-caveats.rb
==> Name
Expand All @@ -95,7 +95,7 @@
described_class.run("with-conditional-caveats")
}.to output(<<~EOS).to_stdout
with-conditional-caveats: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-conditional-caveats.rb
==> Name
Expand All @@ -110,7 +110,7 @@
described_class.run("with-languages")
}.to output(<<~EOS).to_stdout
with-languages: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-languages.rb
==> Name
Expand All @@ -127,7 +127,7 @@
described_class.run("without-languages")
}.to output(<<~EOS).to_stdout
without-languages: 1.2.3
https://example.com/local-caffeine
https://example.com
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/without-languages.rb
==> Name
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cask/cmd/internal_stanza_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
command = described_class.new("homepage", "local-caffeine")
expect {
command.run
}.to output("https://example.com/local-caffeine\n").to_stdout
}.to output("https://example.com\n").to_stdout
end

it "raises an exception when stanza is unknown/unsupported" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

installer manual: 'Caffeine.app'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'
homepage 'https://www.example.com/local-caffeine'

app 'Caffeine.app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
url 'https://example.com/caffeine.zip'
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://example.com/local-transmission'
homepage 'https://example.com'

app 'Transmission.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version '1.2.3'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://example.com/local-transmission'
homepage 'https://example.com'

app 'Transmission.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine Mini.app'
app 'Caffeine Pro.app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine Mini.app'
app 'Caffeine Pro.app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://example.com/local-transmission'
homepage 'https://example.com'

app 'container'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app', target: 'AnotherName.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

installer manual: 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '3178fbfd1ea5d87a2a0662a4eb599ebc9a03888e73f37538d9f3f6ee69d2368e'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine Mini.app'
app 'Caffeine Pro.app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 'd687c22a21c02bd8f07da9302c8292b93a04df9a929e3f04d09aea6c76f75c65'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines-subdir.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeines/Caffeine Mini.app'
app 'Caffeines/Caffeine Pro.app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/local-caffeine'
homepage 'https://example.com'

app 'Caffeine.app'
end