github.imxd.top/openshift/source-to-image@v1.2.0/pkg/util/util_test.go (about) 1 package util 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/docker/docker/api/types/container" 9 ) 10 11 func TestSafeForLoggingContainerConfig(t *testing.T) { 12 c := &container.Config{ 13 Env: []string{ 14 "http_proxy=http://user:password@hostname.com", 15 "https_proxy=https://user:password@hostname.com", 16 "HTTP_PROXY=HTTP://user:password@hostname.com", 17 "HTTPS_PROXY=HTTPS://user:password@hostname.com", 18 }, 19 } 20 orig := fmt.Sprintf("%+v", *c) 21 22 s := fmt.Sprintf("%+v", *SafeForLoggingContainerConfig(c)) 23 if strings.Contains(s, "user:password") { 24 t.Errorf("expected %s to not contain credentials", s) 25 } 26 27 if !strings.Contains(s, "redacted") { 28 t.Errorf("expected %s to be redacted", s) 29 } 30 31 // make sure the original object was not changed 32 s = fmt.Sprintf("%+v", *c) 33 if !(s == orig) { 34 t.Errorf("expected original %s to be unchanged, got %s", orig, s) 35 } 36 37 }