mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
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>
41 lines
866 B
Go
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)
|
|
}
|