Merge pull request #617 from jangie/fix-nil-client-tls

fix for nil clientTLS causing issue
This commit is contained in:
Vincent Demeester 2016-08-17 09:46:17 +02:00 committed by GitHub
commit f1c3d820f7
2 changed files with 26 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import (
"crypto/x509"
"fmt"
"github.com/BurntSushi/toml"
log "github.com/Sirupsen/logrus"
"github.com/containous/traefik/autogen"
"github.com/containous/traefik/safe"
"github.com/containous/traefik/types"
@ -109,6 +110,10 @@ type ClientTLS struct {
// CreateTLSConfig creates a TLS config from ClientTLS structures
func (clientTLS *ClientTLS) CreateTLSConfig() (*tls.Config, error) {
var err error
if clientTLS == nil {
log.Warnf("clientTLS is nil")
return nil, nil
}
caPool := x509.NewCertPool()
if clientTLS.CA != "" {
var ca []byte

View file

@ -12,6 +12,7 @@ import (
type myProvider struct {
BaseProvider
TLS *ClientTLS
}
func (p *myProvider) Foo() string {
@ -54,6 +55,7 @@ func TestConfigurationErrors(t *testing.T) {
BaseProvider{
Filename: "/non/existent/template.tmpl",
},
nil,
},
expectedError: "open /non/existent/template.tmpl: no such file or directory",
},
@ -67,6 +69,7 @@ func TestConfigurationErrors(t *testing.T) {
BaseProvider{
Filename: templateErrorFile.Name(),
},
nil,
},
expectedError: `function "Bar" not defined`,
},
@ -75,6 +78,7 @@ func TestConfigurationErrors(t *testing.T) {
BaseProvider{
Filename: templateInvalidTOMLFile.Name(),
},
nil,
},
expectedError: "Near line 1 (last key parsed 'Hello'): Expected key separator '=', but got '<' instead",
funcMap: template.FuncMap{
@ -130,6 +134,7 @@ func TestGetConfiguration(t *testing.T) {
BaseProvider{
Filename: templateFile.Name(),
},
nil,
}
configuration, err := provider.getConfiguration(templateFile.Name(), nil, nil)
if err != nil {
@ -191,6 +196,7 @@ func TestGetConfigurationReturnsCorrectMaxConnConfiguration(t *testing.T) {
BaseProvider{
Filename: templateFile.Name(),
},
nil,
}
configuration, err := provider.getConfiguration(templateFile.Name(), nil, nil)
if err != nil {
@ -209,6 +215,19 @@ func TestGetConfigurationReturnsCorrectMaxConnConfiguration(t *testing.T) {
}
}
func TestNilClientTLS(t *testing.T) {
provider := &myProvider{
BaseProvider{
Filename: "",
},
nil,
}
_, err := provider.TLS.CreateTLSConfig()
if err != nil {
t.Fatalf("CreateTLSConfig should assume that consumer does not want a TLS configuration if input is nil")
}
}
func TestMatchingConstraints(t *testing.T) {
cases := []struct {
constraints []types.Constraint
@ -298,10 +317,11 @@ func TestMatchingConstraints(t *testing.T) {
BaseProvider{
Constraints: c.constraints,
},
nil,
}
actual, _ := provider.MatchConstraints(c.tags)
if actual != c.expected {
t.Fatalf("test #%v: expected %q, got %q, for %q", i, c.expected, actual, c.constraints)
t.Fatalf("test #%v: expected %t, got %t, for %#v", i, c.expected, actual, c.constraints)
}
}
}