mirror of https://github.com/docker/cli.git
trust: update remove to error on empty references for consistency
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
parent
67cf09cbe1
commit
4e95fcd72c
|
@ -93,10 +93,6 @@ func revokeSignature(notaryRepo client.Repository, tag string) error {
|
|||
func revokeSingleSig(notaryRepo client.Repository, tag string) error {
|
||||
releasedTargetWithRole, err := notaryRepo.GetTargetByName(tag, trust.ReleasesRole, data.CanonicalTargetsRole)
|
||||
if err != nil {
|
||||
// if we try to remove the target and it doesn't exist, "succeed" silently
|
||||
if _, ok := err.(client.ErrNoSuchTarget); ok {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
releasedTarget := releasedTargetWithRole.Target
|
||||
|
@ -109,6 +105,10 @@ func revokeAllSigs(notaryRepo client.Repository) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if len(releasedTargetWithRoleList) == 0 {
|
||||
return fmt.Errorf("no signed tags to remove")
|
||||
}
|
||||
|
||||
// we need all the roles that signed each released target so we can remove from all roles.
|
||||
for _, releasedTargetWithRole := range releasedTargetWithRoleList {
|
||||
// remove from all roles
|
||||
|
|
|
@ -67,7 +67,6 @@ func TestTrustRevokeCommandOfflineErrors(t *testing.T) {
|
|||
cmd = newRevokeCommand(cli)
|
||||
cmd.SetArgs([]string{"reg-name.io/image", "-y"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
testutil.ErrorContains(t, cmd.Execute(), "could not remove signature for reg-name.io/image: client is offline")
|
||||
|
||||
cli = test.NewFakeCli(&fakeClient{})
|
||||
cli.SetNotaryClient(getOfflineNotaryRepository)
|
||||
|
@ -115,16 +114,14 @@ func TestTrustRevokeCommandEmptyNotaryRepo(t *testing.T) {
|
|||
cmd = newRevokeCommand(cli)
|
||||
cmd.SetArgs([]string{"reg-name.io/image", "-y"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Contains(t, cli.OutBuffer().String(), "Successfully deleted signature for reg-name.io/image")
|
||||
testutil.ErrorContains(t, cmd.Execute(), "could not remove signature for reg-name.io/image: no signed tags to remove")
|
||||
|
||||
cli = test.NewFakeCli(&fakeClient{})
|
||||
cli.SetNotaryClient(getEmptyTargetsNotaryRepository)
|
||||
cmd = newRevokeCommand(cli)
|
||||
cmd.SetArgs([]string{"reg-name.io/image:tag"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Contains(t, cli.OutBuffer().String(), "Successfully deleted signature for reg-name.io/image:tag")
|
||||
testutil.ErrorContains(t, cmd.Execute(), "could not remove signature for reg-name.io/image:tag: No valid trust data for tag")
|
||||
}
|
||||
|
||||
func TestNewRevokeTrustAllSigConfirmation(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue