Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions cli/config/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestFileStoreIdempotent(t *testing.T) {
},
})
authOne := types.AuthConfig{
Username: "foo@example.com",
Auth: "super_secret_token",
Email: "foo@example.com",
ServerAddress: "https://example.com",
}
authTwo := types.AuthConfig{
Username: "bar@example.com",
Auth: "also_super_secret_token",
Email: "bar@example.com",
ServerAddress: "https://other.example.com",
}

Expand Down Expand Up @@ -106,8 +106,8 @@ func TestFileStoreAddCredentials(t *testing.T) {

s := NewFileStore(f)
auth := types.AuthConfig{
Username: "foo@example.com",
Auth: "super_secret_token",
Email: "foo@example.com",
ServerAddress: "https://example.com",
}
err := s.Store(auth)
Expand All @@ -122,8 +122,8 @@ func TestFileStoreAddCredentials(t *testing.T) {
func TestFileStoreGet(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
"https://example.com": {
Username: "foo@example.com",
Auth: "super_secret_token",
Email: "foo@example.com",
ServerAddress: "https://example.com",
},
}}
Expand All @@ -136,8 +136,8 @@ func TestFileStoreGet(t *testing.T) {
if a.Auth != "super_secret_token" {
t.Fatalf("expected auth `super_secret_token`, got %s", a.Auth)
}
if a.Email != "foo@example.com" {
t.Fatalf("expected email `foo@example.com`, got %s", a.Email)
if a.Username != "foo@example.com" {
t.Fatalf("expected username `foo@example.com`, got %s", a.Username)
}
}

Expand All @@ -146,13 +146,13 @@ func TestFileStoreGetAll(t *testing.T) {
s2 := "https://example2.example.com"
f := &fakeStore{configs: map[string]types.AuthConfig{
s1: {
Username: "foo@example.com",
Auth: "super_secret_token",
Email: "foo@example.com",
ServerAddress: "https://example.com",
},
s2: {
Username: "foo@example2.com",
Auth: "super_secret_token2",
Email: "foo@example2.com",
ServerAddress: "https://example2.example.com",
},
}}
Expand All @@ -168,22 +168,22 @@ func TestFileStoreGetAll(t *testing.T) {
if as[s1].Auth != "super_secret_token" {
t.Fatalf("expected auth `super_secret_token`, got %s", as[s1].Auth)
}
if as[s1].Email != "foo@example.com" {
t.Fatalf("expected email `foo@example.com`, got %s", as[s1].Email)
if as[s1].Username != "foo@example.com" {
t.Fatalf("expected username `foo@example.com`, got %s", as[s1].Username)
}
if as[s2].Auth != "super_secret_token2" {
t.Fatalf("expected auth `super_secret_token2`, got %s", as[s2].Auth)
}
if as[s2].Email != "foo@example2.com" {
t.Fatalf("expected email `foo@example2.com`, got %s", as[s2].Email)
if as[s2].Username != "foo@example2.com" {
t.Fatalf("expected username `foo@example2.com`, got %s", as[s2].Username)
}
}

func TestFileStoreErase(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
"https://example.com": {
Username: "foo@example.com",
Auth: "super_secret_token",
Email: "foo@example.com",
ServerAddress: "https://example.com",
},
}}
Expand All @@ -203,9 +203,6 @@ func TestFileStoreErase(t *testing.T) {
if a.Auth != "" {
t.Fatalf("expected empty auth token, got %s", a.Auth)
}
if a.Email != "" {
t.Fatalf("expected empty email, got %s", a.Email)
}
}

func TestConvertToHostname(t *testing.T) {
Expand Down
63 changes: 15 additions & 48 deletions cli/config/credentials/native_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func TestNativeStoreAddCredentials(t *testing.T) {
auth := types.AuthConfig{
Username: "foo",
Password: "bar",
Email: "foo@example.com",
ServerAddress: validServerAddress,
}
err := s.Store(auth)
Expand All @@ -109,7 +108,6 @@ func TestNativeStoreAddCredentials(t *testing.T) {
actual, ok := f.GetAuthConfigs()[validServerAddress]
assert.Check(t, ok)
expected := types.AuthConfig{
Email: auth.Email,
ServerAddress: auth.ServerAddress,
}
assert.Check(t, is.DeepEqual(expected, actual))
Expand All @@ -124,7 +122,6 @@ func TestNativeStoreAddInvalidCredentials(t *testing.T) {
err := s.Store(types.AuthConfig{
Username: "foo",
Password: "bar",
Email: "foo@example.com",
ServerAddress: invalidServerAddress,
})
assert.ErrorContains(t, err, "program failed")
Expand All @@ -134,7 +131,7 @@ func TestNativeStoreAddInvalidCredentials(t *testing.T) {
func TestNativeStoreGet(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
Username: "foo@example.com",
},
}}
s := &nativeStore{
Expand All @@ -147,17 +144,14 @@ func TestNativeStoreGet(t *testing.T) {
expected := types.AuthConfig{
Username: "foo",
Password: "bar",
Email: "foo@example.com",
ServerAddress: validServerAddress,
}
assert.Check(t, is.DeepEqual(expected, actual))
}

func TestNativeStoreGetIdentityToken(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress2: {
Email: "foo@example2.com",
},
validServerAddress2: {},
}}

s := &nativeStore{
Expand All @@ -169,17 +163,14 @@ func TestNativeStoreGetIdentityToken(t *testing.T) {

expected := types.AuthConfig{
IdentityToken: "abcd1234",
Email: "foo@example2.com",
ServerAddress: validServerAddress2,
}
assert.Check(t, is.DeepEqual(expected, actual))
}

func TestNativeStoreGetAll(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
},
validServerAddress: {},
}}

s := &nativeStore{
Expand All @@ -189,38 +180,20 @@ func TestNativeStoreGetAll(t *testing.T) {
as, err := s.GetAll()
assert.NilError(t, err)
assert.Check(t, is.Len(as, 2))

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].IdentityToken != "" {
t.Fatalf("expected identity to be empty for %s, got %s", validServerAddress, as[validServerAddress].IdentityToken)
}
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 != "" {
t.Fatalf("expected username to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Username)
}
if as[validServerAddress2].Password != "" {
t.Fatalf("expected password to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Password)
}
if as[validServerAddress2].IdentityToken != "abcd1234" {
t.Fatalf("expected identity token `abcd1324` for %s, got %s", validServerAddress2, as[validServerAddress2].IdentityToken)
}
if as[validServerAddress2].Email != "" {
t.Fatalf("expected no email for %s, got %s", validServerAddress2, as[validServerAddress2].Email)
expected := types.AuthConfig{
Username: "foo",
Password: "bar",
ServerAddress: "https://index.docker.io/v1",
IdentityToken: "",
}
actual, ok := as[validServerAddress]
assert.Check(t, ok)
assert.Check(t, is.DeepEqual(expected, actual))
}

func TestNativeStoreGetMissingCredentials(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
},
validServerAddress: {},
}}

s := &nativeStore{
Expand All @@ -233,9 +206,7 @@ func TestNativeStoreGetMissingCredentials(t *testing.T) {

func TestNativeStoreGetInvalidAddress(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
},
validServerAddress: {},
}}

s := &nativeStore{
Expand All @@ -248,9 +219,7 @@ func TestNativeStoreGetInvalidAddress(t *testing.T) {

func TestNativeStoreErase(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
},
validServerAddress: {},
}}

s := &nativeStore{
Expand All @@ -264,9 +233,7 @@ func TestNativeStoreErase(t *testing.T) {

func TestNativeStoreEraseInvalidAddress(t *testing.T) {
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "foo@example.com",
},
validServerAddress: {},
}}

s := &nativeStore{
Expand Down
4 changes: 2 additions & 2 deletions cli/config/types/authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type AuthConfig struct {
Auth string `json:"auth,omitempty"`

// Email is an optional value associated with the username.
// This field is deprecated and will be removed in a later
// version of docker.
//
// Deprecated: This field is deprecated since docker 1.11 (API v1.23) and will be removed in the next release.
Email string `json:"email,omitempty"`

ServerAddress string `json:"serveraddress,omitempty"`
Expand Down
Loading