mirror of https://github.com/docker/cli.git
Merge pull request #1835 from dhiltgen/refined_login_warning
Refine warning for storing registry passwords
This commit is contained in:
commit
49bd6b729d
|
@ -143,7 +143,8 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint: gocycl
|
||||||
creds := dockerCli.ConfigFile().GetCredentialsStore(serverAddress)
|
creds := dockerCli.ConfigFile().GetCredentialsStore(serverAddress)
|
||||||
|
|
||||||
store, isDefault := creds.(isFileStore)
|
store, isDefault := creds.(isFileStore)
|
||||||
if isDefault {
|
// Display a warning if we're storing the users password (not a token)
|
||||||
|
if isDefault && authConfig.Password != "" {
|
||||||
err = displayUnencryptedWarning(dockerCli, store.GetFilename())
|
err = displayUnencryptedWarning(dockerCli, store.GetFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -24,6 +24,7 @@ var testAuthErrors = map[string]error{
|
||||||
}
|
}
|
||||||
|
|
||||||
var expiredPassword = "I_M_EXPIRED"
|
var expiredPassword = "I_M_EXPIRED"
|
||||||
|
var useToken = "I_M_TOKEN"
|
||||||
|
|
||||||
type fakeClient struct {
|
type fakeClient struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
@ -37,6 +38,11 @@ func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (r
|
||||||
if auth.Password == expiredPassword {
|
if auth.Password == expiredPassword {
|
||||||
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
|
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
|
||||||
}
|
}
|
||||||
|
if auth.Password == useToken {
|
||||||
|
return registrytypes.AuthenticateOKBody{
|
||||||
|
IdentityToken: auth.Password,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
err := testAuthErrors[auth.Username]
|
err := testAuthErrors[auth.Username]
|
||||||
return registrytypes.AuthenticateOKBody{}, err
|
return registrytypes.AuthenticateOKBody{}, err
|
||||||
}
|
}
|
||||||
|
@ -90,6 +96,11 @@ func TestRunLogin(t *testing.T) {
|
||||||
Username: validUsername,
|
Username: validUsername,
|
||||||
Password: expiredPassword,
|
Password: expiredPassword,
|
||||||
}
|
}
|
||||||
|
validIdentityToken := configtypes.AuthConfig{
|
||||||
|
ServerAddress: storedServerAddress,
|
||||||
|
Username: validUsername,
|
||||||
|
IdentityToken: useToken,
|
||||||
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
inputLoginOption loginOptions
|
inputLoginOption loginOptions
|
||||||
inputStoredCred *configtypes.AuthConfig
|
inputStoredCred *configtypes.AuthConfig
|
||||||
|
@ -134,6 +145,16 @@ func TestRunLogin(t *testing.T) {
|
||||||
inputStoredCred: &validAuthConfig,
|
inputStoredCred: &validAuthConfig,
|
||||||
expectedErr: testAuthErrMsg,
|
expectedErr: testAuthErrMsg,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
inputLoginOption: loginOptions{
|
||||||
|
serverAddress: storedServerAddress,
|
||||||
|
user: validUsername,
|
||||||
|
password: useToken,
|
||||||
|
},
|
||||||
|
inputStoredCred: &validIdentityToken,
|
||||||
|
expectedErr: "",
|
||||||
|
expectedSavedCred: validIdentityToken,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue