diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index dc469a07a6..072a72feab 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -1,6 +1,7 @@ package registry import ( + "bytes" "context" "errors" "fmt" @@ -92,6 +93,7 @@ func TestRunLogin(t *testing.T) { testCases := []struct { doc string priorCredentials map[string]configtypes.AuthConfig + stdIn string input loginOptions expectedCredentials map[string]configtypes.AuthConfig expectedErr string @@ -287,6 +289,23 @@ func TestRunLogin(t *testing.T) { }, }, }, + { + doc: "password stdin with line-endings", + priorCredentials: map[string]configtypes.AuthConfig{}, + stdIn: "my password\r\n", + input: loginOptions{ + serverAddress: "reg1", + user: "my-username", + passwordStdin: true, + }, + expectedCredentials: map[string]configtypes.AuthConfig{ + "reg1": { + Username: "my-username", + Password: "my password", + ServerAddress: "reg1", + }, + }, + }, } for _, tc := range testCases { @@ -295,6 +314,9 @@ func TestRunLogin(t *testing.T) { cfg := configfile.New(filepath.Join(tmpDir, "config.json")) cli := test.NewFakeCli(&fakeClient{}) cli.SetConfigFile(cfg) + if tc.input.passwordStdin { + cli.SetIn(streams.NewIn(io.NopCloser(bytes.NewBufferString(tc.stdIn)))) + } for _, priorCred := range tc.priorCredentials { assert.NilError(t, cfg.GetCredentialsStore(priorCred.ServerAddress).Store(priorCred))