Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
handle registry password with colon
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Jan 9, 2019
1 parent 3b5936a commit 6576d4b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
11 changes: 7 additions & 4 deletions engine/docker/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ func decode(s string) (username, password string) {
if err != nil {
return
}
parts := strings.Split(string(d), ":")
if len(parts) != 2 {
return
parts := strings.SplitN(string(d), ":", 2)
if len(parts) > 0 {
username = parts[0]
}
if len(parts) > 1 {
password = parts[1]
}
return parts[0], parts[1]
return
}

func hostname(s string) string {
Expand Down
25 changes: 18 additions & 7 deletions engine/docker/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func TestParse(t *testing.T) {
}
}

func TestParseGCR(t *testing.T) {
got, err := ParseFile("testdata/config_gcr.json")
if err != nil {
t.Error(err)
return
}
want := []*engine.DockerAuth{
{
Address: "gcr.io",
Username: "_json_key",
Password: "xxx:bar\n",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf(diff)
}
}

func TestParseErr(t *testing.T) {
_, err := ParseString("")
if err == nil {
Expand Down Expand Up @@ -82,13 +100,6 @@ func Test_decodeInvalid(t *testing.T) {
}
}

func Test_decodeEmpty(t *testing.T) {
username, password := decode("b2N0b2NhdDpoZWxsbzp3b3JsZA==")
if username != "" || password != "" {
t.Errorf("Expect decoding error")
}
}

func TestEncode(t *testing.T) {
username := "octocat"
password := "correct-horse-battery-staple"
Expand Down
7 changes: 7 additions & 0 deletions engine/docker/auth/testdata/config_gcr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"auths": {
"gcr.io": {
"auth": "X2pzb25fa2V5Onh4eDpiYXIK"
}
}
}

0 comments on commit 6576d4b

Please sign in to comment.