File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 11package registry
22
33import (
4+ "bytes"
45 "context"
56 "errors"
67 "fmt"
@@ -92,6 +93,7 @@ func TestRunLogin(t *testing.T) {
9293 testCases := []struct {
9394 doc string
9495 priorCredentials map [string ]configtypes.AuthConfig
96+ stdIn string
9597 input loginOptions
9698 expectedCredentials map [string ]configtypes.AuthConfig
9799 expectedErr string
@@ -287,6 +289,23 @@ func TestRunLogin(t *testing.T) {
287289 },
288290 },
289291 },
292+ {
293+ doc : "password stdin with line-endings" ,
294+ priorCredentials : map [string ]configtypes.AuthConfig {},
295+ stdIn : "my password\r \n " ,
296+ input : loginOptions {
297+ serverAddress : "reg1" ,
298+ user : "my-username" ,
299+ passwordStdin : true ,
300+ },
301+ expectedCredentials : map [string ]configtypes.AuthConfig {
302+ "reg1" : {
303+ Username : "my-username" ,
304+ Password : "my password" ,
305+ ServerAddress : "reg1" ,
306+ },
307+ },
308+ },
290309 }
291310
292311 for _ , tc := range testCases {
@@ -295,6 +314,9 @@ func TestRunLogin(t *testing.T) {
295314 cfg := configfile .New (filepath .Join (tmpDir , "config.json" ))
296315 cli := test .NewFakeCli (& fakeClient {})
297316 cli .SetConfigFile (cfg )
317+ if tc .input .passwordStdin {
318+ cli .SetIn (streams .NewIn (io .NopCloser (bytes .NewBufferString (tc .stdIn ))))
319+ }
298320
299321 for _ , priorCred := range tc .priorCredentials {
300322 assert .NilError (t , cfg .GetCredentialsStore (priorCred .ServerAddress ).Store (priorCred ))
You can’t perform that action at this time.
0 commit comments