@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 37 lines 966 Bytes
Raw
1 package caddytls
2
3 import (
4 "context"
5 "encoding/pem"
6 "os"
7 "strings"
8 "testing"
9
10 "github.com/caddyserver/caddy/v2"
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 }