MCPcopy
hub / github.com/caddyserver/caddy / TestLeafFolderLoader

Function TestLeafFolderLoader

modules/caddytls/leaffolderloader_test.go:13–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestLeafFolderLoader(t *testing.T) {
14 fl := LeafFolderLoader{Folders: []string{"../../caddytest"}}
15 fl.Provision(caddy.Context{Context: context.Background()})
16
17 out, err := fl.LoadLeafCertificates()
18 if err != nil {
19 t.Errorf("Leaf certs folder loading test failed: %v", err)
20 }
21 if len(out) != 1 {
22 t.Errorf("Error loading leaf cert in memory struct")
23 return
24 }
25 pemBytes := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: out[0].Raw})
26 pemFileBytes, err := os.ReadFile("../../caddytest/leafcert.pem")
27 if err != nil {
28 t.Errorf("Unable to read the example certificate from the file")
29 }
30
31 // Remove /r because windows.
32 pemFileString := strings.ReplaceAll(string(pemFileBytes), "\r\n", "\n")
33
34 if string(pemBytes) != pemFileString {
35 t.Errorf("Leaf Certificate Folder Loader: Failed to load the correct certificate")
36 }
37}

Callers

nothing calls this directly

Calls 4

ProvisionMethod · 0.95
LoadLeafCertificatesMethod · 0.95
ReadFileMethod · 0.80
ReplaceAllMethod · 0.80

Tested by

no test coverage detected