Merge pull request #5416 from hashicorp/b-docker-email

Fix regression with requiring docker auth email
This commit is contained in:
Preetha 2019-03-13 13:28:34 -05:00 committed by GitHub
commit 0ffbe64503
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View file

@ -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()

View file

@ -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{