Skip to content

Commit fd9fe78

Browse files
mokagioclaude
andcommitted
Verify app bundles through the signed? helper
Review feedback: two call sites each spelled out their own `codesign --verify` invocation, leaving the reader to work out how they differed. The helper now owns the command, and the difference lives at the call site instead: an unsigned disk image is tolerated, an unsigned app bundle is not. Failures on an app bundle now carry the `codesign` output in the error message, which the previous fixed string dropped. --- Generated with the help of Claude Code, https://claude.ai/code Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 679af96 commit fd9fe78

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.run(params)
2929
end
3030

3131
def self.verify_app_bundle(path:, expected_authority:, verify_notarization:)
32-
verify!("The code signature of #{path} is not valid", 'codesign', '--verify', '--deep', '--strict', '--verbose=2', path)
32+
UI.user_error!("#{path} is not signed at all") unless signed?(path, deep: true)
3333
verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil?
3434

3535
return unless verify_notarization
@@ -61,8 +61,14 @@ def self.verify_disk_image(path:, expected_authority:, verify_notarization:)
6161
# Distinguishes an artifact that carries no signature at all from one whose signature is
6262
# broken: the former is expected for a disk image, the latter always a failure.
6363
#
64-
def self.signed?(path)
65-
exitstatus, output = sh('codesign', '--verify', '--strict', '--verbose=2', path) { |status, result, _| [status.exitstatus, result] }
64+
# @param deep [Boolean] Whether to also verify the nested code an app bundle embeds.
65+
#
66+
def self.signed?(path, deep: false)
67+
command = ['codesign', '--verify']
68+
command << '--deep' if deep
69+
command += ['--strict', '--verbose=2', path]
70+
71+
exitstatus, output = sh(*command) { |status, result, _| [status.exitstatus, result] }
6672

6773
return true if exitstatus.zero?
6874
return false if output.include?('not signed at all')

spec/macos_verify_code_signing_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def with_artifacts(*names)
2121
end
2222
end
2323

24-
def expect_codesign_verify_deep(path, exitstatus: 0)
25-
expect_shell_command('codesign', '--verify', '--deep', '--strict', '--verbose=2', path, exitstatus: exitstatus)
24+
def expect_codesign_verify_deep(path, exitstatus: 0, output: '')
25+
expect_shell_command('codesign', '--verify', '--deep', '--strict', '--verbose=2', path, exitstatus: exitstatus, output: output)
2626
end
2727

2828
def expect_codesign_verify(path, exitstatus: 0, output: '')
@@ -93,13 +93,23 @@ def expect_stapler_validate(path, exitstatus: 0)
9393

9494
it 'fails when the signature is not valid' do
9595
with_artifacts('Test.app') do |(path)|
96-
expect_codesign_verify_deep(path, exitstatus: 1)
96+
expect_codesign_verify_deep(path, exitstatus: 1, output: "#{path}: invalid signature (code or signature have been modified)\n")
9797

9898
expect { run_described_fastlane_action(artifact_path: path) }
9999
.to raise_error(FastlaneCore::Interface::FastlaneError, /The code signature of .*Test\.app is not valid/)
100100
end
101101
end
102102

103+
# Unlike a disk image, an app bundle without a signature is always a failure.
104+
it 'fails when it is not signed at all' do
105+
with_artifacts('Test.app') do |(path)|
106+
expect_codesign_verify_deep(path, exitstatus: 1, output: "#{path}: code object is not signed at all\n")
107+
108+
expect { run_described_fastlane_action(artifact_path: path) }
109+
.to raise_error(FastlaneCore::Interface::FastlaneError, /Test\.app is not signed at all/)
110+
end
111+
end
112+
103113
it 'fails when Gatekeeper rejects it' do
104114
with_artifacts('Test.app') do |(path)|
105115
expect_codesign_verify_deep(path)

0 commit comments

Comments
 (0)