@@ -10,113 +10,70 @@ import (
1010 "gotest.tools/v3/icmd"
1111)
1212
13- const privateRegistryPrefix = "privateregistry:5001"
14-
1513// Regression test for https://github.com/docker/cli/issues/5963
1614func TestPullPushPrivateRepository (t * testing.T ) {
1715 t .Parallel ()
1816
19- dir := fixtures .SetupConfigFile (t )
20- t .Cleanup (dir .Remove )
21- emptyConfigDir := t .TempDir ()
22-
23- sourceImage := fixtures .AlpineImage
24- privateImage := privateRegistryPrefix + "/private/alpine:test-private-pull-push"
25-
26- runWithPrivateRegistryRetry (t ,
27- icmd .Command ("docker" , "pull" , sourceImage ),
28- ).Assert (t , icmd .Success )
29- t .Cleanup (func () {
30- icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
31- })
32-
33- icmd .RunCommand ("docker" , "tag" , sourceImage , privateImage ).Assert (t , icmd .Success )
34-
35- pushNoAuth := runWithPrivateRegistryRetry (t ,
36- icmd .Command ("docker" , "push" , privateImage ),
37- fixtures .WithConfig (emptyConfigDir ),
38- )
39- pushNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
40- assertAuthDenied (t , pushNoAuth )
41-
42- pushWithAuth := runWithPrivateRegistryRetry (t ,
43- icmd .Command ("docker" , "push" , privateImage ),
44- fixtures .WithConfig (dir .Path ()),
45- )
46- pushWithAuth .Assert (t , icmd .Success )
47- // Docker omits the tag in the "push refers to repository" line; strip it before asserting.
48- privateRepo := privateImage [:strings .LastIndex (privateImage , ":" )]
49- assert .Check (t , strings .Contains (pushWithAuth .Combined (), "The push refers to repository [" + privateRepo + "]" ), pushWithAuth .Combined ())
50-
51- icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
52-
53- pullNoAuth := runWithPrivateRegistryRetry (t ,
54- icmd .Command ("docker" , "pull" , privateImage ),
55- fixtures .WithConfig (emptyConfigDir ),
56- )
57- pullNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
58- assertAuthDenied (t , pullNoAuth )
59-
60- pullWithAuth := runWithPrivateRegistryRetry (t ,
61- icmd .Command ("docker" , "pull" , privateImage ),
62- fixtures .WithConfig (dir .Path ()),
63- )
64- pullWithAuth .Assert (t , icmd .Success )
65- assert .Check (t , strings .Contains (pullWithAuth .Combined (), privateImage ), pullWithAuth .Combined ())
66- }
67-
68- // TestPullPushTlsRepository verifies authenticated pull/push against a
69- // TLS-enabled private registry (not behind --insecure-registry).
70- func TestPullPushTlsRepository (t * testing.T ) {
71- t .Parallel ()
72-
73- dir := fixtures .SetupConfigFile (t )
74- t .Cleanup (dir .Remove )
75- emptyConfigDir := t .TempDir ()
76-
77- const tlsRegistryPrefix = "tlsregistry:5003"
78- sourceImage := fixtures .AlpineImage
79- privateImage := tlsRegistryPrefix + "/private/alpine:test-tls-pull-push"
80-
81- runWithPrivateRegistryRetry (t ,
82- icmd .Command ("docker" , "pull" , sourceImage ),
83- ).Assert (t , icmd .Success )
84- t .Cleanup (func () {
85- icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
86- })
87-
88- icmd .RunCommand ("docker" , "tag" , sourceImage , privateImage ).Assert (t , icmd .Success )
89-
90- pushNoAuth := runWithPrivateRegistryRetry (t ,
91- icmd .Command ("docker" , "push" , privateImage ),
92- fixtures .WithConfig (emptyConfigDir ),
93- )
94- pushNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
95- assertAuthDenied (t , pushNoAuth )
96-
97- pushWithAuth := runWithPrivateRegistryRetry (t ,
98- icmd .Command ("docker" , "push" , privateImage ),
99- fixtures .WithConfig (dir .Path ()),
100- )
101- pushWithAuth .Assert (t , icmd .Success )
102- privateRepo := privateImage [:strings .LastIndex (privateImage , ":" )]
103- assert .Check (t , strings .Contains (pushWithAuth .Combined (), "The push refers to repository [" + privateRepo + "]" ), pushWithAuth .Combined ())
104-
105- icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
106-
107- pullNoAuth := runWithPrivateRegistryRetry (t ,
108- icmd .Command ("docker" , "pull" , privateImage ),
109- fixtures .WithConfig (emptyConfigDir ),
110- )
111- pullNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
112- assertAuthDenied (t , pullNoAuth )
113-
114- pullWithAuth := runWithPrivateRegistryRetry (t ,
115- icmd .Command ("docker" , "pull" , privateImage ),
116- fixtures .WithConfig (dir .Path ()),
117- )
118- pullWithAuth .Assert (t , icmd .Success )
119- assert .Check (t , strings .Contains (pullWithAuth .Combined (), privateImage ), pullWithAuth .Combined ())
17+ for _ , tc := range []struct {
18+ name string
19+ registryPrefix string
20+ tagSuffix string
21+ }{
22+ {name : "insecure" , registryPrefix : "privateregistry:5001" , tagSuffix : "private" },
23+ {name : "tls" , registryPrefix : "tlsregistry:5003" , tagSuffix : "tls" },
24+ } {
25+ t .Run (tc .name , func (t * testing.T ) {
26+ t .Parallel ()
27+
28+ dir := fixtures .SetupConfigFile (t )
29+ t .Cleanup (dir .Remove )
30+ emptyConfigDir := t .TempDir ()
31+
32+ sourceImage := fixtures .AlpineImage
33+ privateImage := tc .registryPrefix + "/private/alpine:test-" + tc .tagSuffix + "-pull-push"
34+
35+ runWithPrivateRegistryRetry (t ,
36+ icmd .Command ("docker" , "pull" , sourceImage ),
37+ ).Assert (t , icmd .Success )
38+ t .Cleanup (func () {
39+ icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
40+ })
41+
42+ icmd .RunCommand ("docker" , "tag" , sourceImage , privateImage ).Assert (t , icmd .Success )
43+
44+ pushNoAuth := runWithPrivateRegistryRetry (t ,
45+ icmd .Command ("docker" , "push" , privateImage ),
46+ fixtures .WithConfig (emptyConfigDir ),
47+ )
48+ pushNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
49+ assertAuthDenied (t , pushNoAuth )
50+
51+ pushWithAuth := runWithPrivateRegistryRetry (t ,
52+ icmd .Command ("docker" , "push" , privateImage ),
53+ fixtures .WithConfig (dir .Path ()),
54+ )
55+ pushWithAuth .Assert (t , icmd .Success )
56+ // Docker omits the tag in the "push refers to repository" line; strip it before asserting.
57+ privateRepo := privateImage [:strings .LastIndex (privateImage , ":" )]
58+ assert .Check (t , strings .Contains (pushWithAuth .Combined (), "The push refers to repository [" + privateRepo + "]" ), pushWithAuth .Combined ())
59+
60+ icmd .RunCommand ("docker" , "image" , "rm" , "-f" , privateImage ).Assert (t , icmd .Success )
61+
62+ pullNoAuth := runWithPrivateRegistryRetry (t ,
63+ icmd .Command ("docker" , "pull" , privateImage ),
64+ fixtures .WithConfig (emptyConfigDir ),
65+ )
66+ pullNoAuth .Assert (t , icmd.Expected {ExitCode : 1 })
67+ assertAuthDenied (t , pullNoAuth )
68+
69+ pullWithAuth := runWithPrivateRegistryRetry (t ,
70+ icmd .Command ("docker" , "pull" , privateImage ),
71+ fixtures .WithConfig (dir .Path ()),
72+ )
73+ pullWithAuth .Assert (t , icmd .Success )
74+ assert .Check (t , strings .Contains (pullWithAuth .Combined (), privateImage ), pullWithAuth .Combined ())
75+ })
76+ }
12077}
12178
12279func assertAuthDenied (t * testing.T , result * icmd.Result ) {
0 commit comments