(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
nothing calls this directly
no test coverage detected