Skip to content

Commit

Permalink
Fix cask source checksum handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Mar 19, 2024
1 parent e3797d3 commit d2e1af8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def ruby_source_path
@ruby_source_path = sourcefile_path.relative_path_from(tap.path)
end

sig { returns(T::Hash[Symbol, String]) }
def ruby_source_checksum
@ruby_source_checksum ||= {
sha256: Digest::SHA256.file(sourcefile_path).hexdigest,
Expand All @@ -300,7 +301,7 @@ def populate_from_api!(json_cask)
# TODO: Clean this up when we deprecate the current JSON API and move to the internal JSON v3.
ruby_source_sha256 = json_cask.dig(:ruby_source_checksum, :sha256)
ruby_source_sha256 ||= json_cask[:ruby_source_sha256]
@ruby_source_checksum = { "sha256" => ruby_source_sha256 }
@ruby_source_checksum = { sha256: ruby_source_sha256 }

Check warning on line 304 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L304

Added line #L304 was not covered by tests
end

def to_s
Expand Down
26 changes: 26 additions & 0 deletions Library/Homebrew/test/api/cask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,30 @@ def mock_curl_download(stdout:)
expect(casks_output).to eq casks_hash
end
end

describe "::source_download", :needs_macos do
let(:cask) do
cask = Cask::CaskLoader::FromAPILoader.new(
"everything",
from_json: JSON.parse((TEST_FIXTURE_DIR/"cask/everything.json").read.strip),
).load(config: nil)
cask
end

before do
allow_any_instance_of(Homebrew::API::Download).to receive(:fetch)
allow_any_instance_of(Homebrew::API::Download).to receive(:symlink_location).and_return(
TEST_FIXTURE_DIR/"cask/Casks/everything.rb",
)
end

it "specifies the correct URL and sha256" do
expect(Homebrew::API::Download).to receive(:new).with(
"https://raw.githubusercontent.com/Homebrew/homebrew-cask/abcdef1234567890abcdef1234567890abcdef12/Casks/everything.rb",
Checksum.new("d8d0d6b2e5ff65388eccb82236fd3aa157b4a29bb043a1f72b97f0e9b70e8320"),
any_args,
).and_call_original
described_class.source_download(cask)
end
end
end
6 changes: 5 additions & 1 deletion Library/Homebrew/test/cask/cask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@
it "returns expected hash" do
allow(MacOS).to receive(:version).and_return(MacOSVersion.new("13"))

hash = Cask::CaskLoader.load("everything").to_h
cask = Cask::CaskLoader.load("everything")

expect(cask.tap).to receive(:git_head).and_return("abcdef1234567890abcdef1234567890abcdef12")

hash = cask.to_h

expect(hash).to be_a(Hash)
expect(JSON.pretty_generate(hash)).to eq(expected_json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"disabled": false,
"disable_date": null,
"disable_reason": null,
"tap_git_head": null,
"tap_git_head": "abcdef1234567890abcdef1234567890abcdef12",
"languages": [
"en",
"eo"
Expand Down

0 comments on commit d2e1af8

Please sign in to comment.