Add TLSStores to Kubernetes CRD

This commit is contained in:
Daniel Tomcej 2020-02-24 08:14:06 -08:00 committed by GitHub
parent 101aefbfe8
commit a474e196ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1560 additions and 6 deletions

View file

@ -294,3 +294,95 @@ func TestAggregator_tlsoptions(t *testing.T) {
})
}
}
func TestAggregator_tlsStore(t *testing.T) {
testCases := []struct {
desc string
given dynamic.Configurations
expected map[string]tls.Store
}{
{
desc: "Create a valid default tls store when appears only in one provider",
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Stores: map[string]tls.Store{
"default": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
},
},
},
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Stores: map[string]tls.Store{
"foo": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
},
},
},
},
expected: map[string]tls.Store{
"default": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
"foo@provider-2": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
},
},
{
desc: "Don't default tls store when appears two times",
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Stores: map[string]tls.Store{
"default": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
},
},
},
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Stores: map[string]tls.Store{
"default": {
DefaultCertificate: &tls.Certificate{
CertFile: "foo",
KeyFile: "bar",
},
},
},
},
},
},
expected: map[string]tls.Store{},
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
actual := mergeConfiguration(test.given)
assert.Equal(t, test.expected, actual.TLS.Stores)
})
}
}