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

Function TestLeafFileLoader

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

Source from the content-addressed store, hash-verified

11)
12
13func TestLeafFileLoader(t *testing.T) {
14 fl := LeafFileLoader{Files: []string{"../../caddytest/leafcert.pem"}}
15 fl.Provision(caddy.Context{Context: context.Background()})
16
17 out, err := fl.LoadLeafCertificates()
18 if err != nil {
19 t.Errorf("Leaf certs file 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
27 pemFileBytes, err := os.ReadFile("../../caddytest/leafcert.pem")
28 if err != nil {
29 t.Errorf("Unable to read the example certificate from the file")
30 }
31
32 // Remove /r because windows.
33 pemFileString := strings.ReplaceAll(string(pemFileBytes), "\r\n", "\n")
34
35 if string(pemBytes) != pemFileString {
36 t.Errorf("Leaf Certificate File Loader: Failed to load the correct certificate")
37 }
38}

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