Skip to content

Commit 9fac01c

Browse files
committed
Assert output artifact shim and bootloader ESP paths per distro
1 parent c9fee1e commit 9fac01c

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/artifactsinputoutput_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestOutputAndInjectArtifacts(t *testing.T) {
5555
return
5656
}
5757

58-
espFiles := verifyAndSignOutputtedArtifacts(t, outputArtifactsDir, false)
58+
espFiles := verifyAndSignOutputtedArtifacts(t, baseImageInfo, outputArtifactsDir, false)
5959

6060
// Use new buildDir to ensure the buildDir is created if it doesn't exist.
6161
buildDirInject := filepath.Join(buildDir, "inject")
@@ -163,7 +163,7 @@ func TestOutputAndInjectArtifactsCosi(t *testing.T) {
163163
return
164164
}
165165

166-
espFiles := verifyAndSignOutputtedArtifacts(t, outputArtifactsDir, true)
166+
espFiles := verifyAndSignOutputtedArtifacts(t, baseImageInfo, outputArtifactsDir, true)
167167

168168
// Inject artifacts into image.
169169
options := InjectFilesOptions{
@@ -305,7 +305,19 @@ func TestOutputAndInjectArtifactsCosi(t *testing.T) {
305305
"root", buildDir, "", "restart-on-corruption", false /*inlineVerity*/)
306306
}
307307

308-
func verifyAndSignOutputtedArtifacts(t *testing.T, outputArtifactsDir string, expectVerityHash bool) []string {
308+
func verifyAndSignOutputtedArtifacts(t *testing.T, baseImageInfo testBaseImageInfo, outputArtifactsDir string, expectVerityHash bool) []string {
309+
// Resolve the distro-version's boot file layout so artifact destinations can be checked against the distro's
310+
// actual ESP paths. The boot file names differ per distro-version (for example, Azure Linux 4 uses the Fedora-style
311+
// uppercase BOOTX64.EFI shim, while Azure Linux 3 uses lowercase bootx64.efi).
312+
distroHandler, err := NewDistroHandler(baseImageInfo.TargetOs())
313+
if !assert.NoError(t, err) {
314+
return nil
315+
}
316+
bootConfig, err := distroHandler.GetBootArchConfig()
317+
if !assert.NoError(t, err) {
318+
return nil
319+
}
320+
309321
// Confirm inject-files.yaml was generated
310322
injectConfigPath := filepath.Join(outputArtifactsDir, "inject-files.yaml")
311323
exists, err := file.PathExists(injectConfigPath)
@@ -333,15 +345,15 @@ func verifyAndSignOutputtedArtifacts(t *testing.T, outputArtifactsDir string, ex
333345

334346
switch entry.Type {
335347
case imagecustomizerapi.OutputArtifactsItemShim:
336-
assert.True(t, strings.HasPrefix(entry.Destination, "/EFI/BOOT/boot"), "Expected shim destination to start with /EFI/BOOT/boot")
337-
assert.True(t, strings.HasSuffix(entry.Destination, ".efi"), "Expected shim destination to end with .efi")
348+
expectedShimDestination := filepath.Join("/", bootConfig.espBootBinaryPath)
349+
assert.Equal(t, expectedShimDestination, entry.Destination, "Expected shim destination to match the distro ESP boot binary path")
338350
assert.True(t, strings.HasPrefix(entry.Source, "./shim/"), "Expected shim source to be in shim/ subdirectory")
339351
hasShim = true
340352
espFiles = append(espFiles, entry.Destination)
341353

342354
case imagecustomizerapi.OutputArtifactsItemBootloader:
343-
assert.True(t, strings.HasPrefix(entry.Destination, "/EFI/BOOT/grub"), "Expected bootloader destination to start with /EFI/BOOT/grub")
344-
assert.True(t, strings.HasSuffix(entry.Destination, ".efi"), "Expected bootloader destination to end with .efi")
355+
expectedBootloaderDestination := filepath.Join("/", bootConfig.espGrubBinaryPath)
356+
assert.Equal(t, expectedBootloaderDestination, entry.Destination, "Expected bootloader destination to match the distro ESP grub binary path")
345357
assert.True(t, strings.HasPrefix(entry.Source, "./bootloader/"), "Expected bootloader source to be in bootloader/ subdirectory")
346358
hasBootloader = true
347359
espFiles = append(espFiles, entry.Destination)

0 commit comments

Comments
 (0)