diff --git a/drivers/docker/driver_test.go b/drivers/docker/driver_test.go index c0a9e8fbe..8d68aa4ca 100644 --- a/drivers/docker/driver_test.go +++ b/drivers/docker/driver_test.go @@ -1664,6 +1664,60 @@ func TestDockerDriver_AuthConfiguration(t *testing.T) { } } +func TestDockerDriver_AuthFromTaskConfig(t *testing.T) { + if !tu.IsCI() { + t.Parallel() + } + + cases := []struct { + Auth DockerAuth + AuthConfig *docker.AuthConfiguration + Desc string + }{ + { + Auth: DockerAuth{}, + AuthConfig: nil, + Desc: "Empty Config", + }, + { + Auth: DockerAuth{ + Username: "foo", + Password: "bar", + Email: "foo@bar.com", + ServerAddr: "www.foobar.com", + }, + AuthConfig: &docker.AuthConfiguration{ + Username: "foo", + Password: "bar", + Email: "foo@bar.com", + ServerAddress: "www.foobar.com", + }, + Desc: "All fields set", + }, + { + Auth: DockerAuth{ + Username: "foo", + Password: "bar", + ServerAddr: "www.foobar.com", + }, + AuthConfig: &docker.AuthConfiguration{ + Username: "foo", + Password: "bar", + ServerAddress: "www.foobar.com", + }, + Desc: "Email not set", + }, + } + + for _, c := range cases { + t.Run(c.Desc, func(t *testing.T) { + act, err := authFromTaskConfig(&TaskConfig{Auth: c.Auth})("test") + require.NoError(t, err) + require.Exactly(t, c.AuthConfig, act) + }) + } +} + func TestDockerDriver_OOMKilled(t *testing.T) { if !tu.IsCI() { t.Parallel() diff --git a/drivers/docker/utils.go b/drivers/docker/utils.go index fc20b30b7..d2ce1709a 100644 --- a/drivers/docker/utils.go +++ b/drivers/docker/utils.go @@ -82,7 +82,8 @@ func firstValidAuth(repo string, backends []authBackend) (*docker.AuthConfigurat // authFromTaskConfig generates an authBackend for any auth given in the task-configuration func authFromTaskConfig(driverConfig *TaskConfig) authBackend { return func(string) (*docker.AuthConfiguration, error) { - if len(driverConfig.Auth.Email) == 0 { + // If all auth fields are empty, return + if len(driverConfig.Auth.Username) == 0 && len(driverConfig.Auth.Password) == 0 && len(driverConfig.Auth.Email) == 0 && len(driverConfig.Auth.ServerAddr) == 0 { return nil, nil } return &docker.AuthConfiguration{