2017-10-06 19:32:57 -04:00
|
|
|
package image
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-11-13 20:18:04 -05:00
|
|
|
"github.com/docker/cli/e2e/internal/fixtures"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
const registryPrefix = "registry:5000"
|
|
|
|
|
|
|
|
func TestPullWithContentTrust(t *testing.T) {
|
2017-10-10 17:04:32 -04:00
|
|
|
image := createMaskedTrustedRemoteImage(t, "trust", "latest")
|
2017-10-06 19:32:57 -04:00
|
|
|
|
2017-11-13 20:18:04 -05:00
|
|
|
result := icmd.RunCmd(icmd.Command("docker", "pull", image), 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
|
|
|
|
2017-10-10 17:04:32 -04:00
|
|
|
// createMaskedTrustedRemoteImage creates a remote image that is signed with
|
|
|
|
// content trust, then pushes a different untrusted image at the same tag.
|
|
|
|
func createMaskedTrustedRemoteImage(t *testing.T, repo, tag string) string {
|
|
|
|
image := createTrustedRemoteImage(t, repo, tag)
|
2017-10-10 15:00:52 -04:00
|
|
|
createNamedUnsignedImageFromBusyBox(t, image)
|
2017-10-10 17:04:32 -04:00
|
|
|
return image
|
2017-10-06 19:32:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func createTrustedRemoteImage(t *testing.T, repo, tag string) string {
|
|
|
|
image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag)
|
2017-11-13 20:18:04 -05:00
|
|
|
icmd.RunCommand("docker", "pull", fixtures.AlpineImage).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.AlpineImage, image).Assert(t, icmd.Success)
|
2017-10-10 17:04:32 -04:00
|
|
|
result := icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "push", image),
|
2017-11-13 20:18:04 -05:00
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"), fixtures.WithTrust, fixtures.WithNotary)
|
2017-10-10 17:04:32 -04:00
|
|
|
result.Assert(t, icmd.Success)
|
2017-10-06 19:32:57 -04:00
|
|
|
icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success)
|
|
|
|
return image
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:00:52 -04:00
|
|
|
func createNamedUnsignedImageFromBusyBox(t *testing.T, image string) {
|
2017-11-13 20:18:04 -05:00
|
|
|
icmd.RunCommand("docker", "pull", fixtures.BusyboxImage).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, image).Assert(t, icmd.Success)
|
2017-10-10 15:00:52 -04:00
|
|
|
icmd.RunCommand("docker", "push", image).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success)
|
|
|
|
}
|