forked from docker/cli
-
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.
config: print deprecation warning when falling back to ~/.dockercfg
Relates to the deprecation, added in 3c0a167 The docker CLI up until v1.7.0 used the `~/.dockercfg` file to store credentials after authenticating to a registry (`docker login`). Docker v1.7.0 replaced this file with a new CLI configuration file, located in `~/.docker/config.json`. When implementing the new configuration file, the old file (and file-format) was kept as a fall-back, to assist existing users with migrating to the new file. Given that the old file format encourages insecure storage of credentials (credentials are stored unencrypted), and that no version of the CLI since Docker v1.7.0 has created this file, the file is marked deprecated, and support for this file will be removed in a future release. This patch adds a deprecation warning, which is printed if the CLI falls back to using the deprecated ~/.dockercfg file. Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information
Showing
3 changed files
with
57 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,11 @@ import ( | |
|
||
"github.com/docker/cli/cli/config/configfile" | ||
"github.com/docker/cli/cli/config/credentials" | ||
"github.com/docker/cli/cli/config/types" | ||
"gotest.tools/v3/assert" | ||
is "gotest.tools/v3/assert/cmp" | ||
"gotest.tools/v3/env" | ||
"gotest.tools/v3/fs" | ||
) | ||
|
||
var homeKey = "HOME" | ||
|
@@ -223,6 +225,31 @@ func TestOldJSON(t *testing.T) { | |
} | ||
} | ||
|
||
func TestOldJSONFallbackDeprecationWarning(t *testing.T) { | ||
js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"[email protected]"}}` | ||
tmpHome := fs.NewDir(t, t.Name(), fs.WithFile(oldConfigfile, js)) | ||
defer tmpHome.Remove() | ||
defer env.PatchAll(t, map[string]string{homeKey: tmpHome.Path(), "DOCKER_CONFIG": ""})() | ||
|
||
// reset the homeDir, configDir, and its sync.Once, to force them being resolved again | ||
resetHomeDir() | ||
resetConfigDir() | ||
|
||
buffer := new(bytes.Buffer) | ||
configFile := LoadDefaultConfigFile(buffer) | ||
expected := configfile.New(tmpHome.Join(configFileDir, ConfigFileName)) | ||
expected.AuthConfigs = map[string]types.AuthConfig{ | ||
"https://index.docker.io/v1/": { | ||
Username: "joejoe", | ||
Password: "hello", | ||
Email: "[email protected]", | ||
ServerAddress: "https://index.docker.io/v1/", | ||
}, | ||
} | ||
assert.Assert(t, strings.Contains(buffer.String(), "WARNING: Support for the legacy ~/.dockercfg configuration file and file-format is deprecated and will be removed in an upcoming release")) | ||
assert.Check(t, is.DeepEqual(expected, configFile)) | ||
} | ||
|
||
func TestNewJSON(t *testing.T) { | ||
tmpHome, err := ioutil.TempDir("", "config-test") | ||
assert.NilError(t, err) | ||
|
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