traefik/anonymize/anonymize_config_test.go

330 lines
8.6 KiB
Go
Raw Normal View History

2017-10-02 08:32:02 +00:00
package anonymize
import (
2018-10-01 17:18:03 +00:00
"os"
2017-10-02 08:32:02 +00:00
"testing"
"time"
2018-07-31 17:28:03 +00:00
"github.com/containous/flaeg/parse"
"github.com/containous/traefik/config/static"
2019-03-14 18:32:03 +00:00
"github.com/containous/traefik/ping"
"github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/acme"
acmeprovider "github.com/containous/traefik/provider/acme"
2019-03-14 18:32:03 +00:00
"github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/file"
2019-03-14 18:32:03 +00:00
"github.com/containous/traefik/provider/kubernetes/crd"
"github.com/containous/traefik/provider/kubernetes/ingress"
traefiktls "github.com/containous/traefik/tls"
2019-03-14 18:32:03 +00:00
"github.com/containous/traefik/tracing/datadog"
"github.com/containous/traefik/tracing/instana"
"github.com/containous/traefik/tracing/jaeger"
"github.com/containous/traefik/tracing/zipkin"
"github.com/containous/traefik/types"
2019-02-18 06:52:03 +00:00
assetfs "github.com/elazarl/go-bindata-assetfs"
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
2019-03-14 18:32:03 +00:00
sendAnonymousUsage := true
config.Global = &static.Global{
Debug: true,
CheckNewVersion: true,
2019-03-14 18:32:03 +00:00
SendAnonymousUsage: &sendAnonymousUsage,
}
2019-03-14 18:32:03 +00:00
2017-10-02 08:32:02 +00:00
config.AccessLog = &types.AccessLog{
FilePath: "AccessLog FilePath",
Format: "AccessLog Format",
2019-03-14 18:32:03 +00:00
Filters: &types.AccessLogFilters{
StatusCodes: types.StatusCodes{"200", "500"},
RetryAttempts: true,
MinDuration: 10,
},
Fields: &types.AccessLogFields{
DefaultMode: "drop",
Names: types.FieldNames{
"RequestHost": "keep",
},
Headers: &types.FieldHeaders{
DefaultMode: "drop",
Names: types.FieldHeaderNames{
"Referer": "keep",
},
},
},
BufferingSize: 4,
2017-10-02 08:32:02 +00:00
}
2019-03-14 18:32:03 +00:00
config.Log = &types.TraefikLog{
LogLevel: "LogLevel",
FilePath: "/foo/path",
Format: "json",
}
2019-03-14 18:32:03 +00:00
config.EntryPoints = static.EntryPoints{
2017-10-02 08:32:02 +00:00
"foo": {
Address: "foo Address",
Transport: &static.EntryPointsTransport{
RespondingTimeouts: &static.RespondingTimeouts{
ReadTimeout: parse.Duration(111 * time.Second),
WriteTimeout: parse.Duration(111 * time.Second),
IdleTimeout: parse.Duration(111 * time.Second),
},
},
ProxyProtocol: &static.ProxyProtocol{
2017-10-10 12:50:03 +00:00
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
2017-10-02 08:32:02 +00:00
},
"fii": {
Address: "fii Address",
Transport: &static.EntryPointsTransport{
RespondingTimeouts: &static.RespondingTimeouts{
ReadTimeout: parse.Duration(111 * time.Second),
WriteTimeout: parse.Duration(111 * time.Second),
IdleTimeout: parse.Duration(111 * time.Second),
},
},
ProxyProtocol: &static.ProxyProtocol{
2017-10-10 12:50:03 +00:00
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
2017-10-02 08:32:02 +00:00
},
}
config.ACME = &acme.Configuration{
2019-03-14 18:32:03 +00:00
Email: "acme Email",
ACMELogging: true,
CAServer: "CAServer",
Storage: "Storage",
EntryPoint: "EntryPoint",
KeyType: "MyKeyType",
OnHostRule: true,
DNSChallenge: &acmeprovider.DNSChallenge{Provider: "DNSProvider"},
HTTPChallenge: &acmeprovider.HTTPChallenge{
EntryPoint: "MyEntryPoint",
},
TLSChallenge: &acmeprovider.TLSChallenge{},
2018-03-05 19:54:04 +00:00
Domains: []types.Domain{
2017-10-02 08:32:02 +00:00
{
Main: "Domains Main",
SANs: []string{"Domains acme SANs 1", "Domains acme SANs 2", "Domains acme SANs 3"},
},
},
}
config.Providers = &static.Providers{
ProvidersThrottleDuration: parse.Duration(111 * time.Second),
2017-10-02 08:32:02 +00:00
}
config.ServersTransport = &static.ServersTransport{
InsecureSkipVerify: true,
RootCAs: traefiktls.FilesOrContents{"RootCAs 1", "RootCAs 2", "RootCAs 3"},
MaxIdleConnsPerHost: 111,
ForwardingTimeouts: &static.ForwardingTimeouts{
DialTimeout: parse.Duration(111 * time.Second),
ResponseHeaderTimeout: parse.Duration(111 * time.Second),
},
2017-10-02 08:32:02 +00:00
}
config.API = &static.API{
EntryPoint: "traefik",
Dashboard: true,
2018-10-01 17:18:03 +00:00
Statistics: &types.Statistics{
RecentErrors: 111,
2018-10-01 17:18:03 +00:00
},
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",
},
Middlewares: []string{"first", "second"},
2018-10-01 17:18:03 +00:00
}
config.Providers.File = &file.Provider{
2017-10-02 08:32:02 +00:00
BaseProvider: provider.BaseProvider{
Watch: true,
Filename: "file Filename",
Constraints: types.Constraints{
{
Key: "file Constraints Key 1",
Regex: "file Constraints Regex 2",
MustMatch: true,
},
{
Key: "file Constraints Key 1",
Regex: "file Constraints Regex 2",
MustMatch: true,
},
},
2018-09-07 07:40:03 +00:00
Trace: true,
2017-10-02 08:32:02 +00:00
DebugLogGeneratedTemplate: true,
},
Directory: "file Directory",
}
2019-03-14 18:32:03 +00:00
config.Providers.Docker = &docker.Provider{
BaseProvider: provider.BaseProvider{
Watch: true,
Filename: "myfilename",
Constraints: nil,
Trace: true,
DebugLogGeneratedTemplate: true,
},
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,
}
config.Providers.Kubernetes = &ingress.Provider{
BaseProvider: provider.BaseProvider{
Watch: true,
Filename: "myFileName",
Constraints: types.Constraints{
{
Key: "k8s Constraints Key 1",
Regex: "k8s Constraints Regex 2",
MustMatch: true,
},
{
Key: "k8s Constraints Key 1",
Regex: "k8s Constraints Regex 2",
MustMatch: true,
},
},
Trace: true,
DebugLogGeneratedTemplate: true,
},
Endpoint: "MyEndpoint",
Token: "MyToken",
CertAuthFilePath: "MyCertAuthPath",
DisablePassHostHeaders: true,
EnablePassTLSCert: true,
Namespaces: []string{"a", "b"},
LabelSelector: "myLabelSelector",
IngressClass: "MyIngressClass",
}
config.Providers.KubernetesCRD = &crd.Provider{
BaseProvider: provider.BaseProvider{
Watch: true,
Filename: "myFileName",
Constraints: types.Constraints{
{
Key: "k8s Constraints Key 1",
Regex: "k8s Constraints Regex 2",
MustMatch: true,
},
{
Key: "k8s Constraints Key 1",
Regex: "k8s Constraints Regex 2",
MustMatch: true,
},
},
Trace: true,
DebugLogGeneratedTemplate: true,
},
Endpoint: "MyEndpoint",
Token: "MyToken",
CertAuthFilePath: "MyCertAuthPath",
DisablePassHostHeaders: true,
EnablePassTLSCert: true,
Namespaces: []string{"a", "b"},
LabelSelector: "myLabelSelector",
IngressClass: "MyIngressClass",
}
// FIXME Test the other providers once they are migrated
2017-10-02 08:32:02 +00:00
2019-03-14 18:32:03 +00:00
config.Metrics = &types.Metrics{
Prometheus: &types.Prometheus{
Buckets: types.Buckets{0.1, 0.3, 1.2, 5},
EntryPoint: "MyEntryPoint",
Middlewares: []string{"m1", "m2"},
},
Datadog: &types.Datadog{
Address: "localhost:8181",
PushInterval: "12",
},
StatsD: &types.Statsd{
Address: "localhost:8182",
PushInterval: "42",
},
InfluxDB: &types.InfluxDB{
Address: "localhost:8183",
Protocol: "http",
PushInterval: "22",
Database: "myDB",
RetentionPolicy: "12",
Username: "a",
Password: "aaaa",
},
}
config.Ping = &ping.Handler{
EntryPoint: "MyEntryPoint",
Middlewares: []string{"m1", "m2", "m3"},
}
config.Tracing = &static.Tracing{
Backend: "myBackend",
ServiceName: "myServiceName",
SpanNameLimit: 3,
Jaeger: &jaeger.Config{
SamplingServerURL: "aaa",
SamplingType: "bbb",
SamplingParam: 43,
LocalAgentHostPort: "ccc",
Gen128Bit: true,
Propagation: "ddd",
TraceContextHeaderName: "eee",
},
Zipkin: &zipkin.Config{
HTTPEndpoint: "fff",
SameSpan: true,
ID128Bit: true,
Debug: true,
SampleRate: 53,
},
DataDog: &datadog.Config{
LocalAgentHostPort: "ggg",
GlobalTag: "eee",
Debug: true,
PrioritySampling: true,
},
Instana: &instana.Config{
LocalAgentHost: "fff",
LocalAgentPort: 32,
LogLevel: "ggg",
},
}
config.HostResolver = &types.HostResolverConfig{
CnameFlattening: true,
ResolvConfig: "aaa",
ResolvDepth: 3,
}
2017-10-02 08:32:02 +00:00
cleanJSON, err := Do(config, true)
if err != nil {
t.Fatal(err, cleanJSON)
}
}