traefik/pkg/anonymize/anonymize_config_test.go

540 lines
15 KiB
Go
Raw Normal View History

2017-10-02 08:32:02 +00:00
package anonymize
import (
2020-10-30 11:44:05 +00:00
"flag"
"io/ioutil"
2018-10-01 17:18:03 +00:00
"os"
2020-10-30 11:44:05 +00:00
"strings"
2017-10-02 08:32:02 +00:00
"testing"
"time"
2019-02-18 06:52:03 +00:00
assetfs "github.com/elazarl/go-bindata-assetfs"
2020-10-30 11:44:05 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v2/pkg/config/static"
"github.com/traefik/traefik/v2/pkg/ping"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/plugins"
"github.com/traefik/traefik/v2/pkg/provider/acme"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/provider/consulcatalog"
"github.com/traefik/traefik/v2/pkg/provider/docker"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/provider/ecs"
"github.com/traefik/traefik/v2/pkg/provider/file"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/provider/http"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/ingress"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/provider/kv"
"github.com/traefik/traefik/v2/pkg/provider/kv/consul"
"github.com/traefik/traefik/v2/pkg/provider/kv/etcd"
"github.com/traefik/traefik/v2/pkg/provider/kv/redis"
"github.com/traefik/traefik/v2/pkg/provider/kv/zk"
"github.com/traefik/traefik/v2/pkg/provider/marathon"
"github.com/traefik/traefik/v2/pkg/provider/rancher"
"github.com/traefik/traefik/v2/pkg/provider/rest"
traefiktls "github.com/traefik/traefik/v2/pkg/tls"
"github.com/traefik/traefik/v2/pkg/tracing/datadog"
2020-10-30 11:44:05 +00:00
"github.com/traefik/traefik/v2/pkg/tracing/elastic"
"github.com/traefik/traefik/v2/pkg/tracing/haystack"
"github.com/traefik/traefik/v2/pkg/tracing/instana"
"github.com/traefik/traefik/v2/pkg/tracing/jaeger"
"github.com/traefik/traefik/v2/pkg/tracing/zipkin"
"github.com/traefik/traefik/v2/pkg/types"
2017-10-02 08:32:02 +00:00
)
2020-10-30 11:44:05 +00:00
var updateExpected = flag.Bool("update_expected", false, "Update expected files in fixtures")
2017-10-02 08:32:02 +00:00
func TestDo_globalConfiguration(t *testing.T) {
config := &static.Configuration{}
2017-10-02 08:32:02 +00:00
config.Global = &static.Global{
CheckNewVersion: true,
2019-09-16 15:26:06 +00:00
SendAnonymousUsage: true,
}
2019-03-14 18:32:03 +00:00
2020-10-30 11:44:05 +00:00
config.ServersTransport = &static.ServersTransport{
InsecureSkipVerify: true,
RootCAs: []traefiktls.FileOrContent{"root.ca"},
MaxIdleConnsPerHost: 42,
ForwardingTimeouts: &static.ForwardingTimeouts{
DialTimeout: 42,
ResponseHeaderTimeout: 42,
IdleConnTimeout: 42,
2019-03-14 18:32:03 +00:00
},
}
2019-03-14 18:32:03 +00:00
config.EntryPoints = static.EntryPoints{
2020-10-30 11:44:05 +00:00
"foobar": {
2017-10-02 08:32:02 +00:00
Address: "foo Address",
Transport: &static.EntryPointsTransport{
2020-10-30 11:44:05 +00:00
LifeCycle: &static.LifeCycle{
RequestAcceptGraceTimeout: ptypes.Duration(111 * time.Second),
GraceTimeOut: ptypes.Duration(111 * time.Second),
},
RespondingTimeouts: &static.RespondingTimeouts{
ReadTimeout: ptypes.Duration(111 * time.Second),
WriteTimeout: ptypes.Duration(111 * time.Second),
IdleTimeout: ptypes.Duration(111 * time.Second),
},
},
ProxyProtocol: &static.ProxyProtocol{
2020-10-30 11:44:05 +00:00
Insecure: true,
2017-10-10 12:50:03 +00:00
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
2020-10-30 11:44:05 +00:00
ForwardedHeaders: &static.ForwardedHeaders{
Insecure: true,
2017-10-10 12:50:03 +00:00
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
2020-10-30 11:44:05 +00:00
HTTP: static.HTTPConfig{
Redirections: &static.Redirections{
EntryPoint: &static.RedirectEntryPoint{
To: "foobar",
Scheme: "foobar",
Permanent: true,
Priority: 42,
},
},
Middlewares: []string{"foobar", "foobar"},
TLS: &static.TLSConfig{
Options: "foobar",
CertResolver: "foobar",
Domains: []types.Domain{
{Main: "foobar", SANs: []string{"foobar", "foobar"}},
},
},
2017-10-02 08:32:02 +00:00
},
},
}
2020-10-30 11:44:05 +00:00
config.Providers = &static.Providers{
ProvidersThrottleDuration: ptypes.Duration(111 * time.Second),
2017-10-02 08:32:02 +00:00
}
config.ServersTransport = &static.ServersTransport{
InsecureSkipVerify: true,
RootCAs: []traefiktls.FileOrContent{"RootCAs 1", "RootCAs 2", "RootCAs 3"},
MaxIdleConnsPerHost: 111,
ForwardingTimeouts: &static.ForwardingTimeouts{
DialTimeout: ptypes.Duration(111 * time.Second),
ResponseHeaderTimeout: ptypes.Duration(111 * time.Second),
2020-10-30 11:44:05 +00:00
IdleConnTimeout: ptypes.Duration(111 * time.Second),
2018-10-01 17:18:03 +00:00
},
}
config.Providers.File = &file.Provider{
2019-03-27 14:02:06 +00:00
Directory: "file Directory",
Watch: true,
Filename: "file Filename",
DebugLogGeneratedTemplate: true,
}
config.Providers.Docker = &docker.Provider{
Constraints: `Label("foo", "bar")`,
2019-03-27 14:02:06 +00:00
Watch: true,
2019-03-14 18:32:03 +00:00
Endpoint: "MyEndPoint",
DefaultRule: "PathPrefix(`/`)",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
ExposedByDefault: true,
UseBindPortIP: true,
SwarmMode: true,
Network: "MyNetwork",
SwarmModeRefreshSeconds: 42,
}
2020-10-30 11:44:05 +00:00
config.Providers.Marathon = &marathon.Provider{
Constraints: `Label("foo", "bar")`,
Trace: true,
Watch: true,
Endpoint: "foobar",
DefaultRule: "PathPrefix(`/`)",
ExposedByDefault: true,
DCOSToken: "foobar",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
DialerTimeout: 42,
ResponseHeaderTimeout: 42,
TLSHandshakeTimeout: 42,
KeepAlive: 42,
ForceTaskHostname: true,
Basic: &marathon.Basic{
HTTPBasicAuthUser: "user",
HTTPBasicPassword: "password",
},
RespectReadinessChecks: true,
}
config.Providers.KubernetesIngress = &ingress.Provider{
2019-03-14 18:32:03 +00:00
Endpoint: "MyEndpoint",
Token: "MyToken",
CertAuthFilePath: "MyCertAuthPath",
DisablePassHostHeaders: true,
Namespaces: []string{"a", "b"},
LabelSelector: "myLabelSelector",
IngressClass: "MyIngressClass",
2020-10-30 11:44:05 +00:00
IngressEndpoint: &ingress.EndpointIngress{
IP: "IP",
Hostname: "Hostname",
PublishedService: "PublishedService",
},
ThrottleDuration: ptypes.Duration(111 * time.Second),
2019-03-14 18:32:03 +00:00
}
config.Providers.KubernetesCRD = &crd.Provider{
Endpoint: "MyEndpoint",
Token: "MyToken",
CertAuthFilePath: "MyCertAuthPath",
DisablePassHostHeaders: true,
Namespaces: []string{"a", "b"},
LabelSelector: "myLabelSelector",
IngressClass: "MyIngressClass",
2020-10-30 11:44:05 +00:00
ThrottleDuration: ptypes.Duration(111 * time.Second),
}
config.Providers.Rest = &rest.Provider{
Insecure: true,
}
config.Providers.Rancher = &rancher.Provider{
Constraints: `Label("foo", "bar")`,
Watch: true,
DefaultRule: "PathPrefix(`/`)",
ExposedByDefault: true,
EnableServiceHealthFilter: true,
RefreshSeconds: 42,
IntervalPoll: true,
Prefix: "MyPrefix",
2019-03-14 18:32:03 +00:00
}
2020-10-30 11:44:05 +00:00
config.Providers.ConsulCatalog = &consulcatalog.Provider{
Constraints: `Label("foo", "bar")`,
Endpoint: &consulcatalog.EndpointConfig{
Address: "MyAddress",
Scheme: "MyScheme",
DataCenter: "MyDatacenter",
Token: "MyToken",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
HTTPAuth: &consulcatalog.EndpointHTTPAuthConfig{
Username: "MyUsername",
Password: "MyPassword",
},
EndpointWaitTime: 42,
},
Prefix: "MyPrefix",
RefreshInterval: 42,
RequireConsistent: true,
Stale: true,
Cache: true,
ExposedByDefault: true,
DefaultRule: "PathPrefix(`/`)",
}
config.Providers.Ecs = &ecs.Provider{
Constraints: `Label("foo", "bar")`,
ExposedByDefault: true,
RefreshSeconds: 42,
DefaultRule: "PathPrefix(`/`)",
Clusters: []string{"Cluster1", "Cluster2"},
AutoDiscoverClusters: true,
Region: "Awsregion",
AccessKeyID: "AwsAccessKeyID",
SecretAccessKey: "AwsSecretAccessKey",
}
config.Providers.Consul = &consul.Provider{
Provider: kv.Provider{
RootKey: "RootKey",
Endpoints: nil,
Username: "username",
Password: "password",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
},
}
config.Providers.Etcd = &etcd.Provider{
Provider: kv.Provider{
RootKey: "RootKey",
Endpoints: nil,
Username: "username",
Password: "password",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
},
}
config.Providers.ZooKeeper = &zk.Provider{
Provider: kv.Provider{
RootKey: "RootKey",
Endpoints: nil,
Username: "username",
Password: "password",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
},
}
config.Providers.Redis = &redis.Provider{
Provider: kv.Provider{
RootKey: "RootKey",
Endpoints: nil,
Username: "username",
Password: "password",
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
},
}
config.Providers.HTTP = &http.Provider{
Endpoint: "Myenpoint",
PollInterval: 42,
PollTimeout: 42,
TLS: &types.ClientTLS{
CA: "myCa",
CAOptional: true,
Cert: "mycert.pem",
Key: "mycert.key",
InsecureSkipVerify: true,
},
}
config.API = &static.API{
Insecure: true,
Dashboard: true,
Debug: true,
DashboardAssets: &assetfs.AssetFS{
Asset: func(path string) ([]byte, error) {
return nil, nil
},
AssetDir: func(path string) ([]string, error) {
return nil, nil
},
AssetInfo: func(path string) (os.FileInfo, error) {
return nil, nil
},
Prefix: "fii",
},
}
2017-10-02 08:32:02 +00:00
2019-03-14 18:32:03 +00:00
config.Metrics = &types.Metrics{
Prometheus: &types.Prometheus{
2020-10-30 11:44:05 +00:00
Buckets: []float64{0.1, 0.3, 1.2, 5},
AddEntryPointsLabels: true,
AddServicesLabels: true,
EntryPoint: "MyEntryPoint",
ManualRouting: true,
2019-03-14 18:32:03 +00:00
},
2019-09-02 10:18:04 +00:00
Datadog: &types.Datadog{
2020-10-30 11:44:05 +00:00
Address: "localhost:8181",
PushInterval: 42,
AddEntryPointsLabels: true,
AddServicesLabels: true,
2019-03-14 18:32:03 +00:00
},
StatsD: &types.Statsd{
2020-10-30 11:44:05 +00:00
Address: "localhost:8182",
PushInterval: 42,
AddEntryPointsLabels: true,
AddServicesLabels: true,
Prefix: "MyPrefix",
2019-03-14 18:32:03 +00:00
},
InfluxDB: &types.InfluxDB{
2020-10-30 11:44:05 +00:00
Address: "localhost:8183",
Protocol: "http",
PushInterval: 42,
Database: "myDB",
RetentionPolicy: "12",
Username: "a",
Password: "aaaa",
AddEntryPointsLabels: true,
AddServicesLabels: true,
2019-03-14 18:32:03 +00:00
},
}
2020-10-30 11:44:05 +00:00
config.Ping = &ping.Handler{
EntryPoint: "MyEntryPoint",
ManualRouting: true,
TerminatingStatusCode: 42,
}
config.Log = &types.TraefikLog{
Level: "Level",
FilePath: "/foo/path",
Format: "json",
}
config.AccessLog = &types.AccessLog{
FilePath: "AccessLog FilePath",
Format: "AccessLog Format",
Filters: &types.AccessLogFilters{
StatusCodes: []string{"200", "500"},
RetryAttempts: true,
MinDuration: 42,
},
Fields: &types.AccessLogFields{
DefaultMode: "drop",
Names: map[string]string{
"RequestHost": "keep",
},
Headers: &types.FieldHeaders{
DefaultMode: "drop",
Names: map[string]string{
"Referer": "keep",
},
},
},
BufferingSize: 42,
}
2019-03-14 18:32:03 +00:00
config.Tracing = &static.Tracing{
ServiceName: "myServiceName",
2020-10-30 11:44:05 +00:00
SpanNameLimit: 42,
2019-03-14 18:32:03 +00:00
Jaeger: &jaeger.Config{
2020-10-30 11:44:05 +00:00
SamplingServerURL: "foobar",
SamplingType: "foobar",
SamplingParam: 42,
LocalAgentHostPort: "foobar",
2019-03-14 18:32:03 +00:00
Gen128Bit: true,
2020-10-30 11:44:05 +00:00
Propagation: "foobar",
TraceContextHeaderName: "foobar",
Collector: &jaeger.Collector{
Endpoint: "foobar",
User: "foobar",
Password: "foobar",
},
DisableAttemptReconnecting: true,
2019-03-14 18:32:03 +00:00
},
Zipkin: &zipkin.Config{
2020-10-30 11:44:05 +00:00
HTTPEndpoint: "foobar",
2019-03-14 18:32:03 +00:00
SameSpan: true,
ID128Bit: true,
2020-10-30 11:44:05 +00:00
SampleRate: 42,
2019-03-14 18:32:03 +00:00
},
2019-09-02 10:18:04 +00:00
Datadog: &datadog.Config{
2020-10-30 11:44:05 +00:00
LocalAgentHostPort: "foobar",
GlobalTag: "foobar",
Debug: true,
PrioritySampling: true,
TraceIDHeaderName: "foobar",
ParentIDHeaderName: "foobar",
SamplingPriorityHeaderName: "foobar",
BagagePrefixHeaderName: "foobar",
2019-03-14 18:32:03 +00:00
},
Instana: &instana.Config{
2020-10-30 11:44:05 +00:00
LocalAgentHost: "foobar",
LocalAgentPort: 4242,
LogLevel: "foobar",
2019-03-14 18:32:03 +00:00
},
2019-06-27 22:16:04 +00:00
Haystack: &haystack.Config{
2020-10-30 11:44:05 +00:00
LocalAgentHost: "foobar",
LocalAgentPort: 42,
GlobalTag: "foobar",
TraceIDHeaderName: "foobar",
ParentIDHeaderName: "foobar",
SpanIDHeaderName: "foobar",
BaggagePrefixHeaderName: "foobar",
},
Elastic: &elastic.Config{
ServerURL: "foobar",
SecretToken: "foobar",
ServiceEnvironment: "foobar",
2019-06-27 22:16:04 +00:00
},
2019-03-14 18:32:03 +00:00
}
config.HostResolver = &types.HostResolverConfig{
CnameFlattening: true,
2020-10-30 11:44:05 +00:00
ResolvConfig: "foobar",
ResolvDepth: 42,
2019-03-14 18:32:03 +00:00
}
2020-10-30 11:44:05 +00:00
config.CertificatesResolvers = map[string]static.CertificateResolver{
"CertificateResolver0": {
ACME: &acme.Configuration{
Email: "acme Email",
CAServer: "CAServer",
PreferredChain: "foobar",
Storage: "Storage",
KeyType: "MyKeyType",
DNSChallenge: &acme.DNSChallenge{
Provider: "DNSProvider",
DelayBeforeCheck: 42,
Resolvers: []string{"resolver1", "resolver2"},
DisablePropagationCheck: true,
},
HTTPChallenge: &acme.HTTPChallenge{
EntryPoint: "MyEntryPoint",
},
TLSChallenge: &acme.TLSChallenge{},
},
},
}
config.Pilot = &static.Pilot{
Token: "token",
}
config.Experimental = &static.Experimental{
Plugins: map[string]plugins.Descriptor{
"Descriptor0": {
ModuleName: "foobar",
Version: "foobar",
},
"Descriptor1": {
ModuleName: "foobar",
Version: "foobar",
},
},
DevPlugin: &plugins.DevPlugin{
GoPath: "foobar",
ModuleName: "foobar",
},
}
expectedConfiguration, err := ioutil.ReadFile("./testdata/anonymized-static-config.json")
require.NoError(t, err)
2017-10-02 08:32:02 +00:00
cleanJSON, err := Do(config, true)
2020-10-30 11:44:05 +00:00
require.NoError(t, err)
if *updateExpected {
require.NoError(t, ioutil.WriteFile("testdata/anonymized-static-config.json", []byte(cleanJSON), 0666))
2017-10-02 08:32:02 +00:00
}
2020-10-30 11:44:05 +00:00
expected := strings.TrimSuffix(string(expectedConfiguration), "\n")
assert.Equal(t, expected, cleanJSON)
2017-10-02 08:32:02 +00:00
}