Merge pull request #1835 from dhiltgen/refined_login_warning

Refine warning for storing registry passwords
This commit is contained in:
Sebastiaan van Stijn 2019-04-16 10:36:24 +02:00 committed by GitHub
commit 49bd6b729d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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) {