@@ -339,6 +339,57 @@ func TestRunLogin(t *testing.T) {
339339 },
340340 },
341341 },
342+ {
343+ doc : "password dash reads password from stdin" ,
344+ priorCredentials : map [string ]configtypes.AuthConfig {},
345+ stdIn : "my password\r \n " ,
346+ input : loginOptions {
347+ serverAddress : "reg1" ,
348+ user : "my-username" ,
349+ password : "-" ,
350+ },
351+ expectedCredentials : map [string ]configtypes.AuthConfig {
352+ "reg1" : {
353+ Username : "my-username" ,
354+ Password : "my password" ,
355+ ServerAddress : "reg1" ,
356+ },
357+ },
358+ },
359+ {
360+ doc : "password dash empty stdin" ,
361+ priorCredentials : map [string ]configtypes.AuthConfig {},
362+ input : loginOptions {
363+ serverAddress : "reg1" ,
364+ user : "my-username" ,
365+ password : "-" ,
366+ },
367+ expectedErr : `password is empty` ,
368+ expectedCredentials : map [string ]configtypes.AuthConfig {
369+ "reg1" : {
370+ Username : "my-username" ,
371+ ServerAddress : "reg1" ,
372+ },
373+ },
374+ },
375+ {
376+ doc : "password dash and password stdin read password from stdin" ,
377+ priorCredentials : map [string ]configtypes.AuthConfig {},
378+ stdIn : "my password\r \n " ,
379+ input : loginOptions {
380+ serverAddress : "reg1" ,
381+ user : "my-username" ,
382+ password : "-" ,
383+ passwordStdin : true ,
384+ },
385+ expectedCredentials : map [string ]configtypes.AuthConfig {
386+ "reg1" : {
387+ Username : "my-username" ,
388+ Password : "my password" ,
389+ ServerAddress : "reg1" ,
390+ },
391+ },
392+ },
342393 {
343394 doc : "password with leading and trailing spaces" ,
344395 priorCredentials : map [string ]configtypes.AuthConfig {},
@@ -397,7 +448,7 @@ func TestRunLogin(t *testing.T) {
397448 cfg := configfile .New (filepath .Join (tmpDir , "config.json" ))
398449 cli := test .NewFakeCli (& fakeClient {})
399450 cli .SetConfigFile (cfg )
400- if tc .input .passwordStdin {
451+ if tc .input .passwordStdin || tc . input . password == "-" || tc . stdIn != "" {
401452 if tc .expectedErr == "TEST_READ_ERR" {
402453 cli .SetIn (streams .NewIn (io .NopCloser (iotest .ErrReader (errors .New (tc .expectedErr )))))
403454 } else {
@@ -632,6 +683,21 @@ func TestLoginValidateFlags(t *testing.T) {
632683 args : []string {"--password-stdin" , "--password" , "" },
633684 expectedErr : `conflicting options: cannot specify both --password and --password-stdin` ,
634685 },
686+ {
687+ name : "password stdin and password dash without stdin" ,
688+ args : []string {"--password-stdin" , "--username" , "my-username" , "--password" , "-" },
689+ expectedErr : `password is empty` ,
690+ },
691+ {
692+ name : "password dash without username" ,
693+ args : []string {"--password" , "-" },
694+ expectedErr : `the --password-stdin option requires --username to be set` ,
695+ },
696+ {
697+ name : "short password dash without username" ,
698+ args : []string {"-p" , "-" },
699+ expectedErr : `the --password-stdin option requires --username to be set` ,
700+ },
635701 {
636702 name : "empty --password" ,
637703 args : []string {"--password" , "" },
@@ -658,3 +724,10 @@ func TestLoginValidateFlags(t *testing.T) {
658724 })
659725 }
660726}
727+
728+ func TestLoginHelpDocumentsPasswordDash (t * testing.T ) {
729+ cmd := newLoginCommand (test .NewFakeCli (& fakeClient {}))
730+ flag := cmd .Flags ().Lookup ("password" )
731+ assert .Check (t , flag != nil )
732+ assert .Check (t , is .Contains (flag .Usage , `"-"` ))
733+ }
0 commit comments