github.com/nak3/source-to-image@v1.1.10-0.20180319140719-2ed55639898d/pkg/util/env_test.go (about) 1 package util 2 3 import ( 4 "testing" 5 ) 6 7 func TestStripProxyCredentials(t *testing.T) { 8 9 inputs := []string{ 10 // values w/o protocols are untouched 11 "http_proxy=user:password@hostname.com", 12 "https_proxy=user:password@hostname.com", 13 "HTTP_PROXY=user:password@hostname.com", 14 "HTTPS_PROXY=user:password@hostname.com", 15 // values with protocol are properly stripped 16 "http_proxy=http://user:password@hostname.com", 17 "https_proxy=https://user:password@hostname.com", 18 "HTTP_PROXY=http://user:password@hostname.com", 19 "HTTPS_PROXY=https://user:password@hostname.com", 20 "http_proxy=http://user:password@hostname.com:80", 21 "https_proxy=https://user:password@hostname.com:443", 22 "HTTP_PROXY=http://user:password@hostname.com:8080", 23 "HTTPS_PROXY=https://user:password@hostname.com:8443", 24 // values with no user info are untouched 25 "http_proxy=http://hostname.com", 26 "https_proxy=https://hostname.com", 27 "HTTP_PROXY=http://hostname.com", 28 "HTTPS_PROXY=https://hostname.com", 29 // keys that don't contain "proxy" are untouched 30 "othervalue=http://user:password@hostname.com", 31 "othervalue=user:password@hostname.com", 32 // unparseable url 33 "proxy=https://user:password@foo%$ @bar@blah.com", 34 } 35 36 expected := []string{ 37 "http_proxy=user:password@hostname.com", 38 "https_proxy=user:password@hostname.com", 39 "HTTP_PROXY=user:password@hostname.com", 40 "HTTPS_PROXY=user:password@hostname.com", 41 "http_proxy=http://redacted@hostname.com", 42 "https_proxy=https://redacted@hostname.com", 43 "HTTP_PROXY=http://redacted@hostname.com", 44 "HTTPS_PROXY=https://redacted@hostname.com", 45 "http_proxy=http://redacted@hostname.com:80", 46 "https_proxy=https://redacted@hostname.com:443", 47 "HTTP_PROXY=http://redacted@hostname.com:8080", 48 "HTTPS_PROXY=https://redacted@hostname.com:8443", 49 "http_proxy=http://redacted@hostname.com", 50 "https_proxy=https://redacted@hostname.com", 51 "HTTP_PROXY=http://redacted@hostname.com", 52 "HTTPS_PROXY=https://redacted@hostname.com", 53 "othervalue=http://user:password@hostname.com", 54 "othervalue=user:password@hostname.com", 55 "proxy=https://user:password@foo%$ @bar@blah.com", 56 } 57 result := SafeForLoggingEnv(inputs) 58 for i := range result { 59 if result[i] != expected[i] { 60 t.Errorf("expected %s to be stripped to %s, but got %s", inputs[i], expected[i], result[i]) 61 } 62 } 63 }