Fix panic when getting certificates with non-existing store
Co-authored-by: Tom Moulard <tom.moulard@traefik.io>
This commit is contained in:
parent
575d4ab431
commit
e642365613
2 changed files with 37 additions and 0 deletions
|
@ -171,6 +171,13 @@ func (m *Manager) Get(storeName, configName string) (*tls.Config, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if store == nil {
|
||||||
|
log.WithoutContext().Errorf("TLS: No certificate store found with this name: %q, closing connection", storeName)
|
||||||
|
|
||||||
|
// Same comment as above, as in the isACMETLS case.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
log.WithoutContext().Debugf("Serving default certificate for request: %q", domainToCheck)
|
log.WithoutContext().Debugf("Serving default certificate for request: %q", domainToCheck)
|
||||||
return store.DefaultCertificate, nil
|
return store.DefaultCertificate, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,6 +171,36 @@ func TestManager_Get(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestManager_Get_GetCertificate(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
expectedGetConfigErr require.ErrorAssertionFunc
|
||||||
|
expectedCertificate assert.ValueAssertionFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "Get a default certificate from non-existing store",
|
||||||
|
expectedGetConfigErr: require.Error,
|
||||||
|
expectedCertificate: assert.Nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsManager := NewManager()
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
test := test
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
config, err := tlsManager.Get("default", "foo")
|
||||||
|
test.expectedGetConfigErr(t, err)
|
||||||
|
|
||||||
|
certificate, err := config.GetCertificate(&tls.ClientHelloInfo{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
test.expectedCertificate(t, certificate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClientAuth(t *testing.T) {
|
func TestClientAuth(t *testing.T) {
|
||||||
tlsConfigs := map[string]Options{
|
tlsConfigs := map[string]Options{
|
||||||
"eca": {
|
"eca": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue