github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/e2e/trust/revoke_test.go (about)

     1  package trust
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/docker/cli/e2e/internal/fixtures"
     8  	"github.com/docker/cli/internal/test/environment"
     9  	"gotest.tools/v3/assert"
    10  	is "gotest.tools/v3/assert/cmp"
    11  	"gotest.tools/v3/fs"
    12  	"gotest.tools/v3/icmd"
    13  	"gotest.tools/v3/skip"
    14  )
    15  
    16  const (
    17  	revokeImage = "registry:5000/revoke:v1"
    18  	revokeRepo  = "registry:5000/revokerepo"
    19  )
    20  
    21  func TestRevokeImage(t *testing.T) {
    22  	skip.If(t, environment.RemoteDaemon())
    23  
    24  	dir := fixtures.SetupConfigFile(t)
    25  	defer dir.Remove()
    26  	setupTrustedImagesForRevoke(t, dir)
    27  	result := icmd.RunCmd(
    28  		icmd.Command("docker", "trust", "revoke", revokeImage),
    29  		fixtures.WithPassphrase("root_password", "repo_password"),
    30  		fixtures.WithNotary, fixtures.WithConfig(dir.Path()))
    31  	result.Assert(t, icmd.Success)
    32  	assert.Check(t, is.Contains(result.Stdout(), "Successfully deleted signature for registry:5000/revoke:v1"))
    33  }
    34  
    35  func TestRevokeRepo(t *testing.T) {
    36  	skip.If(t, environment.RemoteDaemon())
    37  
    38  	dir := fixtures.SetupConfigFile(t)
    39  	defer dir.Remove()
    40  	setupTrustedImagesForRevokeRepo(t, dir)
    41  	result := icmd.RunCmd(
    42  		icmd.Command("docker", "trust", "revoke", revokeRepo, "-y"),
    43  		fixtures.WithPassphrase("root_password", "repo_password"),
    44  		fixtures.WithNotary, fixtures.WithConfig(dir.Path()))
    45  	result.Assert(t, icmd.Success)
    46  	assert.Check(t, is.Contains(result.Stdout(), "Successfully deleted signature for registry:5000/revoke"))
    47  }
    48  
    49  func setupTrustedImagesForRevoke(t *testing.T, dir fs.Dir) {
    50  	icmd.RunCmd(icmd.Command("docker", "pull", fixtures.AlpineImage)).Assert(t, icmd.Success)
    51  	icmd.RunCommand("docker", "tag", fixtures.AlpineImage, revokeImage).Assert(t, icmd.Success)
    52  	icmd.RunCmd(
    53  		icmd.Command("docker", "-D", "trust", "sign", revokeImage),
    54  		fixtures.WithPassphrase("root_password", "repo_password"),
    55  		fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
    56  }
    57  
    58  func setupTrustedImagesForRevokeRepo(t *testing.T, dir fs.Dir) {
    59  	icmd.RunCmd(icmd.Command("docker", "pull", fixtures.AlpineImage)).Assert(t, icmd.Success)
    60  	icmd.RunCommand("docker", "tag", fixtures.AlpineImage, fmt.Sprintf("%s:v1", revokeRepo)).Assert(t, icmd.Success)
    61  	icmd.RunCmd(
    62  		icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v1", revokeRepo)),
    63  		fixtures.WithPassphrase("root_password", "repo_password"),
    64  		fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
    65  	icmd.RunCmd(icmd.Command("docker", "pull", fixtures.BusyboxImage)).Assert(t, icmd.Success)
    66  	icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, fmt.Sprintf("%s:v2", revokeRepo)).Assert(t, icmd.Success)
    67  	icmd.RunCmd(
    68  		icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v2", revokeRepo)),
    69  		fixtures.WithPassphrase("root_password", "repo_password"),
    70  		fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success)
    71  }