config_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. package config // import "github.com/docker/docker/daemon/config"
  2. import (
  3. "os"
  4. "reflect"
  5. "strings"
  6. "testing"
  7. "github.com/docker/docker/libnetwork/ipamutils"
  8. "github.com/docker/docker/opts"
  9. "github.com/google/go-cmp/cmp"
  10. "github.com/google/go-cmp/cmp/cmpopts"
  11. "github.com/imdario/mergo"
  12. "github.com/spf13/pflag"
  13. "gotest.tools/v3/assert"
  14. is "gotest.tools/v3/assert/cmp"
  15. "gotest.tools/v3/fs"
  16. "gotest.tools/v3/skip"
  17. )
  18. func TestDaemonConfigurationNotFound(t *testing.T) {
  19. _, err := MergeDaemonConfigurations(&Config{}, nil, "/tmp/foo-bar-baz-docker")
  20. assert.Check(t, os.IsNotExist(err), "got: %[1]T: %[1]v", err)
  21. }
  22. func TestDaemonBrokenConfiguration(t *testing.T) {
  23. f, err := os.CreateTemp("", "docker-config-")
  24. assert.NilError(t, err)
  25. configFile := f.Name()
  26. f.Write([]byte(`{"Debug": tru`))
  27. f.Close()
  28. _, err = MergeDaemonConfigurations(&Config{}, nil, configFile)
  29. assert.ErrorContains(t, err, `invalid character ' ' in literal true`)
  30. }
  31. func TestFindConfigurationConflicts(t *testing.T) {
  32. config := map[string]interface{}{"authorization-plugins": "foobar"}
  33. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  34. flags.String("authorization-plugins", "", "")
  35. assert.Check(t, flags.Set("authorization-plugins", "asdf"))
  36. assert.Check(t, is.ErrorContains(findConfigurationConflicts(config, flags), "authorization-plugins: (from flag: asdf, from file: foobar)"))
  37. }
  38. func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) {
  39. config := map[string]interface{}{"hosts": []string{"qwer"}}
  40. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  41. var hosts []string
  42. flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to")
  43. assert.Check(t, flags.Set("host", "tcp://127.0.0.1:4444"))
  44. assert.Check(t, flags.Set("host", "unix:///var/run/docker.sock"))
  45. assert.Check(t, is.ErrorContains(findConfigurationConflicts(config, flags), "hosts"))
  46. }
  47. func TestDaemonConfigurationMergeConflicts(t *testing.T) {
  48. f, err := os.CreateTemp("", "docker-config-")
  49. assert.NilError(t, err)
  50. configFile := f.Name()
  51. f.Write([]byte(`{"debug": true}`))
  52. f.Close()
  53. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  54. flags.Bool("debug", false, "")
  55. assert.Check(t, flags.Set("debug", "false"))
  56. _, err = MergeDaemonConfigurations(&Config{}, flags, configFile)
  57. if err == nil {
  58. t.Fatal("expected error, got nil")
  59. }
  60. if !strings.Contains(err.Error(), "debug") {
  61. t.Fatalf("expected debug conflict, got %v", err)
  62. }
  63. }
  64. func TestDaemonConfigurationMergeConcurrent(t *testing.T) {
  65. f, err := os.CreateTemp("", "docker-config-")
  66. assert.NilError(t, err)
  67. configFile := f.Name()
  68. f.Write([]byte(`{"max-concurrent-downloads": 1}`))
  69. f.Close()
  70. _, err = MergeDaemonConfigurations(&Config{}, nil, configFile)
  71. assert.NilError(t, err)
  72. }
  73. func TestDaemonConfigurationMergeConcurrentError(t *testing.T) {
  74. f, err := os.CreateTemp("", "docker-config-")
  75. assert.NilError(t, err)
  76. configFile := f.Name()
  77. f.Write([]byte(`{"max-concurrent-downloads": -1}`))
  78. f.Close()
  79. _, err = MergeDaemonConfigurations(&Config{}, nil, configFile)
  80. assert.ErrorContains(t, err, `invalid max concurrent downloads: -1`)
  81. }
  82. func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) {
  83. f, err := os.CreateTemp("", "docker-config-")
  84. assert.NilError(t, err)
  85. configFile := f.Name()
  86. f.Write([]byte(`{"tlscacert": "/etc/certificates/ca.pem"}`))
  87. f.Close()
  88. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  89. flags.String("tlscacert", "", "")
  90. assert.Check(t, flags.Set("tlscacert", "~/.docker/ca.pem"))
  91. _, err = MergeDaemonConfigurations(&Config{}, flags, configFile)
  92. assert.ErrorContains(t, err, `the following directives are specified both as a flag and in the configuration file: tlscacert`)
  93. }
  94. // Test for #40711
  95. func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) {
  96. emptyConfigFile := fs.NewFile(t, "config", fs.WithContent(`{}`))
  97. defer emptyConfigFile.Remove()
  98. configFile := fs.NewFile(t, "config", fs.WithContent(`{"default-address-pools":[{"base": "10.123.0.0/16", "size": 24 }]}`))
  99. defer configFile.Remove()
  100. expected := []*ipamutils.NetworkToSplit{{Base: "10.123.0.0/16", Size: 24}}
  101. t.Run("empty config file", func(t *testing.T) {
  102. var conf = Config{}
  103. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  104. flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "")
  105. assert.Check(t, flags.Set("default-address-pool", "base=10.123.0.0/16,size=24"))
  106. config, err := MergeDaemonConfigurations(&conf, flags, emptyConfigFile.Path())
  107. assert.NilError(t, err)
  108. assert.DeepEqual(t, config.DefaultAddressPools.Value(), expected)
  109. })
  110. t.Run("config file", func(t *testing.T) {
  111. var conf = Config{}
  112. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  113. flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "")
  114. config, err := MergeDaemonConfigurations(&conf, flags, configFile.Path())
  115. assert.NilError(t, err)
  116. assert.DeepEqual(t, config.DefaultAddressPools.Value(), expected)
  117. })
  118. t.Run("with conflicting options", func(t *testing.T) {
  119. var conf = Config{}
  120. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  121. flags.Var(&conf.NetworkConfig.DefaultAddressPools, "default-address-pool", "")
  122. assert.Check(t, flags.Set("default-address-pool", "base=10.123.0.0/16,size=24"))
  123. _, err := MergeDaemonConfigurations(&conf, flags, configFile.Path())
  124. assert.ErrorContains(t, err, "the following directives are specified both as a flag and in the configuration file")
  125. assert.ErrorContains(t, err, "default-address-pools")
  126. })
  127. }
  128. func TestFindConfigurationConflictsWithUnknownKeys(t *testing.T) {
  129. config := map[string]interface{}{"tls-verify": "true"}
  130. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  131. flags.Bool("tlsverify", false, "")
  132. err := findConfigurationConflicts(config, flags)
  133. assert.ErrorContains(t, err, "the following directives don't match any configuration option: tls-verify")
  134. }
  135. func TestFindConfigurationConflictsWithMergedValues(t *testing.T) {
  136. var hosts []string
  137. config := map[string]interface{}{"hosts": "tcp://127.0.0.1:2345"}
  138. flags := pflag.NewFlagSet("base", pflag.ContinueOnError)
  139. flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, nil), "host", "H", "")
  140. err := findConfigurationConflicts(config, flags)
  141. assert.NilError(t, err)
  142. assert.Check(t, flags.Set("host", "unix:///var/run/docker.sock"))
  143. err = findConfigurationConflicts(config, flags)
  144. assert.ErrorContains(t, err, "hosts: (from flag: [unix:///var/run/docker.sock], from file: tcp://127.0.0.1:2345)")
  145. }
  146. func TestValidateConfigurationErrors(t *testing.T) {
  147. testCases := []struct {
  148. name string
  149. field string
  150. config *Config
  151. expectedErr string
  152. }{
  153. {
  154. name: "single label without value",
  155. config: &Config{
  156. CommonConfig: CommonConfig{
  157. Labels: []string{"one"},
  158. },
  159. },
  160. expectedErr: "bad attribute format: one",
  161. },
  162. {
  163. name: "multiple label without value",
  164. config: &Config{
  165. CommonConfig: CommonConfig{
  166. Labels: []string{"foo=bar", "one"},
  167. },
  168. },
  169. expectedErr: "bad attribute format: one",
  170. },
  171. {
  172. name: "single DNS, invalid IP-address",
  173. config: &Config{
  174. CommonConfig: CommonConfig{
  175. DNSConfig: DNSConfig{
  176. DNS: []string{"1.1.1.1o"},
  177. },
  178. },
  179. },
  180. expectedErr: "1.1.1.1o is not an ip address",
  181. },
  182. {
  183. name: "multiple DNS, invalid IP-address",
  184. config: &Config{
  185. CommonConfig: CommonConfig{
  186. DNSConfig: DNSConfig{
  187. DNS: []string{"2.2.2.2", "1.1.1.1o"},
  188. },
  189. },
  190. },
  191. expectedErr: "1.1.1.1o is not an ip address",
  192. },
  193. {
  194. name: "single DNSSearch",
  195. config: &Config{
  196. CommonConfig: CommonConfig{
  197. DNSConfig: DNSConfig{
  198. DNSSearch: []string{"123456"},
  199. },
  200. },
  201. },
  202. expectedErr: "123456 is not a valid domain",
  203. },
  204. {
  205. name: "multiple DNSSearch",
  206. config: &Config{
  207. CommonConfig: CommonConfig{
  208. DNSConfig: DNSConfig{
  209. DNSSearch: []string{"a.b.c", "123456"},
  210. },
  211. },
  212. },
  213. expectedErr: "123456 is not a valid domain",
  214. },
  215. {
  216. name: "negative MTU",
  217. config: &Config{
  218. CommonConfig: CommonConfig{
  219. Mtu: -10,
  220. },
  221. },
  222. expectedErr: "invalid default MTU: -10",
  223. },
  224. {
  225. name: "negative max-concurrent-downloads",
  226. config: &Config{
  227. CommonConfig: CommonConfig{
  228. MaxConcurrentDownloads: -10,
  229. },
  230. },
  231. expectedErr: "invalid max concurrent downloads: -10",
  232. },
  233. {
  234. name: "negative max-concurrent-uploads",
  235. config: &Config{
  236. CommonConfig: CommonConfig{
  237. MaxConcurrentUploads: -10,
  238. },
  239. },
  240. expectedErr: "invalid max concurrent uploads: -10",
  241. },
  242. {
  243. name: "negative max-download-attempts",
  244. config: &Config{
  245. CommonConfig: CommonConfig{
  246. MaxDownloadAttempts: -10,
  247. },
  248. },
  249. expectedErr: "invalid max download attempts: -10",
  250. },
  251. // TODO(thaJeztah) temporarily excluding this test as it assumes defaults are set before validating and applying updated configs
  252. /*
  253. {
  254. name: "zero max-download-attempts",
  255. field: "MaxDownloadAttempts",
  256. config: &Config{
  257. CommonConfig: CommonConfig{
  258. MaxDownloadAttempts: 0,
  259. },
  260. },
  261. expectedErr: "invalid max download attempts: 0",
  262. },
  263. */
  264. {
  265. name: "generic resource without =",
  266. config: &Config{
  267. CommonConfig: CommonConfig{
  268. NodeGenericResources: []string{"foo"},
  269. },
  270. },
  271. expectedErr: "could not parse GenericResource: incorrect term foo, missing '=' or malformed expression",
  272. },
  273. {
  274. name: "generic resource mixed named and discrete",
  275. config: &Config{
  276. CommonConfig: CommonConfig{
  277. NodeGenericResources: []string{"foo=bar", "foo=1"},
  278. },
  279. },
  280. expectedErr: "could not parse GenericResource: mixed discrete and named resources in expression 'foo=[bar 1]'",
  281. },
  282. {
  283. name: "with invalid hosts",
  284. config: &Config{
  285. CommonConfig: CommonConfig{
  286. Hosts: []string{"127.0.0.1:2375/path"},
  287. },
  288. },
  289. expectedErr: "invalid bind address (127.0.0.1:2375/path): should not contain a path element",
  290. },
  291. {
  292. name: "with invalid log-level",
  293. config: &Config{
  294. CommonConfig: CommonConfig{
  295. LogLevel: "foobar",
  296. },
  297. },
  298. expectedErr: "invalid logging level: foobar",
  299. },
  300. }
  301. for _, tc := range testCases {
  302. t.Run(tc.name, func(t *testing.T) {
  303. cfg, err := New()
  304. assert.NilError(t, err)
  305. if tc.field != "" {
  306. assert.Check(t, mergo.Merge(cfg, tc.config, mergo.WithOverride, withForceOverwrite(tc.field)))
  307. } else {
  308. assert.Check(t, mergo.Merge(cfg, tc.config, mergo.WithOverride))
  309. }
  310. err = Validate(cfg)
  311. assert.Error(t, err, tc.expectedErr)
  312. })
  313. }
  314. }
  315. func withForceOverwrite(fieldName string) func(config *mergo.Config) {
  316. return mergo.WithTransformers(overwriteTransformer{fieldName: fieldName})
  317. }
  318. type overwriteTransformer struct {
  319. fieldName string
  320. }
  321. func (tf overwriteTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
  322. if typ == reflect.TypeOf(CommonConfig{}) {
  323. return func(dst, src reflect.Value) error {
  324. dst.FieldByName(tf.fieldName).Set(src.FieldByName(tf.fieldName))
  325. return nil
  326. }
  327. }
  328. return nil
  329. }
  330. func TestValidateConfiguration(t *testing.T) {
  331. testCases := []struct {
  332. name string
  333. field string
  334. config *Config
  335. }{
  336. {
  337. name: "with label",
  338. field: "Labels",
  339. config: &Config{
  340. CommonConfig: CommonConfig{
  341. Labels: []string{"one=two"},
  342. },
  343. },
  344. },
  345. {
  346. name: "with dns",
  347. field: "DNSConfig",
  348. config: &Config{
  349. CommonConfig: CommonConfig{
  350. DNSConfig: DNSConfig{
  351. DNS: []string{"1.1.1.1"},
  352. },
  353. },
  354. },
  355. },
  356. {
  357. name: "with dns-search",
  358. field: "DNSConfig",
  359. config: &Config{
  360. CommonConfig: CommonConfig{
  361. DNSConfig: DNSConfig{
  362. DNSSearch: []string{"a.b.c"},
  363. },
  364. },
  365. },
  366. },
  367. {
  368. name: "with mtu",
  369. field: "Mtu",
  370. config: &Config{
  371. CommonConfig: CommonConfig{
  372. Mtu: 1234,
  373. },
  374. },
  375. },
  376. {
  377. name: "with max-concurrent-downloads",
  378. field: "MaxConcurrentDownloads",
  379. config: &Config{
  380. CommonConfig: CommonConfig{
  381. MaxConcurrentDownloads: 4,
  382. },
  383. },
  384. },
  385. {
  386. name: "with max-concurrent-uploads",
  387. field: "MaxConcurrentUploads",
  388. config: &Config{
  389. CommonConfig: CommonConfig{
  390. MaxConcurrentUploads: 4,
  391. },
  392. },
  393. },
  394. {
  395. name: "with max-download-attempts",
  396. field: "MaxDownloadAttempts",
  397. config: &Config{
  398. CommonConfig: CommonConfig{
  399. MaxDownloadAttempts: 4,
  400. },
  401. },
  402. },
  403. {
  404. name: "with multiple node generic resources",
  405. field: "NodeGenericResources",
  406. config: &Config{
  407. CommonConfig: CommonConfig{
  408. NodeGenericResources: []string{"foo=bar", "foo=baz"},
  409. },
  410. },
  411. },
  412. {
  413. name: "with node generic resources",
  414. field: "NodeGenericResources",
  415. config: &Config{
  416. CommonConfig: CommonConfig{
  417. NodeGenericResources: []string{"foo=1"},
  418. },
  419. },
  420. },
  421. {
  422. name: "with hosts",
  423. field: "Hosts",
  424. config: &Config{
  425. CommonConfig: CommonConfig{
  426. Hosts: []string{"tcp://127.0.0.1:2375"},
  427. },
  428. },
  429. },
  430. {
  431. name: "with log-level warn",
  432. field: "LogLevel",
  433. config: &Config{
  434. CommonConfig: CommonConfig{
  435. LogLevel: "warn",
  436. },
  437. },
  438. },
  439. }
  440. for _, tc := range testCases {
  441. t.Run(tc.name, func(t *testing.T) {
  442. // Start with a config with all defaults set, so that we only
  443. cfg, err := New()
  444. assert.NilError(t, err)
  445. assert.Check(t, mergo.Merge(cfg, tc.config, mergo.WithOverride))
  446. // Check that the override happened :)
  447. assert.Check(t, is.DeepEqual(cfg, tc.config, field(tc.field)))
  448. err = Validate(cfg)
  449. assert.NilError(t, err)
  450. })
  451. }
  452. }
  453. func field(field string) cmp.Option {
  454. tmp := reflect.TypeOf(Config{})
  455. ignoreFields := make([]string, 0, tmp.NumField())
  456. for i := 0; i < tmp.NumField(); i++ {
  457. if tmp.Field(i).Name != field {
  458. ignoreFields = append(ignoreFields, tmp.Field(i).Name)
  459. }
  460. }
  461. return cmpopts.IgnoreFields(Config{}, ignoreFields...)
  462. }
  463. // TestReloadSetConfigFileNotExist tests that when `--config-file` is set
  464. // and it doesn't exist the `Reload` function returns an error.
  465. func TestReloadSetConfigFileNotExist(t *testing.T) {
  466. configFile := "/tmp/blabla/not/exists/config.json"
  467. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  468. flags.String("config-file", "", "")
  469. assert.Check(t, flags.Set("config-file", configFile))
  470. err := Reload(configFile, flags, func(c *Config) {})
  471. assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file"))
  472. }
  473. // TestReloadDefaultConfigNotExist tests that if the default configuration file
  474. // doesn't exist the daemon still will be reloaded.
  475. func TestReloadDefaultConfigNotExist(t *testing.T) {
  476. skip.If(t, os.Getuid() != 0, "skipping test that requires root")
  477. defaultConfigFile := "/tmp/blabla/not/exists/daemon.json"
  478. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  479. flags.String("config-file", defaultConfigFile, "")
  480. reloaded := false
  481. err := Reload(defaultConfigFile, flags, func(c *Config) {
  482. reloaded = true
  483. })
  484. assert.Check(t, err)
  485. assert.Check(t, reloaded)
  486. }
  487. // TestReloadBadDefaultConfig tests that when `--config-file` is not set
  488. // and the default configuration file exists and is bad return an error
  489. func TestReloadBadDefaultConfig(t *testing.T) {
  490. f, err := os.CreateTemp("", "docker-config-")
  491. assert.NilError(t, err)
  492. configFile := f.Name()
  493. f.Write([]byte(`{wrong: "configuration"}`))
  494. f.Close()
  495. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  496. flags.String("config-file", configFile, "")
  497. reloaded := false
  498. err = Reload(configFile, flags, func(c *Config) {
  499. reloaded = true
  500. })
  501. assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file"))
  502. assert.Check(t, reloaded == false)
  503. }
  504. func TestReloadWithConflictingLabels(t *testing.T) {
  505. tempFile := fs.NewFile(t, "config", fs.WithContent(`{"labels":["foo=bar","foo=baz"]}`))
  506. defer tempFile.Remove()
  507. configFile := tempFile.Path()
  508. var lbls []string
  509. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  510. flags.String("config-file", configFile, "")
  511. flags.StringSlice("labels", lbls, "")
  512. reloaded := false
  513. err := Reload(configFile, flags, func(c *Config) {
  514. reloaded = true
  515. })
  516. assert.Check(t, is.ErrorContains(err, "conflict labels for foo=baz and foo=bar"))
  517. assert.Check(t, reloaded == false)
  518. }
  519. func TestReloadWithDuplicateLabels(t *testing.T) {
  520. tempFile := fs.NewFile(t, "config", fs.WithContent(`{"labels":["foo=the-same","foo=the-same"]}`))
  521. defer tempFile.Remove()
  522. configFile := tempFile.Path()
  523. var lbls []string
  524. flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
  525. flags.String("config-file", configFile, "")
  526. flags.StringSlice("labels", lbls, "")
  527. reloaded := false
  528. err := Reload(configFile, flags, func(c *Config) {
  529. reloaded = true
  530. assert.Check(t, is.DeepEqual(c.Labels, []string{"foo=the-same"}))
  531. })
  532. assert.Check(t, err)
  533. assert.Check(t, reloaded)
  534. }
  535. func TestMaskURLCredentials(t *testing.T) {
  536. tests := []struct {
  537. rawURL string
  538. maskedURL string
  539. }{
  540. {
  541. rawURL: "",
  542. maskedURL: "",
  543. }, {
  544. rawURL: "invalidURL",
  545. maskedURL: "invalidURL",
  546. }, {
  547. rawURL: "http://proxy.example.com:80/",
  548. maskedURL: "http://proxy.example.com:80/",
  549. }, {
  550. rawURL: "http://USER:PASSWORD@proxy.example.com:80/",
  551. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  552. }, {
  553. rawURL: "http://PASSWORD:PASSWORD@proxy.example.com:80/",
  554. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  555. }, {
  556. rawURL: "http://USER:@proxy.example.com:80/",
  557. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  558. }, {
  559. rawURL: "http://:PASSWORD@proxy.example.com:80/",
  560. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  561. }, {
  562. rawURL: "http://USER@docker:password@proxy.example.com:80/",
  563. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  564. }, {
  565. rawURL: "http://USER%40docker:password@proxy.example.com:80/",
  566. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  567. }, {
  568. rawURL: "http://USER%40docker:pa%3Fsword@proxy.example.com:80/",
  569. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/",
  570. }, {
  571. rawURL: "http://USER%40docker:pa%3Fsword@proxy.example.com:80/hello%20world",
  572. maskedURL: "http://xxxxx:xxxxx@proxy.example.com:80/hello%20world",
  573. },
  574. }
  575. for _, test := range tests {
  576. maskedURL := MaskCredentials(test.rawURL)
  577. assert.Equal(t, maskedURL, test.maskedURL)
  578. }
  579. }