Skip to content

Commit 30fb480

Browse files
authored
Merge pull request #6784 from thaJeztah/login_cleanups
cli/command/registry: preserve all whitespace in secrets
2 parents 6347345 + e2cafd6 commit 30fb480

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

cli/command/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
144144
}
145145
}
146146

147-
argPassword = strings.TrimSpace(argPassword)
148-
if argPassword == "" {
147+
isEmpty := strings.TrimSpace(argPassword) == ""
148+
if isEmpty {
149149
restoreInput, err := prompt.DisableInputEcho(cli.In())
150150
if err != nil {
151151
return registrytypes.AuthConfig{}, err

cli/command/registry/login_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,56 @@ func TestRunLogin(t *testing.T) {
339339
},
340340
},
341341
},
342+
{
343+
doc: "password with leading and trailing spaces",
344+
priorCredentials: map[string]configtypes.AuthConfig{},
345+
input: loginOptions{
346+
serverAddress: "reg1",
347+
user: "my-username",
348+
password: " my password with spaces ",
349+
},
350+
expectedCredentials: map[string]configtypes.AuthConfig{
351+
"reg1": {
352+
Username: "my-username",
353+
Password: " my password with spaces ",
354+
ServerAddress: "reg1",
355+
},
356+
},
357+
},
358+
{
359+
doc: "password stdin with line-endings",
360+
priorCredentials: map[string]configtypes.AuthConfig{},
361+
stdIn: " my password with spaces \r\n",
362+
input: loginOptions{
363+
serverAddress: "reg1",
364+
user: "my-username",
365+
passwordStdin: true,
366+
},
367+
expectedCredentials: map[string]configtypes.AuthConfig{
368+
"reg1": {
369+
Username: "my-username",
370+
Password: " my password with spaces ",
371+
ServerAddress: "reg1",
372+
},
373+
},
374+
},
375+
{
376+
doc: "password stdin with multiple line-endings",
377+
priorCredentials: map[string]configtypes.AuthConfig{},
378+
stdIn: " my password\nwith spaces \r\n\r\n",
379+
input: loginOptions{
380+
serverAddress: "reg1",
381+
user: "my-username",
382+
passwordStdin: true,
383+
},
384+
expectedCredentials: map[string]configtypes.AuthConfig{
385+
"reg1": {
386+
Username: "my-username",
387+
Password: " my password\nwith spaces \r\n",
388+
ServerAddress: "reg1",
389+
},
390+
},
391+
},
342392
}
343393

344394
for _, tc := range testCases {

0 commit comments

Comments
 (0)