|
@@ -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: "foo@example.com",
|
|
|
+ },
|
|
|
+ validServerAddress2: {
|
|
|
+ Email: "foo@example2.com",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ 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 != "foo@example.com" {
|
|
|
+ t.Fatalf("expected email `foo@example.com` 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 != "foo@example2.com" {
|
|
|
+ t.Fatalf("expected email `foo@example2.com` for %s, got %s", validServerAddress2, as[validServerAddress2].Email)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestNativeStoreGetMissingCredentials(t *testing.T) {
|
|
|
f := newConfigFile(map[string]types.AuthConfig{
|
|
|
validServerAddress: {
|