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"
|
2017-10-10 17:04:32 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/golden"
|
2017-10-06 19:32:57 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
2018-05-17 07:11:59 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/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())
|
|
|
|
|
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-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
|
|
|
}
|