@@ -639,6 +639,16 @@ class _SmokeFiles {
639639 Map <String , dynamic > get evidence => records[1 ]['details' ];
640640 Map <String , dynamic > get settings => report['metadata' ]['settings' ];
641641
642+ Future <void > changeLaunchJson (
643+ String name,
644+ void Function (Map <String , dynamic >) change,
645+ ) async {
646+ final file = File (p.join (root.path, 'launch-000' , name));
647+ final value = jsonDecode (await file.readAsString ()) as Map <String , dynamic >;
648+ change (value);
649+ await file.writeAsString (jsonEncode (value));
650+ }
651+
642652 Future <void > save ({bool synchronizeReceipt = true }) async {
643653 await File (p.join (root.path, 'manifest.json' ))
644654 .writeAsString (jsonEncode (manifest));
@@ -748,12 +758,47 @@ Future<_SmokeFiles> _smoke({
748758 'buildMode' : mode,
749759 'engineRevision' : '2' * 40 ,
750760 'bundleSha256' : _hash,
751- 'verification' :
752- mode == 'release' ? 'patched-action-sha256' : 'bundle-sha256' ,
761+ 'verification' : mode == 'release'
762+ ? 'patched-action-sha256'
763+ : 'bundle-sha256' ,
753764 if (mode == 'release' ) 'expectedSha256' : _hash,
754765 };
755766 manifest['engineIdentity' ] = engine;
756767 settings['engineBinary' ] = engine;
768+ } else {
769+ final binaryName = platform == 'linux'
770+ ? 'libflutter_linux_gtk.so'
771+ : 'FlutterMacOS' ;
772+ final engine = {
773+ 'schemaVersion' : 1 ,
774+ 'platform' : platform,
775+ 'buildMode' : mode,
776+ 'binaryName' : binaryName,
777+ 'bytes' : 1024 ,
778+ 'bundleSha256' : _hash,
779+ };
780+ final enginePath = platform == 'linux'
781+ ? '/bundle/lib/$binaryName '
782+ : '/bundle/Contents/Frameworks/FlutterMacOS.framework/Versions/A/$binaryName ' ;
783+ manifest['engineIdentity' ] = engine;
784+ manifest['engineEvidence' ] = {
785+ 'canonicalPath' : enginePath,
786+ 'verifiedAfterRuns' : true ,
787+ };
788+ await File (p.join (root.path, 'launch-000' , 'engine.json' )).writeAsString (
789+ jsonEncode ({
790+ 'source' : platform == 'linux'
791+ ? '/proc/123/maps'
792+ : 'lsof -a -p <owned PID> -d txt -Fpcfn0' ,
793+ 'pid' : 123 ,
794+ 'canonicalPath' : enginePath,
795+ 'identity' : engine,
796+ 'observedAfterCompletion' : true ,
797+ 'rawObservation' : platform == 'linux'
798+ ? '1000-2000 r-xp 0 08:01 123 $enginePath \n '
799+ : 'p123\u 0000\n cotzaria\u 0000\n ftxt\u 0000n$enginePath \u 0000\n ' ,
800+ }),
801+ );
757802 }
758803 final report = < String , dynamic > {
759804 'complete' : true ,
@@ -818,7 +863,16 @@ Future<_SmokeFiles> _smoke({
818863 },
819864 ];
820865 await File (p.join (root.path, 'launch-000' , 'launch.json' )).writeAsString (
821- jsonEncode ({'launchIndex' : 0 , 'pid' : 123 , 'identityStartTicks' : '1234' }),
866+ jsonEncode ({
867+ 'launchIndex' : 0 ,
868+ 'pid' : 123 ,
869+ 'identityStartTicks' : '1234' ,
870+ if (platform != 'windows' ) ...{
871+ 'preparationOnly' : false ,
872+ 'completedBeforeTermination' : true ,
873+ 'engineVerifiedAfterCompletion' : true ,
874+ },
875+ }),
822876 );
823877 await File (p.join (root.path, 'launch-000' , 'completion.json' )).writeAsString (
824878 jsonEncode ({
@@ -844,20 +898,157 @@ void _smokeTests() {
844898 await expectLater (files.validate (), throwsFormatException);
845899 });
846900
847- test ('accepts all desktop profiles and the verified Windows release' , () async {
848- for (final platform in ['linux' , 'macos' , 'windows' ]) {
849- final files = await _smoke (platform: platform);
850- expect ((await files.validate ())['status' ], 'passed' );
901+ test (
902+ 'accepts all desktop profiles and the verified Windows release' ,
903+ () async {
904+ for (final platform in ['linux' , 'macos' , 'windows' ]) {
905+ final files = await _smoke (platform: platform);
906+ final result = await files.validate ();
907+ expect (result['status' ], 'passed' );
908+ expect (result['engineIdentity' ], files.manifest['engineIdentity' ]);
909+ }
910+ final release = await _smoke (platform: 'windows' , mode: 'release' );
911+ final result = await release.validate ();
912+ expect (result['buildMode' ], 'release' );
913+ expect (
914+ (result['engineIdentity' ] as Map )['verification' ],
915+ 'patched-action-sha256' ,
916+ );
917+ },
918+ );
919+
920+ test (
921+ 'POSIX rejects missing, foreign or malformed engine identities' ,
922+ () async {
923+ for (final platform in ['linux' , 'macos' ]) {
924+ for (final invalid in < MapEntry <String , Object ?>> [
925+ const MapEntry ('schemaVersion' , 1.0 ),
926+ const MapEntry ('platform' , 'windows' ),
927+ const MapEntry ('buildMode' , 'release' ),
928+ const MapEntry ('binaryName' , 'flutter_windows.dll' ),
929+ const MapEntry ('bytes' , 0 ),
930+ const MapEntry ('bytes' , - 1 ),
931+ const MapEntry ('bytes' , 1024.0 ),
932+ MapEntry ('bundleSha256' , 'A' * 64 ),
933+ MapEntry ('bundleSha256' , 'a' * 63 ),
934+ const MapEntry ('verification' , 'bundle-sha256' ),
935+ ]) {
936+ final files = await _smoke (platform: platform);
937+ final identity = files.manifest['engineIdentity' ] as Map ;
938+ identity[invalid.key] = invalid.value;
939+ await files.changeLaunchJson ('engine.json' , (proof) {
940+ proof['identity' ] = identity;
941+ });
942+ await files.save ();
943+ await expectLater (files.validate (), throwsFormatException);
944+ }
945+ final missing = await _smoke (platform: platform);
946+ missing.manifest.remove ('engineIdentity' );
947+ missing.report['metadata' ].remove ('engineIdentity' );
948+ await missing.save ();
949+ await expectLater (missing.validate (), throwsFormatException);
950+ }
951+ },
952+ );
953+
954+ test ('POSIX engine identity and evidence must match the report' , () async {
955+ for (final field in ['engineIdentity' , 'engineEvidence' ]) {
956+ final files = await _smoke ();
957+ files.report['metadata' ][field] = < String , Object ? > {};
958+ await files.save ();
959+ await expectLater (files.validate (), throwsFormatException);
851960 }
852- final release = await _smoke (platform: 'windows' , mode: 'release' );
853- final result = await release.validate ();
854- expect (result['buildMode' ], 'release' );
855- expect (
856- (result['engineIdentity' ] as Map )['verification' ],
857- 'patched-action-sha256' ,
858- );
961+ final windows = await _smoke ();
962+ windows.settings['engineBinary' ] = windows.manifest['engineIdentity' ];
963+ await windows.save ();
964+ await expectLater (windows.validate (), throwsFormatException);
859965 });
860966
967+ test (
968+ 'POSIX requires the verified absolute path and completed launch' ,
969+ () async {
970+ for (final platform in ['linux' , 'macos' ]) {
971+ for (final invalid in [null , false ]) {
972+ final files = await _smoke (platform: platform);
973+ final evidence = files.manifest['engineEvidence' ] as Map ;
974+ if (invalid == null ) {
975+ evidence.remove ('verifiedAfterRuns' );
976+ } else {
977+ evidence['verifiedAfterRuns' ] = invalid;
978+ }
979+ await files.save ();
980+ await expectLater (files.validate (), throwsFormatException);
981+ }
982+ for (final path in [
983+ 'lib/FlutterMacOS' ,
984+ r'C:\bundle\FlutterMacOS' ,
985+ '/bundle/foreign' ,
986+ ]) {
987+ final files = await _smoke (platform: platform);
988+ files.manifest['engineEvidence' ]['canonicalPath' ] = path;
989+ await files.changeLaunchJson ('engine.json' , (proof) {
990+ proof['canonicalPath' ] = path;
991+ });
992+ await files.save ();
993+ await expectLater (files.validate (), throwsFormatException);
994+ }
995+ for (final field in [
996+ 'preparationOnly' ,
997+ 'completedBeforeTermination' ,
998+ 'engineVerifiedAfterCompletion' ,
999+ ]) {
1000+ for (final missing in [false , true ]) {
1001+ final files = await _smoke (platform: platform);
1002+ await files.changeLaunchJson ('launch.json' , (launch) {
1003+ if (missing) {
1004+ launch.remove (field);
1005+ } else {
1006+ launch[field] = field == 'preparationOnly' ;
1007+ }
1008+ });
1009+ await expectLater (files.validate (), throwsFormatException);
1010+ }
1011+ }
1012+ }
1013+ },
1014+ );
1015+
1016+ test (
1017+ 'POSIX requires mapped engine proof for the same owned process' ,
1018+ () async {
1019+ for (final platform in ['linux' , 'macos' ]) {
1020+ for (final invalid in < MapEntry <String , Object ?>> [
1021+ const MapEntry ('pid' , 0 ),
1022+ const MapEntry ('pid' , 456 ),
1023+ const MapEntry ('pid' , 123.0 ),
1024+ const MapEntry ('source' , '/proc/456/maps' ),
1025+ const MapEntry ('canonicalPath' , '/foreign/FlutterMacOS' ),
1026+ const MapEntry ('observedAfterCompletion' , false ),
1027+ const MapEntry ('identity' , < String , Object ? > {}),
1028+ const MapEntry ('rawObservation' , '' ),
1029+ const MapEntry ('rawObservation' , ' \n ' ),
1030+ ]) {
1031+ for (final missing in [false , true ]) {
1032+ final files = await _smoke (platform: platform);
1033+ await files.changeLaunchJson ('engine.json' , (proof) {
1034+ if (missing) {
1035+ proof.remove (invalid.key);
1036+ } else {
1037+ proof[invalid.key] = invalid.value;
1038+ }
1039+ });
1040+ await expectLater (files.validate (), throwsFormatException);
1041+ }
1042+ }
1043+ final absent = await _smoke (platform: platform);
1044+ await File (
1045+ p.join (absent.root.path, 'launch-000' , 'engine.json' ),
1046+ ).delete ();
1047+ await expectLater (absent.validate (), throwsFormatException);
1048+ }
1049+ },
1050+ );
1051+
8611052 test ('dirty or missing source evidence never becomes a verified run' , () async {
8621053 for (final stage in ['beforeBuild' , 'afterBuild' , 'afterRuns' ]) {
8631054 for (final field in ['statusPorcelain' , 'trackedDiffSummary' ]) {
0 commit comments