From 324824233a23964f866612735db9644864d28dbc Mon Sep 17 00:00:00 2001 From: LordNoteworthy Date: Wed, 30 Oct 2024 21:36:24 +1100 Subject: [PATCH] feat: loadSystemRoots use ExitCode to test cmd success --- security.go | 4 ++-- security_test.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/security.go b/security.go index f577f4a..bf1326b 100644 --- a/security.go +++ b/security.go @@ -467,11 +467,11 @@ func loadSystemRoots() (*x509.CertPool, error) { if needSync { cmd := exec.Command("certutil", "-syncWithWU", dir) hideWindow(cmd) - out, err := cmd.Output() + err := cmd.Run() if err != nil { return roots, err } - if !strings.Contains(string(out), "command completed successfully") { + if cmd.ProcessState.ExitCode() != 0 { return roots, err } } diff --git a/security_test.go b/security_test.go index fb41f12..f7bad3a 100644 --- a/security_test.go +++ b/security_test.go @@ -9,7 +9,6 @@ import ( "fmt" "path/filepath" "reflect" - "runtime" "testing" "time" ) @@ -199,11 +198,10 @@ func TestParseSecurityDirectory(t *testing.T) { if expected.SignatureValid != cert.SignatureValid { t.Fatalf("signature verification %d failed, cert %v, want %v", i, cert.SignatureValid, expected.SignatureValid) } - if runtime.GOOS == "linux" { - if expected.Verified != cert.Verified { - t.Fatalf("certificate verification %d failed, cert %v, want %v", i, cert.Verified, expected.Verified) - } + if expected.Verified != cert.Verified { + t.Fatalf("certificate verification %d failed, cert %v, want %v", i, cert.Verified, expected.Verified) } + } }) }