first commit
This commit is contained in:
22
httpdl/ca_test.go
Normal file
22
httpdl/ca_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package httpdl
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadCAPool(t *testing.T) {
|
||||
// A missing file is an error, not a silent fall-back to the system roots.
|
||||
if _, err := loadCAPool(filepath.Join(t.TempDir(), "absent.pem")); err == nil {
|
||||
t.Errorf("loadCAPool(missing): want error")
|
||||
}
|
||||
// A file with no PEM certificates is an error (AppendCertsFromPEM found none).
|
||||
bad := filepath.Join(t.TempDir(), "bad.pem")
|
||||
if err := os.WriteFile(bad, []byte("not a certificate\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := loadCAPool(bad); err == nil {
|
||||
t.Errorf("loadCAPool(garbage): want error (no certificates)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user