plugin/tls: respect the path specified by root plugin (#6138)

* plugin/tls: respect the path specified by root plugin

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>

* improve readme

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>

---------

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>
This commit is contained in:
Marius Kimmina
2023-12-08 16:50:30 +01:00
committed by GitHub
parent f9d5d0cb56
commit 92ec849acb
8 changed files with 86 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package tls
import (
"os"
"path/filepath"
"testing"
@@ -22,7 +23,6 @@ func getPEMFiles(t *testing.T) (cert, key, ca string) {
func TestNewTLSConfig(t *testing.T) {
cert, key, ca := getPEMFiles(t)
_, err := NewTLSConfig(cert, key, ca)
if err != nil {
t.Errorf("Failed to create TLSConfig: %s", err)
@@ -77,6 +77,36 @@ func TestNewTLSConfigFromArgs(t *testing.T) {
}
}
func TestNewTLSConfigFromArgsWithRoot(t *testing.T) {
cert, key, ca := getPEMFiles(t)
tempDir, err := os.MkdirTemp("", "go-test-pemfiles")
defer func() {
if err := os.RemoveAll(tempDir); err != nil {
t.Error("failed to clean up temporary directory", err)
}
}()
if err != nil {
t.Error("failed to create temporary directory", err)
}
root := tempDir
args := []string{cert, key, ca}
for i := range args {
if !filepath.IsAbs(args[i]) && root != "" {
args[i] = filepath.Join(root, args[i])
}
}
c, err := NewTLSConfigFromArgs(args...)
if err != nil {
t.Errorf("Failed to create TLSConfig: %s", err)
}
if c.RootCAs == nil {
t.Error("RootCAs should not be nil when three args passed")
}
if len(c.Certificates) != 1 {
t.Error("Certificates should have a single entry when three args passed")
}
}
func TestNewHTTPSTransport(t *testing.T) {
_, _, ca := getPEMFiles(t)