mirror of
https://github.com/caddyserver/caddy.git
synced 2025-04-22 04:18:47 +08:00
add failing test
This commit is contained in:
parent
0e570e0cc7
commit
c8d150daf3
@ -20,6 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
)
|
||||
|
||||
@ -278,3 +279,50 @@ func TestClientAuthenticationUnmarshalCaddyfileWithDirectiveName(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientAuthenticationProvision(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ca ClientAuthentication
|
||||
expected ClientAuthentication
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "specifying both 'CARaw' and 'TrustedCACerts' produces an error",
|
||||
ca: ClientAuthentication{
|
||||
CARaw: json.RawMessage(`{"provider":"inline","trusted_ca_certs":["foo"]}`),
|
||||
TrustedCACerts: []string{"foo"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "specifying both 'CARaw' and 'TrustedCACertPEMFiles' produces an error",
|
||||
ca: ClientAuthentication{
|
||||
CARaw: json.RawMessage(`{"provider":"inline","trusted_ca_certs":["foo"]}`),
|
||||
TrustedCACertPEMFiles: []string{"foo"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "setting 'TrustedCACerts' provisions the cert pool",
|
||||
ca: ClientAuthentication{
|
||||
TrustedCACerts: []string{test_der_1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.ca.provision(caddy.Context{})
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ClientAuthentication.provision() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !tt.wantErr {
|
||||
if tt.ca.ca.CertPool() == nil {
|
||||
t.Error("CertPool is nil, expected non-nil value")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user