2017-10-06 19:32:57 -04:00
|
|
|
package image
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-11-13 20:18:04 -05:00
|
|
|
"github.com/docker/cli/e2e/internal/fixtures"
|
2018-05-17 07:11:59 -04:00
|
|
|
"github.com/docker/cli/internal/test/environment"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/golden"
|
|
|
|
"gotest.tools/v3/icmd"
|
|
|
|
"gotest.tools/v3/skip"
|
2017-10-06 19:32:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const registryPrefix = "registry:5000"
|
|
|
|
|
|
|
|
func TestPullWithContentTrust(t *testing.T) {
|
2018-05-17 07:11:59 -04:00
|
|
|
skip.If(t, environment.RemoteDaemon())
|
|
|
|
|
2023-02-24 06:36:53 -05:00
|
|
|
// Digests in golden files are linux/amd64 specific.
|
|
|
|
// TODO: Fix this test and make it work on all platforms.
|
|
|
|
environment.SkipIfNotPlatform(t, "linux/amd64")
|
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
dir := fixtures.SetupConfigFile(t)
|
|
|
|
defer dir.Remove()
|
|
|
|
image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull", "latest")
|
|
|
|
defer func() {
|
|
|
|
icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
|
|
|
|
}()
|
2017-10-06 19:32:57 -04:00
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
result := icmd.RunCmd(icmd.Command("docker", "pull", image),
|
|
|
|
fixtures.WithConfig(dir.Path()),
|
|
|
|
fixtures.WithTrust,
|
|
|
|
fixtures.WithNotary,
|
|
|
|
)
|
2017-10-23 13:41:52 -04:00
|
|
|
result.Assert(t, icmd.Success)
|
|
|
|
golden.Assert(t, result.Stderr(), "pull-with-content-trust-err.golden")
|
2017-10-10 17:04:32 -04:00
|
|
|
golden.Assert(t, result.Stdout(), "pull-with-content-trust.golden")
|
|
|
|
}
|
2017-10-06 19:32:57 -04:00
|
|
|
|
2018-12-19 07:48:41 -05:00
|
|
|
func TestPullQuiet(t *testing.T) {
|
|
|
|
result := icmd.RunCommand("docker", "pull", "--quiet", fixtures.AlpineImage)
|
|
|
|
result.Assert(t, icmd.Success)
|
2023-02-23 09:00:59 -05:00
|
|
|
assert.Check(t, is.Equal(result.Stdout(), "registry:5000/alpine:frozen\n"))
|
2018-12-19 07:48:41 -05:00
|
|
|
assert.Check(t, is.Equal(result.Stderr(), ""))
|
|
|
|
}
|
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
func TestPullWithContentTrustUsesCacheWhenNotaryUnavailable(t *testing.T) {
|
2018-05-17 07:11:59 -04:00
|
|
|
skip.If(t, environment.RemoteDaemon())
|
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
dir := fixtures.SetupConfigFile(t)
|
|
|
|
defer dir.Remove()
|
|
|
|
image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull-unreachable", "latest")
|
|
|
|
defer func() {
|
|
|
|
icmd.RunCommand("docker", "image", "rm", image).Assert(t, icmd.Success)
|
|
|
|
}()
|
|
|
|
result := icmd.RunCmd(icmd.Command("docker", "pull", image),
|
|
|
|
fixtures.WithConfig(dir.Path()),
|
|
|
|
fixtures.WithTrust,
|
|
|
|
fixtures.WithNotaryServer("https://invalidnotaryserver"),
|
|
|
|
)
|
|
|
|
result.Assert(t, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "error contacting notary server",
|
|
|
|
})
|
2017-10-06 19:32:57 -04:00
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
// Do valid trusted pull to warm cache
|
|
|
|
result = icmd.RunCmd(icmd.Command("docker", "pull", image),
|
|
|
|
fixtures.WithConfig(dir.Path()),
|
|
|
|
fixtures.WithTrust,
|
|
|
|
fixtures.WithNotary,
|
|
|
|
)
|
|
|
|
result.Assert(t, icmd.Success)
|
|
|
|
result = icmd.RunCommand("docker", "rmi", image)
|
2017-10-10 17:04:32 -04:00
|
|
|
result.Assert(t, icmd.Success)
|
2017-10-06 19:32:57 -04:00
|
|
|
|
2018-03-06 05:15:18 -05:00
|
|
|
// Try pull again with invalid notary server, should use cache
|
|
|
|
result = icmd.RunCmd(icmd.Command("docker", "pull", image),
|
|
|
|
fixtures.WithConfig(dir.Path()),
|
|
|
|
fixtures.WithTrust,
|
|
|
|
fixtures.WithNotaryServer("https://invalidnotaryserver"),
|
|
|
|
)
|
|
|
|
result.Assert(t, icmd.Success)
|
2017-10-10 15:00:52 -04:00
|
|
|
}
|