From 93b358f91269fc81ed00e2c31d75b4eb3858aaf5 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Thu, 22 Jul 2021 13:36:05 -0700 Subject: [PATCH] fix cast error in codesign sub-command (#86890) --- dev/conductor/lib/codesign.dart | 12 +++- dev/conductor/test/codesign_test.dart | 85 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/dev/conductor/lib/codesign.dart b/dev/conductor/lib/codesign.dart index 2f05e1450d..057e902042 100644 --- a/dev/conductor/lib/codesign.dart +++ b/dev/conductor/lib/codesign.dart @@ -316,9 +316,15 @@ class CodesignCommand extends Command { 'Test failed because unexpected binaries found in the cache.'); } - stdio.printStatus( - 'Verified that binaries for commit ${argResults![kRevision] as String} are codesigned and have ' - 'expected entitlements.'); + final String? desiredRevision = argResults![kRevision] as String?; + if (desiredRevision == null) { + stdio.printStatus( + 'Verified that binaries are codesigned and have expected entitlements.'); + } else { + stdio.printStatus( + 'Verified that binaries for commit $desiredRevision are codesigned and have ' + 'expected entitlements.'); + } } List? _allBinaryPaths; diff --git a/dev/conductor/test/codesign_test.dart b/dev/conductor/test/codesign_test.dart index e0348874a6..91b4b0d6b2 100644 --- a/dev/conductor/test/codesign_test.dart +++ b/dev/conductor/test/codesign_test.dart @@ -81,6 +81,90 @@ void main() { ); }); + test('does not fail if --revision flag not provided', () async { + final List codesignCheckCommands = []; + for (final String bin in binariesWithEntitlements) { + codesignCheckCommands.add( + FakeCommand( + command: ['codesign', '-vvv', bin], + ), + ); + codesignCheckCommands.add( + FakeCommand( + command: ['codesign', '--display', '--entitlements', ':-', bin], + stdout: expectedEntitlements.join('\n'), + ), + ); + } + for (final String bin in binariesWithoutEntitlements) { + codesignCheckCommands.add( + FakeCommand( + command: ['codesign', '-vvv', bin], + ), + ); + } + createRunner(commands: [ + const FakeCommand(command: [ + 'git', + 'clone', + '--origin', + 'upstream', + '--', + 'file://$flutterRoot/', + '${checkoutsParentDirectory}flutter_conductor_checkouts/framework', + ]), + const FakeCommand(command: [ + 'git', + 'rev-parse', + 'HEAD', + ], stdout: revision), + const FakeCommand(command: [ + 'git', + 'rev-parse', + 'HEAD', + ], stdout: revision), + const FakeCommand(command: [ + 'git', + 'checkout', + revision, + ]), + const FakeCommand(command: [ + flutterBin, + 'help', + ]), + const FakeCommand(command: [ + flutterBin, + 'help', + ]), + const FakeCommand(command: [ + flutterBin, + 'precache', + '--android', + '--ios', + '--macos', + ]), + FakeCommand( + command: const [ + 'find', + '${checkoutsParentDirectory}flutter_conductor_checkouts/framework/bin/cache', + '-type', + 'f', + ], + stdout: allBinaries.join('\n'), + ), + for (String bin in allBinaries) + FakeCommand( + command: ['file', '--mime-type', '-b', bin], + stdout: 'application/x-mach-binary', + ), + ...codesignCheckCommands, + ]); + await runner.run(['codesign', '--$kVerify']); + expect(processManager.hasRemainingExpectations, false); + expect(stdio.stdout, contains('Verified that binaries are codesigned and have expected entitlements')); + }); + + test('succeeds if every binary is codesigned and has correct entitlements', () async { final List codesignCheckCommands = []; for (final String bin in binariesWithEntitlements) { @@ -156,6 +240,7 @@ void main() { ]); await runner.run(['codesign', '--$kVerify', '--$kRevision', revision]); expect(processManager.hasRemainingExpectations, false); + expect(stdio.stdout, contains('Verified that binaries for commit $revision are codesigned and have expected entitlements')); }); test('fails if a single binary is not codesigned', () async {