Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for empty certificates directory #388

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [#374](https://github.com/suse-edge/edge-image-builder/issues/374) - Enable SELinux support for Kubernetes agents if servers enforce it
* [#381](https://github.com/suse-edge/edge-image-builder/issues/381) - Empty gpg-keys directory passes GPG enablement only to fail during the dependency resolution
* [#383](https://github.com/suse-edge/edge-image-builder/issues/383) - Criteria for validating the OS definition does not include RPM
* [#372](https://github.com/suse-edge/edge-image-builder/issues/372) - Empty certificates directory does not raise a build error but fails to boot the node

---

Expand Down
9 changes: 9 additions & 0 deletions pkg/combustion/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ func copyCertificates(ctx *image.Context) error {
srcDir := filepath.Join(ctx.ImageConfigDir, certsConfigDir)
destDir := filepath.Join(ctx.CombustionDir, certsConfigDir)

dirEntries, err := os.ReadDir(srcDir)
if err != nil {
return fmt.Errorf("reading the certificates directory at %s: %w", srcDir, err)
}

if len(dirEntries) == 0 {
return fmt.Errorf("no certificates found in directory %s", srcDir)
}

if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
return fmt.Errorf("creating certificates directory '%s': %w", destDir, err)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/combustion/certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func setupCertificatesConfigDir(t *testing.T) (ctx *image.Context, teardown func
return
}

func TestCopyCertificatesEmptyDirectory(t *testing.T) {
// Setup
ctx, teardown := setupContext(t)
defer teardown()

testCertsDir := filepath.Join(ctx.ImageConfigDir, certsConfigDir)
err := os.Mkdir(testCertsDir, 0o755)
require.NoError(t, err)
defer os.RemoveAll(testCertsDir)

// Test
err = copyCertificates(ctx)

// Verify
require.Error(t, err)
}

func TestCopyCertificates(t *testing.T) {
// Setup
ctx, teardown := setupCertificatesConfigDir(t)
Expand Down
Loading