@@ -97,6 +97,24 @@ var _ = Describe("Podman login and logout", func() {
97
97
os .RemoveAll (certDirPath )
98
98
})
99
99
100
+ readAuthInfo := func (filePath string ) map [string ]interface {} {
101
+ authBytes , err := ioutil .ReadFile (filePath )
102
+ Expect (err ).To (BeNil ())
103
+
104
+ var authInfo map [string ]interface {}
105
+ err = json .Unmarshal (authBytes , & authInfo )
106
+ Expect (err ).To (BeNil ())
107
+ fmt .Println (authInfo )
108
+
109
+ const authsKey = "auths"
110
+ Expect (authInfo ).To (HaveKey (authsKey ))
111
+
112
+ auths , ok := authInfo [authsKey ].(map [string ]interface {})
113
+ Expect (ok ).To (BeTrue ())
114
+
115
+ return auths
116
+ }
117
+
100
118
It ("podman login and logout" , func () {
101
119
session := podmanTest .Podman ([]string {"login" , "-u" , "podmantest" , "-p" , "test" , server })
102
120
session .WaitWithDefaultTimeout ()
@@ -151,10 +169,7 @@ var _ = Describe("Podman login and logout", func() {
151
169
session .WaitWithDefaultTimeout ()
152
170
Expect (session ).Should (Exit (0 ))
153
171
154
- authInfo , _ := ioutil .ReadFile (authFile )
155
- var info map [string ]interface {}
156
- json .Unmarshal (authInfo , & info )
157
- fmt .Println (info )
172
+ readAuthInfo (authFile )
158
173
159
174
// push should fail with nonexistent authfile
160
175
session = podmanTest .Podman ([]string {"push" , "--authfile" , "/tmp/nonexistent" , ALPINE , testImg })
@@ -284,4 +299,204 @@ var _ = Describe("Podman login and logout", func() {
284
299
session .WaitWithDefaultTimeout ()
285
300
Expect (session ).To (ExitWithError ())
286
301
})
302
+
303
+ It ("podman login and logout with repository" , func () {
304
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
305
+
306
+ testRepository := server + "/podmantest"
307
+ session := podmanTest .Podman ([]string {
308
+ "login" ,
309
+ "-u" , "podmantest" ,
310
+ "-p" , "test" ,
311
+ "--authfile" , authFile ,
312
+ testRepository ,
313
+ })
314
+ session .WaitWithDefaultTimeout ()
315
+ Expect (session ).Should (Exit (0 ))
316
+
317
+ authInfo := readAuthInfo (authFile )
318
+ Expect (authInfo ).To (HaveKey (testRepository ))
319
+
320
+ session = podmanTest .Podman ([]string {
321
+ "logout" ,
322
+ "--authfile" , authFile ,
323
+ testRepository ,
324
+ })
325
+ session .WaitWithDefaultTimeout ()
326
+ Expect (session ).Should (Exit (0 ))
327
+
328
+ authInfo = readAuthInfo (authFile )
329
+ Expect (authInfo ).NotTo (HaveKey (testRepository ))
330
+ })
331
+
332
+ It ("podman login and logout with repository and specified image" , func () {
333
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
334
+
335
+ testTarget := server + "/podmantest/test-alpine"
336
+ session := podmanTest .Podman ([]string {
337
+ "login" ,
338
+ "-u" , "podmantest" ,
339
+ "-p" , "test" ,
340
+ "--authfile" , authFile ,
341
+ testTarget ,
342
+ })
343
+ session .WaitWithDefaultTimeout ()
344
+ Expect (session ).Should (Exit (0 ))
345
+
346
+ authInfo := readAuthInfo (authFile )
347
+ Expect (authInfo ).To (HaveKey (testTarget ))
348
+
349
+ session = podmanTest .Podman ([]string {
350
+ "push" ,
351
+ "--authfile" , authFile ,
352
+ ALPINE , testTarget ,
353
+ })
354
+ session .WaitWithDefaultTimeout ()
355
+ Expect (session ).Should (Exit (0 ))
356
+
357
+ })
358
+
359
+ It ("podman login and logout with repository with fallback" , func () {
360
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
361
+
362
+ testRepos := []string {
363
+ server + "/podmantest" ,
364
+ server ,
365
+ }
366
+ for _ , testRepo := range testRepos {
367
+ session := podmanTest .Podman ([]string {
368
+ "login" ,
369
+ "-u" , "podmantest" ,
370
+ "-p" , "test" ,
371
+ "--authfile" , authFile ,
372
+ testRepo ,
373
+ })
374
+ session .WaitWithDefaultTimeout ()
375
+ Expect (session ).Should (Exit (0 ))
376
+ }
377
+
378
+ authInfo := readAuthInfo (authFile )
379
+ Expect (authInfo ).To (HaveKey (testRepos [0 ]))
380
+ Expect (authInfo ).To (HaveKey (testRepos [1 ]))
381
+
382
+ session := podmanTest .Podman ([]string {
383
+ "push" ,
384
+ "--authfile" , authFile ,
385
+ ALPINE , testRepos [0 ] + "/test-image-alpine" ,
386
+ })
387
+ session .WaitWithDefaultTimeout ()
388
+ Expect (session ).Should (Exit (0 ))
389
+
390
+ session = podmanTest .Podman ([]string {
391
+ "logout" ,
392
+ "--authfile" , authFile ,
393
+ testRepos [0 ],
394
+ })
395
+ session .WaitWithDefaultTimeout ()
396
+ Expect (session ).Should (Exit (0 ))
397
+
398
+ session = podmanTest .Podman ([]string {
399
+ "push" ,
400
+ "--authfile" , authFile ,
401
+ ALPINE , testRepos [0 ] + "/test-image-alpine" ,
402
+ })
403
+ session .WaitWithDefaultTimeout ()
404
+ Expect (session ).Should (Exit (0 ))
405
+
406
+ session = podmanTest .Podman ([]string {
407
+ "logout" ,
408
+ "--authfile" , authFile ,
409
+ testRepos [1 ],
410
+ })
411
+ session .WaitWithDefaultTimeout ()
412
+ Expect (session ).Should (Exit (0 ))
413
+
414
+ authInfo = readAuthInfo (authFile )
415
+ Expect (authInfo ).NotTo (HaveKey (testRepos [0 ]))
416
+ Expect (authInfo ).NotTo (HaveKey (testRepos [1 ]))
417
+ })
418
+
419
+ It ("podman login with repository invalid arguments" , func () {
420
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
421
+
422
+ for _ , invalidArg := range []string {
423
+ "https://" + server + "/podmantest" ,
424
+ server + "/podmantest/image:latest" ,
425
+ } {
426
+ session := podmanTest .Podman ([]string {
427
+ "login" ,
428
+ "-u" , "podmantest" ,
429
+ "-p" , "test" ,
430
+ "--authfile" , authFile ,
431
+ invalidArg ,
432
+ })
433
+ session .WaitWithDefaultTimeout ()
434
+ Expect (session ).Should (ExitWithError ())
435
+ }
436
+ })
437
+
438
+ It ("podman login and logout with repository push with invalid auth.json credentials" , func () {
439
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
440
+ // only `server` contains the correct login data
441
+ err := ioutil .WriteFile (authFile , []byte (fmt .Sprintf (`{"auths": {
442
+ "%s/podmantest": { "auth": "cG9kbWFudGVzdDp3cm9uZw==" },
443
+ "%s": { "auth": "cG9kbWFudGVzdDp0ZXN0" }
444
+ }}` , server , server )), 0644 )
445
+ Expect (err ).To (BeNil ())
446
+
447
+ session := podmanTest .Podman ([]string {
448
+ "push" ,
449
+ "--authfile" , authFile ,
450
+ ALPINE , server + "/podmantest/test-image" ,
451
+ })
452
+ session .WaitWithDefaultTimeout ()
453
+ Expect (session ).To (ExitWithError ())
454
+
455
+ session = podmanTest .Podman ([]string {
456
+ "push" ,
457
+ "--authfile" , authFile ,
458
+ ALPINE , server + "/test-image" ,
459
+ })
460
+ session .WaitWithDefaultTimeout ()
461
+ Expect (session ).To (Exit (0 ))
462
+ })
463
+
464
+ It ("podman login and logout with repository pull with wrong auth.json credentials" , func () {
465
+ authFile := filepath .Join (podmanTest .TempDir , "auth.json" )
466
+
467
+ testTarget := server + "/podmantest/test-alpine"
468
+ session := podmanTest .Podman ([]string {
469
+ "login" ,
470
+ "-u" , "podmantest" ,
471
+ "-p" , "test" ,
472
+ "--authfile" , authFile ,
473
+ testTarget ,
474
+ })
475
+ session .WaitWithDefaultTimeout ()
476
+ Expect (session ).Should (Exit (0 ))
477
+
478
+ session = podmanTest .Podman ([]string {
479
+ "push" ,
480
+ "--authfile" , authFile ,
481
+ ALPINE , testTarget ,
482
+ })
483
+ session .WaitWithDefaultTimeout ()
484
+ Expect (session ).Should (Exit (0 ))
485
+
486
+ // only `server + /podmantest` and `server` have the correct login data
487
+ err := ioutil .WriteFile (authFile , []byte (fmt .Sprintf (`{"auths": {
488
+ "%s/podmantest/test-alpine": { "auth": "cG9kbWFudGVzdDp3cm9uZw==" },
489
+ "%s/podmantest": { "auth": "cG9kbWFudGVzdDp0ZXN0" },
490
+ "%s": { "auth": "cG9kbWFudGVzdDp0ZXN0" }
491
+ }}` , server , server , server )), 0644 )
492
+ Expect (err ).To (BeNil ())
493
+
494
+ session = podmanTest .Podman ([]string {
495
+ "pull" ,
496
+ "--authfile" , authFile ,
497
+ server + "/podmantest/test-alpine" ,
498
+ })
499
+ session .WaitWithDefaultTimeout ()
500
+ Expect (session ).To (ExitWithError ())
501
+ })
287
502
})
0 commit comments