mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
3ae07a73dc
* Made trusted leaf certificates pluggable into the tls.client_auth.leaf module * Added leaf loaders modules: file, folder, pem aand storage * Cleaned implementation of leaf cert loader modules * Added tests for leaf certs file and folder loaders * cmd: fix the output of the `Usage` section (#6138) * core: OnExit hooks (#6128) * core: OnExit callbacks * core: Process-global OnExit callbacks * ci: bump golangci/golangci-lint-action from 3 to 4 (#6141) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 4. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v3...v4) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Added more leaf certificate loaders tests and cleaned up code * Modified leaf cert loaders json field names and cleaned up storage loader comment * Update modules/caddytls/leaffileloader.go * Update LeafStorageLoader certificates field name * Upgraded protobuf version --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
37 lines
966 B
Go
37 lines
966 B
Go
package caddytls
|
|
|
|
import (
|
|
"context"
|
|
"encoding/pem"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/caddyserver/caddy/v2"
|
|
)
|
|
|
|
func TestLeafFolderLoader(t *testing.T) {
|
|
fl := LeafFolderLoader{Folders: []string{"../../caddytest"}}
|
|
fl.Provision(caddy.Context{Context: context.Background()})
|
|
|
|
out, err := fl.LoadLeafCertificates()
|
|
if err != nil {
|
|
t.Errorf("Leaf certs folder loading test failed: %v", err)
|
|
}
|
|
if len(out) != 1 {
|
|
t.Errorf("Error loading leaf cert in memory struct")
|
|
return
|
|
}
|
|
pemBytes := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: out[0].Raw})
|
|
pemFileBytes, err := os.ReadFile("../../caddytest/leafcert.pem")
|
|
if err != nil {
|
|
t.Errorf("Unable to read the example certificate from the file")
|
|
}
|
|
|
|
// Remove /r because windows.
|
|
pemFileString := strings.ReplaceAll(string(pemFileBytes), "\r\n", "\n")
|
|
|
|
if string(pemBytes) != pemFileString {
|
|
t.Errorf("Leaf Certificate Folder Loader: Failed to load the correct certificate")
|
|
}
|
|
}
|