@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 38 lines 970 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 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 }