github.com/geraldss/go/src@v0.0.0-20210511222824-ac7d0ebfc235/crypto/x509/root_darwin_test.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package x509 6 7 import ( 8 "os" 9 "os/exec" 10 "testing" 11 "time" 12 ) 13 14 func TestSystemRoots(t *testing.T) { 15 t0 := time.Now() 16 sysRoots, err := loadSystemRoots() // actual system roots 17 sysRootsDuration := time.Since(t0) 18 19 if err != nil { 20 t.Fatalf("failed to read system roots: %v", err) 21 } 22 23 t.Logf("loadSystemRoots: %v", sysRootsDuration) 24 25 // There are 174 system roots on Catalina, and 163 on iOS right now, require 26 // at least 100 to make sure this is not completely broken. 27 if want, have := 100, sysRoots.len(); have < want { 28 t.Errorf("want at least %d system roots, have %d", want, have) 29 } 30 31 if t.Failed() { 32 cmd := exec.Command("security", "dump-trust-settings") 33 cmd.Stdout, cmd.Stderr = os.Stderr, os.Stderr 34 cmd.Run() 35 cmd = exec.Command("security", "dump-trust-settings", "-d") 36 cmd.Stdout, cmd.Stderr = os.Stderr, os.Stderr 37 cmd.Run() 38 } 39 }