@@ -1129,4 +1129,101 @@ Boot0003* test";
11291129
11301130 Ok ( ( ) )
11311131 }
1132+
1133+ #[ test]
1134+ fn test_package_mode_shim_installation ( ) -> Result < ( ) > {
1135+ // Test that shim can be installed from /usr/lib/efi to ESP
1136+ let tmpdir: & tempfile:: TempDir = & tempfile:: tempdir ( ) ?;
1137+ let tpath = tmpdir. path ( ) ;
1138+
1139+ // Create mock /usr/lib/efi structure with shim
1140+ let efi_path = tpath. join ( "usr/lib/efi" ) ;
1141+ let shim_path = efi_path. join ( "shim/15.8-3/EFI/fedora" ) ;
1142+ std:: fs:: create_dir_all ( & shim_path) ?;
1143+
1144+ // Write shim binary
1145+ let shim_content = b"mock shim binary content" ;
1146+ std:: fs:: write ( shim_path. join ( SHIM ) , shim_content) ?;
1147+
1148+ // Create additional shim files that might be present
1149+ std:: fs:: write ( shim_path. join ( "MokManager.efi" ) , b"mok manager content" ) ?;
1150+ std:: fs:: write ( shim_path. join ( "fbx64.efi" ) , b"fallback content" ) ?;
1151+
1152+ // Create mock ESP directory structure (simulating /boot/efi in container)
1153+ let esp_path = tpath. join ( "boot/efi" ) ;
1154+ std:: fs:: create_dir_all ( & esp_path) ?;
1155+
1156+ // Create EFI directory in ESP
1157+ let esp_efi_path = esp_path. join ( "EFI" ) ;
1158+ std:: fs:: create_dir_all ( & esp_efi_path) ?;
1159+
1160+ // Set up sysroot directory
1161+ let sysroot_dir = openat:: Dir :: open ( tpath) ?;
1162+
1163+ // Get EFI components from usr/lib/efi
1164+ let utf8_tpath =
1165+ Utf8Path :: from_path ( tpath) . ok_or_else ( || anyhow:: anyhow!( "Path is not valid UTF-8" ) ) ?;
1166+ let efi_comps = get_efi_component_from_usr ( utf8_tpath, EFILIB ) ?;
1167+ assert ! ( efi_comps. is_some( ) , "Should find shim component" ) ;
1168+ let efi_comps = efi_comps. unwrap ( ) ;
1169+ assert_eq ! ( efi_comps. len( ) , 1 , "Should find exactly one component" ) ;
1170+ assert_eq ! ( efi_comps[ 0 ] . name, "shim" ) ;
1171+ assert_eq ! ( efi_comps[ 0 ] . version, "15.8-3" ) ;
1172+
1173+ // Create Efi instance and copy components to ESP
1174+ let efi = Efi :: default ( ) ;
1175+ efi. copy_efi_components_to_esp ( & sysroot_dir, & esp_path, & efi_comps) ?;
1176+
1177+ // Expected path: /boot/efi/EFI/fedora/shimx64.efi (or shimaa64.efi, etc.)
1178+ let copied_shim_path = esp_path. join ( "EFI/fedora" ) . join ( SHIM ) ;
1179+ assert ! (
1180+ copied_shim_path. exists( ) ,
1181+ "Shim should be copied to ESP at {}" ,
1182+ copied_shim_path. display( )
1183+ ) ;
1184+
1185+ // Verify the shim file is actually a file, not a directory
1186+ assert ! (
1187+ copied_shim_path. is_file( ) ,
1188+ "Shim should be a file at {}" ,
1189+ copied_shim_path. display( )
1190+ ) ;
1191+
1192+ // Verify the content matches exactly
1193+ let copied_content = std:: fs:: read ( & copied_shim_path) ?;
1194+ assert_eq ! ( copied_content, shim_content, "Shim content should match exactly" ) ;
1195+
1196+ // Verify the directory structure is correct
1197+ assert ! (
1198+ esp_path. join( "EFI" ) . exists( ) ,
1199+ "EFI directory should exist in ESP at {}" ,
1200+ esp_path. join( "EFI" ) . display( )
1201+ ) ;
1202+ assert ! (
1203+ esp_path. join( "EFI" ) . is_dir( ) ,
1204+ "EFI should be a directory"
1205+ ) ;
1206+
1207+ assert ! (
1208+ esp_path. join( "EFI/fedora" ) . exists( ) ,
1209+ "Vendor directory (fedora) should exist in ESP at {}" ,
1210+ esp_path. join( "EFI/fedora" ) . display( )
1211+ ) ;
1212+ assert ! (
1213+ esp_path. join( "EFI/fedora" ) . is_dir( ) ,
1214+ "EFI/fedora should be a directory"
1215+ ) ;
1216+
1217+ // Verify the path structure matches expected package mode layout
1218+ // Source: /usr/lib/efi/shim/15.8-3/EFI/fedora/shimx64.efi
1219+ // Dest: /boot/efi/EFI/fedora/shimx64.efi
1220+ let expected_base = esp_path. join ( "EFI/fedora" ) ;
1221+ assert_eq ! (
1222+ copied_shim_path. parent( ) ,
1223+ Some ( expected_base. as_path( ) ) ,
1224+ "Shim should be directly under EFI/fedora/, not in a subdirectory"
1225+ ) ;
1226+
1227+ Ok ( ( ) )
1228+ }
11321229}
0 commit comments