Skip to content

Commit db1e57b

Browse files
committed
e2e: merge TLS test, generate certs dynamically
Address reviewer feedback on docker/cli PR docker#7007: - Merge TestPullPushPrivateRepository and TestPullPushTlsRepository into one test with "insecure" and "tls" subtests - Generate TLS certs at setup time instead of committing them - Remove committed cert files from git Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
1 parent c9fc077 commit db1e57b

7 files changed

Lines changed: 73 additions & 192 deletions

File tree

e2e/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Generated by gen-certs.sh at setup time
2+
testdata/registry/certs/ca.crt
3+
testdata/registry/certs/ca.key
4+
testdata/registry/certs/tlsregistry.crt
5+
testdata/registry/certs/tlsregistry.key

e2e/image/private_test.go

Lines changed: 60 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1614
func 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

12279
func assertAuthDenied(t *testing.T, result *icmd.Result) {

e2e/testdata/registry/certs/ca.crt

Lines changed: 0 additions & 17 deletions
This file was deleted.

e2e/testdata/registry/certs/ca.key

Lines changed: 0 additions & 27 deletions
This file was deleted.

e2e/testdata/registry/certs/tlsregistry.crt

Lines changed: 0 additions & 18 deletions
This file was deleted.

e2e/testdata/registry/certs/tlsregistry.key

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/test/e2e/run

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ setup() {
2626
export TEST_CONNHELPER_SSH_ID_RSA_PUB
2727
file="${file}:./e2e/compose-env.connhelper-ssh.yaml"
2828
fi
29+
# Generate TLS certificates for the TLS-enabled private registry.
30+
# The certs are baked into the tlsregistry and engine container images,
31+
# so they must exist on disk before docker compose up --build.
32+
# gen-certs.sh handles its own directory navigation.
33+
if [ ! -f e2e/testdata/registry/certs/ca.crt ]; then
34+
sh e2e/testdata/registry/certs/gen-certs.sh
35+
fi
36+
2937
COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker compose up --build -d >&2
3038

3139
# Ensure supporting services exist before running tests. If one fails to start,

0 commit comments

Comments
 (0)