spiegel_podman/pkg/machine/certificates/certificates_windows_test.go
Mario Loriedo f7dd6156d3 Import host certificates at machine startup on Windows
Implements the feature introduced in the design
document added with commit 4bdc1d37

Fixes https://redhat.atlassian.net/browse/RUN-4260

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2026-04-16 13:35:40 +02:00

41 lines
866 B
Go

package certificates
import (
"fmt"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func verifyCertificateFile(filePath string) error {
cmd := exec.Command(
`powershell`,
"-NoProfile",
"-NonInteractive",
"-Command",
"(Get-PfxCertificate -FilePath '"+filePath+"').Verify()",
)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("output: %s, error: %s", out, err)
}
if !strings.Contains(string(out), "True") {
return fmt.Errorf("certificate verification failed")
}
return nil
}
func TestExtractAndSaveCertificates(t *testing.T) {
certs := extractHostCertificates()
assert.NotEmpty(t, certs)
filePath := filepath.Join(t.TempDir(), "cert.pem")
err := saveCertificatesToPEM(certs, filePath)
assert.NoError(t, err)
err = verifyCertificateFile(filePath)
assert.NoError(t, err)
}