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