Files
docker-cli/components/cli/e2e/container/pull_test.go
Riyaz Faizullabhoy 125ffb8b1b update e2e tests for content trust tests
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
(cherry picked from commit 6e3bafd06b)
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2017-10-11 10:47:45 -07:00

52 lines
1.7 KiB
Go

package container
import (
"fmt"
"os"
"strings"
"testing"
"github.com/gotestyourself/gotestyourself/icmd"
)
const notaryURL = "https://notary-server:4443"
const registryPrefix = "registry:5000"
func TestPullWithContentTrust(t *testing.T) {
image := createTrustedRemoteImage(t, "trust", "latest")
icmd.RunCmd(trustedCmdNoPassphrases(icmd.Command("docker", "pull", image))).Assert(t, icmd.Success)
// test that pulling without the tag defaults to latest
imageWithoutTag := strings.TrimSuffix(image, ":latest")
icmd.RunCmd(trustedCmdNoPassphrases(icmd.Command("docker", "pull", imageWithoutTag))).Assert(t, icmd.Success)
}
func createTrustedRemoteImage(t *testing.T, repo, tag string) string {
image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag)
icmd.RunCommand("docker", "pull", alpineImage).Assert(t, icmd.Success)
icmd.RunCommand("docker", "tag", alpineImage, image).Assert(t, icmd.Success)
icmd.RunCmd(trustedCmdWithPassphrases(icmd.Command("docker", "push", image), "root_password", "repo_password")).Assert(t, icmd.Success)
icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success)
return image
}
func trustedCmdWithPassphrases(cmd icmd.Cmd, rootPwd, repositoryPwd string) icmd.Cmd {
env := append(os.Environ(), []string{
"DOCKER_CONTENT_TRUST=1",
fmt.Sprintf("DOCKER_CONTENT_TRUST_SERVER=%s", notaryURL),
fmt.Sprintf("DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE=%s", rootPwd),
fmt.Sprintf("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=%s", repositoryPwd),
}...)
cmd.Env = append(cmd.Env, env...)
return cmd
}
func trustedCmdNoPassphrases(cmd icmd.Cmd) icmd.Cmd {
env := append(os.Environ(), []string{
"DOCKER_CONTENT_TRUST=1",
fmt.Sprintf("DOCKER_CONTENT_TRUST_SERVER=%s", notaryURL),
}...)
cmd.Env = append(cmd.Env, env...)
return cmd
}