2019-01-15 13:28:04 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-29 14:40:04 +00:00
|
|
|
"github.com/go-acme/lego/v4/challenge/tlsalpn01"
|
2019-01-15 13:28:04 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/tls"
|
2019-01-15 13:28:04 +00:00
|
|
|
)
|
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
func Test_mergeConfiguration(t *testing.T) {
|
2019-01-15 13:28:04 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-10 07:26:04 +00:00
|
|
|
given dynamic.Configurations
|
|
|
|
expected *dynamic.HTTPConfiguration
|
2019-01-15 13:28:04 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Nil returns an empty configuration",
|
|
|
|
given: nil,
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.HTTPConfiguration{
|
2020-09-11 13:40:03 +00:00
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: make(map[string]*dynamic.Model),
|
|
|
|
ServersTransports: make(map[string]*dynamic.ServersTransport),
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Returns fully qualified elements from a mono-provider configuration map",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-03-14 08:30:04 +00:00
|
|
|
"router-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.Middleware{
|
2019-03-14 08:30:04 +00:00
|
|
|
"middleware-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-03-14 08:30:04 +00:00
|
|
|
"service-1": {},
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-03-05 11:46:05 +00:00
|
|
|
"router-1@provider-1": {
|
|
|
|
EntryPoints: []string{"defaultEP"},
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.Middleware{
|
2019-06-21 07:54:04 +00:00
|
|
|
"middleware-1@provider-1": {},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-06-21 07:54:04 +00:00
|
|
|
"service-1@provider-1": {},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2020-09-11 13:40:03 +00:00
|
|
|
Models: make(map[string]*dynamic.Model),
|
|
|
|
ServersTransports: make(map[string]*dynamic.ServersTransport),
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-03-14 08:30:04 +00:00
|
|
|
"router-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.Middleware{
|
2019-03-14 08:30:04 +00:00
|
|
|
"middleware-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-03-14 08:30:04 +00:00
|
|
|
"service-1": {},
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
"provider-2": &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-03-14 08:30:04 +00:00
|
|
|
"router-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.Middleware{
|
2019-03-14 08:30:04 +00:00
|
|
|
"middleware-1": {},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-03-14 08:30:04 +00:00
|
|
|
"service-1": {},
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-03-05 11:46:05 +00:00
|
|
|
"router-1@provider-1": {
|
|
|
|
EntryPoints: []string{"defaultEP"},
|
|
|
|
},
|
|
|
|
"router-1@provider-2": {
|
|
|
|
EntryPoints: []string{"defaultEP"},
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Middlewares: map[string]*dynamic.Middleware{
|
2019-06-21 07:54:04 +00:00
|
|
|
"middleware-1@provider-1": {},
|
|
|
|
"middleware-1@provider-2": {},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-06-21 07:54:04 +00:00
|
|
|
"service-1@provider-1": {},
|
|
|
|
"service-1@provider-2": {},
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
2020-09-11 13:40:03 +00:00
|
|
|
Models: make(map[string]*dynamic.Model),
|
|
|
|
ServersTransports: make(map[string]*dynamic.ServersTransport),
|
2019-01-15 13:28:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-03-14 08:30:04 +00:00
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
actual := mergeConfiguration(test.given, []string{"defaultEP"})
|
2019-03-14 08:30:04 +00:00
|
|
|
assert.Equal(t, test.expected, actual.HTTP)
|
2019-01-15 13:28:04 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-21 15:18:05 +00:00
|
|
|
|
2020-10-29 14:40:04 +00:00
|
|
|
func Test_mergeConfiguration_tlsCertificates(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
given dynamic.Configurations
|
|
|
|
expected []*tls.CertAndStores
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Skip temp certificates from another provider than tlsalpn",
|
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
|
|
|
Certificates: []*tls.CertAndStores{
|
|
|
|
{Certificate: tls.Certificate{}, Stores: []string{tlsalpn01.ACMETLS1Protocol}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Allows tlsalpn provider to give certificates",
|
|
|
|
given: dynamic.Configurations{
|
|
|
|
"tlsalpn.acme": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
|
|
|
Certificates: []*tls.CertAndStores{{
|
|
|
|
Certificate: tls.Certificate{CertFile: "foo", KeyFile: "bar"},
|
|
|
|
Stores: []string{tlsalpn01.ACMETLS1Protocol},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []*tls.CertAndStores{{
|
|
|
|
Certificate: tls.Certificate{CertFile: "foo", KeyFile: "bar"},
|
|
|
|
Stores: []string{tlsalpn01.ACMETLS1Protocol},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
actual := mergeConfiguration(test.given, []string{"defaultEP"})
|
|
|
|
assert.Equal(t, test.expected, actual.TLS.Certificates)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
func Test_mergeConfiguration_tlsOptions(t *testing.T) {
|
2019-06-21 15:18:05 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2019-07-10 07:26:04 +00:00
|
|
|
given dynamic.Configurations
|
2019-06-27 21:58:03 +00:00
|
|
|
expected map[string]tls.Options
|
2019-06-21 15:18:05 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Nil returns an empty configuration",
|
|
|
|
given: nil,
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2022-09-08 08:56:08 +00:00
|
|
|
"default": tls.DefaultTLSOptions,
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Returns fully qualified elements from a mono-provider configuration map",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2022-09-08 08:56:08 +00:00
|
|
|
"default": tls.DefaultTLSOptions,
|
2019-06-21 15:18:05 +00:00
|
|
|
"foo@provider-1": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
"provider-2": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2022-09-08 08:56:08 +00:00
|
|
|
"default": tls.DefaultTLSOptions,
|
2019-06-21 15:18:05 +00:00
|
|
|
"foo@provider-1": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
"foo@provider-2": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Create a valid default tls option when appears only in one provider",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
"default": {
|
|
|
|
MinVersion: "VersionTLS11",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
"provider-2": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2019-06-21 15:18:05 +00:00
|
|
|
"default": {
|
|
|
|
MinVersion: "VersionTLS11",
|
|
|
|
},
|
|
|
|
"foo@provider-1": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
"foo@provider-2": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "No default tls option if it is defined in multiple providers",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
"default": {
|
|
|
|
MinVersion: "VersionTLS11",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
"provider-2": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
"default": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2019-06-21 15:18:05 +00:00
|
|
|
"foo@provider-1": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
"foo@provider-2": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Create a default TLS Options configuration if none was provided",
|
2019-07-10 07:26:04 +00:00
|
|
|
given: dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
"provider-2": &dynamic.Configuration{
|
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Options: map[string]tls.Options{
|
|
|
|
"foo": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
2019-06-21 15:18:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
expected: map[string]tls.Options{
|
2022-09-08 08:56:08 +00:00
|
|
|
"default": tls.DefaultTLSOptions,
|
2019-06-21 15:18:05 +00:00
|
|
|
"foo@provider-1": {
|
|
|
|
MinVersion: "VersionTLS12",
|
|
|
|
},
|
|
|
|
"foo@provider-2": {
|
|
|
|
MinVersion: "VersionTLS13",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
actual := mergeConfiguration(test.given, []string{"defaultEP"})
|
2019-06-27 21:58:03 +00:00
|
|
|
assert.Equal(t, test.expected, actual.TLS.Options)
|
2019-06-21 15:18:05 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-02-24 16:14:06 +00:00
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
func Test_mergeConfiguration_tlsStore(t *testing.T) {
|
2020-02-24 16:14:06 +00:00
|
|
|
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 {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
actual := mergeConfiguration(test.given, []string{"defaultEP"})
|
2020-02-24 16:14:06 +00:00
|
|
|
assert.Equal(t, test.expected, actual.TLS.Stores)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 11:46:05 +00:00
|
|
|
|
2021-05-11 14:46:14 +00:00
|
|
|
func Test_mergeConfiguration_defaultTCPEntryPoint(t *testing.T) {
|
|
|
|
given := dynamic.Configurations{
|
|
|
|
"provider-1": &dynamic.Configuration{
|
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
|
|
|
"router-1": {},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.TCPService{
|
|
|
|
"service-1": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
|
|
|
"router-1@provider-1": {
|
|
|
|
EntryPoints: []string{"defaultEP"},
|
|
|
|
},
|
|
|
|
},
|
2021-06-22 12:05:57 +00:00
|
|
|
Middlewares: map[string]*dynamic.TCPMiddleware{},
|
2021-05-11 14:46:14 +00:00
|
|
|
Services: map[string]*dynamic.TCPService{
|
|
|
|
"service-1@provider-1": {},
|
|
|
|
},
|
2024-01-23 10:34:05 +00:00
|
|
|
Models: map[string]*dynamic.TCPModel{},
|
2022-12-09 08:58:05 +00:00
|
|
|
ServersTransports: make(map[string]*dynamic.TCPServersTransport),
|
2021-05-11 14:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actual := mergeConfiguration(given, []string{"defaultEP"})
|
|
|
|
assert.Equal(t, expected, actual.TCP)
|
|
|
|
}
|
|
|
|
|
2020-03-05 11:46:05 +00:00
|
|
|
func Test_applyModel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
input dynamic.Configuration
|
|
|
|
expected dynamic.Configuration
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "empty configuration",
|
|
|
|
input: dynamic.Configuration{},
|
|
|
|
expected: dynamic.Configuration{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "without model",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: make(map[string]*dynamic.Model),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: make(map[string]*dynamic.Model),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "with model, not used",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"ep@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"ep@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "with model, one entry point",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure"},
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "with model, one entry point, and router with tls",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{CertResolver: "router"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{CertResolver: "ep"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure"},
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{CertResolver: "router"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{CertResolver: "ep"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "with model, two entry points",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure", "web"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"web"},
|
|
|
|
},
|
|
|
|
"websecure-test": {
|
|
|
|
EntryPoints: []string{"websecure"},
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
|
|
|
Models: map[string]*dynamic.Model{
|
|
|
|
"websecure@internal": {
|
|
|
|
Middlewares: []string{"test"},
|
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-05-14 07:42:04 +00:00
|
|
|
{
|
|
|
|
desc: "with TCP model, two entry points",
|
|
|
|
input: dynamic.Configuration{
|
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure", "web"},
|
|
|
|
},
|
|
|
|
"test2": {
|
|
|
|
EntryPoints: []string{"web"},
|
|
|
|
RuleSyntax: "barfoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.TCPMiddleware),
|
|
|
|
Services: make(map[string]*dynamic.TCPService),
|
|
|
|
Models: map[string]*dynamic.TCPModel{
|
|
|
|
"websecure@internal": {
|
|
|
|
DefaultRuleSyntax: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: dynamic.Configuration{
|
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.TCPRouter{
|
|
|
|
"test": {
|
|
|
|
EntryPoints: []string{"websecure", "web"},
|
|
|
|
RuleSyntax: "foobar",
|
|
|
|
},
|
|
|
|
"test2": {
|
|
|
|
EntryPoints: []string{"web"},
|
|
|
|
RuleSyntax: "barfoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Middlewares: make(map[string]*dynamic.TCPMiddleware),
|
|
|
|
Services: make(map[string]*dynamic.TCPService),
|
|
|
|
Models: map[string]*dynamic.TCPModel{
|
|
|
|
"websecure@internal": {
|
|
|
|
DefaultRuleSyntax: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-05 11:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
actual := applyModel(test.input)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|