2017-11-13 20:18:10 -05:00
|
|
|
package trust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/cli/e2e/internal/fixtures"
|
2018-05-17 07:11:59 -04:00
|
|
|
"github.com/docker/cli/internal/test/environment"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/fs"
|
|
|
|
"gotest.tools/icmd"
|
|
|
|
"gotest.tools/skip"
|
2017-11-13 20:18:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
revokeImage = "registry:5000/revoke:v1"
|
|
|
|
revokeRepo = "registry:5000/revokerepo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRevokeImage(t *testing.T) {
|
2018-05-17 07:11:59 -04:00
|
|
|
skip.If(t, environment.RemoteDaemon())
|
|
|
|
|
2017-11-13 20:18:10 -05:00
|
|
|
dir := fixtures.SetupConfigFile(t)
|
|
|
|
defer dir.Remove()
|
|
|
|
setupTrustedImagesForRevoke(t, dir)
|
|
|
|
result := icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "trust", "revoke", revokeImage),
|
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"),
|
|
|
|
fixtures.WithNotary, fixtures.WithConfig(dir.Path()))
|
|
|
|
result.Assert(t, icmd.Success)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Contains(result.Stdout(), "Successfully deleted signature for registry:5000/revoke:v1"))
|
2017-11-13 20:18:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRevokeRepo(t *testing.T) {
|
2018-05-17 07:11:59 -04:00
|
|
|
skip.If(t, environment.RemoteDaemon())
|
|
|
|
|
2017-11-13 20:18:10 -05:00
|
|
|
dir := fixtures.SetupConfigFile(t)
|
|
|
|
defer dir.Remove()
|
|
|
|
setupTrustedImagesForRevokeRepo(t, dir)
|
|
|
|
result := icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "trust", "revoke", revokeRepo, "-y"),
|
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"),
|
|
|
|
fixtures.WithNotary, fixtures.WithConfig(dir.Path()))
|
|
|
|
result.Assert(t, icmd.Success)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Contains(result.Stdout(), "Successfully deleted signature for registry:5000/revoke"))
|
2017-11-13 20:18:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func setupTrustedImagesForRevoke(t *testing.T, dir fs.Dir) {
|
|
|
|
icmd.RunCmd(icmd.Command("docker", "pull", fixtures.AlpineImage)).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.AlpineImage, revokeImage).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "-D", "trust", "sign", revokeImage),
|
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"),
|
|
|
|
fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupTrustedImagesForRevokeRepo(t *testing.T, dir fs.Dir) {
|
|
|
|
icmd.RunCmd(icmd.Command("docker", "pull", fixtures.AlpineImage)).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.AlpineImage, fmt.Sprintf("%s:v1", revokeRepo)).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v1", revokeRepo)),
|
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"),
|
|
|
|
fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCmd(icmd.Command("docker", "pull", fixtures.BusyboxImage)).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, fmt.Sprintf("%s:v2", revokeRepo)).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCmd(
|
|
|
|
icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v2", revokeRepo)),
|
|
|
|
fixtures.WithPassphrase("root_password", "repo_password"),
|
|
|
|
fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
|
|
|
|
}
|