traefik/cmd/bug/bug_test.go

68 lines
1.9 KiB
Go
Raw Normal View History

2018-03-01 07:10:04 +00:00
package bug
2017-08-23 22:59:01 +00:00
import (
"testing"
2017-10-02 08:32:02 +00:00
2018-03-01 07:10:04 +00:00
"github.com/containous/traefik/anonymize"
"github.com/containous/traefik/cmd"
2018-11-14 09:18:03 +00:00
"github.com/containous/traefik/old/configuration"
"github.com/containous/traefik/old/provider/file"
"github.com/containous/traefik/old/types"
"github.com/containous/traefik/tls"
2017-10-02 08:32:02 +00:00
"github.com/stretchr/testify/assert"
2017-08-23 22:59:01 +00:00
)
2018-03-01 07:10:04 +00:00
func Test_createReport(t *testing.T) {
traefikConfiguration := &cmd.TraefikConfiguration{
2017-10-02 08:32:02 +00:00
ConfigFile: "FOO",
GlobalConfiguration: configuration.GlobalConfiguration{
EntryPoints: configuration.EntryPoints{
"goo": &configuration.EntryPoint{
Address: "hoo.bar",
2018-01-02 09:14:03 +00:00
Auth: &types.Auth{
Basic: &types.Basic{
UsersFile: "foo Basic UsersFile",
Users: types.Users{"foo Basic Users 1", "foo Basic Users 2", "foo Basic Users 3"},
},
Digest: &types.Digest{
UsersFile: "foo Digest UsersFile",
Users: types.Users{"foo Digest Users 1", "foo Digest Users 2", "foo Digest Users 3"},
},
},
2017-10-02 08:32:02 +00:00
},
},
File: &file.Provider{
Directory: "BAR",
},
2018-08-29 09:36:03 +00:00
RootCAs: tls.FilesOrContents{"fllf"},
2017-10-02 08:32:02 +00:00
},
}
2018-03-01 07:10:04 +00:00
report, err := createReport(traefikConfiguration)
2017-10-02 08:32:02 +00:00
assert.NoError(t, err, report)
2018-01-02 09:14:03 +00:00
// exported anonymous configuration
assert.NotContains(t, "web Basic Users ", report)
assert.NotContains(t, "foo Digest Users ", report)
assert.NotContains(t, "hoo.bar", report)
2017-08-23 22:59:01 +00:00
}
2017-10-02 08:32:02 +00:00
func Test_anonymize_traefikConfiguration(t *testing.T) {
2018-03-01 07:10:04 +00:00
traefikConfiguration := &cmd.TraefikConfiguration{
2017-10-02 08:32:02 +00:00
ConfigFile: "FOO",
GlobalConfiguration: configuration.GlobalConfiguration{
EntryPoints: configuration.EntryPoints{
"goo": &configuration.EntryPoint{
Address: "hoo.bar",
},
},
File: &file.Provider{
Directory: "BAR",
},
},
2017-08-23 22:59:01 +00:00
}
2017-10-02 08:32:02 +00:00
_, err := anonymize.Do(traefikConfiguration, true)
assert.NoError(t, err)
assert.Equal(t, "hoo.bar", traefikConfiguration.GlobalConfiguration.EntryPoints["goo"].Address)
2017-08-23 22:59:01 +00:00
}