2018-09-27 02:43:26 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2018-09-27 02:43:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMaskURLCredentials(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
rawURL string
|
|
|
|
maskedURL string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
rawURL: "",
|
|
|
|
maskedURL: "",
|
|
|
|
}, {
|
|
|
|
rawURL: "invalidURL",
|
|
|
|
maskedURL: "invalidURL",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://proxy.example.com:80/",
|
|
|
|
maskedURL: "http://proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER:PASSWORD@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://PASSWORD:PASSWORD@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER:@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://:PASSWORD@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER@docker:password@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER%40docker:password@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER%40docker:pa%3Fsword@proxy.example.com:80/",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
|
|
|
|
}, {
|
|
|
|
rawURL: "http://USER%40docker:pa%3Fsword@proxy.example.com:80/hello%20world",
|
|
|
|
maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/hello%20world",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
maskedURL := maskCredentials(test.rawURL)
|
|
|
|
assert.Equal(t, maskedURL, test.maskedURL)
|
|
|
|
}
|
|
|
|
}
|