config_test.go 17 KB

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