MCPcopy Create free account
hub / github.com/docker/cli / TestGetAllCredentialsFromEnvironment

Function TestGetAllCredentialsFromEnvironment

cli/config/configfile/file_test.go:502–585  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

500}`
501
502func TestGetAllCredentialsFromEnvironment(t *testing.T) {
503 t.Run("can parse DOCKER_AUTH_CONFIG auth field", func(t *testing.T) {
504 config := &ConfigFile{}
505
506 t.Setenv("DOCKER_AUTH_CONFIG", envTestAuthConfig)
507
508 authConfigs, err := config.GetAllCredentials()
509 assert.NilError(t, err)
510
511 expected := map[string]types.AuthConfig{
512 "env.example.test": {
513 Username: "env_user",
514 Password: "env_pass",
515 ServerAddress: "env.example.test",
516 },
517 }
518 assert.Check(t, is.DeepEqual(authConfigs, expected))
519 })
520
521 t.Run("malformed DOCKER_AUTH_CONFIG should fallback to underlying store", func(t *testing.T) {
522 fallbackStore := map[string]types.AuthConfig{
523 "fallback.example.test": {
524 Username: "fallback_user",
525 Password: "fallback_pass",
526 ServerAddress: "fallback.example.test",
527 },
528 }
529 config := &ConfigFile{
530 AuthConfigs: fallbackStore,
531 }
532
533 t.Setenv("DOCKER_AUTH_CONFIG", envTestUserPassConfig)
534
535 authConfigs, err := config.GetAllCredentials()
536 assert.NilError(t, err)
537
538 expected := fallbackStore
539 assert.Check(t, is.DeepEqual(authConfigs, expected))
540 })
541
542 t.Run("can fetch credentials from DOCKER_AUTH_CONFIG and underlying store", func(t *testing.T) {
543 configFile := New("filename")
544 exampleAuth := types.AuthConfig{
545 Username: "user",
546 Password: "pass",
547 }
548 configFile.AuthConfigs["foo.example.test"] = exampleAuth
549
550 t.Setenv("DOCKER_AUTH_CONFIG", envTestAuthConfig)
551
552 authConfigs, err := configFile.GetAllCredentials()
553 assert.NilError(t, err)
554
555 expected := map[string]types.AuthConfig{
556 "foo.example.test": exampleAuth,
557 "env.example.test": {
558 Username: "env_user",
559 Password: "env_pass",

Callers

nothing calls this directly

Calls 4

GetAllCredentialsMethod · 0.95
GetAuthConfigMethod · 0.80
NewFunction · 0.70
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…