forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cliconfig: credentials: support getting all auths
docker build is broken because it sends to the daemon the full cliconfig file which has only Email(s). This patch retrieves all auth configs from the credentials store. Signed-off-by: Antonio Murdaca <[email protected]>
- Loading branch information
Showing
11 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,44 @@ func TestFileStoreGet(t *testing.T) { | |
} | ||
} | ||
|
||
func TestFileStoreGetAll(t *testing.T) { | ||
s1 := "https://example.com" | ||
s2 := "https://example2.com" | ||
f := newConfigFile(map[string]types.AuthConfig{ | ||
s1: { | ||
Auth: "super_secret_token", | ||
Email: "[email protected]", | ||
ServerAddress: "https://example.com", | ||
}, | ||
s2: { | ||
Auth: "super_secret_token2", | ||
Email: "[email protected]", | ||
ServerAddress: "https://example2.com", | ||
}, | ||
}) | ||
|
||
s := NewFileStore(f) | ||
as, err := s.GetAll() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(as) != 2 { | ||
t.Fatalf("wanted 2, got %d", len(as)) | ||
} | ||
if as[s1].Auth != "super_secret_token" { | ||
t.Fatalf("expected auth `super_secret_token`, got %s", as[s1].Auth) | ||
} | ||
if as[s1].Email != "[email protected]" { | ||
t.Fatalf("expected email `[email protected]`, got %s", as[s1].Email) | ||
} | ||
if as[s2].Auth != "super_secret_token2" { | ||
t.Fatalf("expected auth `super_secret_token2`, got %s", as[s2].Auth) | ||
} | ||
if as[s2].Email != "[email protected]" { | ||
t.Fatalf("expected email `[email protected]`, got %s", as[s2].Email) | ||
} | ||
} | ||
|
||
func TestFileStoreErase(t *testing.T) { | ||
f := newConfigFile(map[string]types.AuthConfig{ | ||
"https://example.com": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
|
||
const ( | ||
validServerAddress = "https://index.docker.io/v1" | ||
validServerAddress2 = "https://example.com:5002" | ||
invalidServerAddress = "https://foobar.example.com" | ||
missingCredsAddress = "https://missing.docker.io/v1" | ||
) | ||
|
@@ -46,7 +47,7 @@ func (m *mockCommand) Output() ([]byte, error) { | |
} | ||
case "get": | ||
switch inS { | ||
case validServerAddress: | ||
case validServerAddress, validServerAddress2: | ||
return []byte(`{"Username": "foo", "Password": "bar"}`), nil | ||
case missingCredsAddress: | ||
return []byte(errCredentialsNotFound.Error()), errCommandExited | ||
|
@@ -67,7 +68,7 @@ func (m *mockCommand) Output() ([]byte, error) { | |
} | ||
} | ||
|
||
return []byte("unknown argument"), errCommandExited | ||
return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errCommandExited | ||
} | ||
|
||
// Input sets the input to send to a remote credentials helper. | ||
|
@@ -178,6 +179,50 @@ func TestNativeStoreGet(t *testing.T) { | |
} | ||
} | ||
|
||
func TestNativeStoreGetAll(t *testing.T) { | ||
f := newConfigFile(map[string]types.AuthConfig{ | ||
validServerAddress: { | ||
Email: "[email protected]", | ||
}, | ||
validServerAddress2: { | ||
Email: "[email protected]", | ||
}, | ||
}) | ||
f.CredentialsStore = "mock" | ||
|
||
s := &nativeStore{ | ||
commandFn: mockCommandFn, | ||
fileStore: NewFileStore(f), | ||
} | ||
as, err := s.GetAll() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(as) != 2 { | ||
t.Fatalf("wanted 2, got %d", len(as)) | ||
} | ||
|
||
if as[validServerAddress].Username != "foo" { | ||
t.Fatalf("expected username `foo` for %s, got %s", validServerAddress, as[validServerAddress].Username) | ||
} | ||
if as[validServerAddress].Password != "bar" { | ||
t.Fatalf("expected password `bar` for %s, got %s", validServerAddress, as[validServerAddress].Password) | ||
} | ||
if as[validServerAddress].Email != "[email protected]" { | ||
t.Fatalf("expected email `[email protected]` for %s, got %s", validServerAddress, as[validServerAddress].Email) | ||
} | ||
if as[validServerAddress2].Username != "foo" { | ||
t.Fatalf("expected username `foo` for %s, got %s", validServerAddress2, as[validServerAddress2].Username) | ||
} | ||
if as[validServerAddress2].Password != "bar" { | ||
t.Fatalf("expected password `bar` for %s, got %s", validServerAddress2, as[validServerAddress2].Password) | ||
} | ||
if as[validServerAddress2].Email != "[email protected]" { | ||
t.Fatalf("expected email `[email protected]` for %s, got %s", validServerAddress2, as[validServerAddress2].Email) | ||
} | ||
} | ||
|
||
func TestNativeStoreGetMissingCredentials(t *testing.T) { | ||
f := newConfigFile(map[string]types.AuthConfig{ | ||
validServerAddress: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters