Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error message for dangling reference index #402

Merged
8 changes: 7 additions & 1 deletion notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

orasRegistry "oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"

"github.com/notaryproject/notation-core-go/signature"
"github.com/notaryproject/notation-core-go/signature/cose"
Expand All @@ -41,6 +42,7 @@ import (
)

var errDoneVerification = errors.New("done verification")

var reservedAnnotationPrefixes = [...]string{"io.cncf.notary"}

// SignerSignOptions contains parameters for Signer.Sign.
Expand Down Expand Up @@ -166,7 +168,11 @@ func Sign(ctx context.Context, signer Signer, repo registry.Repository, signOpts
logger.Debugf("Pushing signature of artifact descriptor: %+v, signature media type: %v", targetDesc, signOpts.SignatureMediaType)
_, _, err = repo.PushSignature(ctx, signOpts.SignatureMediaType, sig, targetDesc, annotations)
if err != nil {
logger.Error("Failed to push the signature")
var referrerError *remote.ReferrersError
// do not log an error for failing to delete referral index
if !errors.As(err, &referrerError) || !referrerError.IsReferrersIndexDelete() {
logger.Error("Failed to push the signature")
}
return ocispec.Descriptor{}, ErrorPushSignatureFailed{Msg: err.Error()}
}

Expand Down
17 changes: 17 additions & 0 deletions notation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/notaryproject/notation-go/verifier/trustpolicy"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/registry/remote"
)

var expectedMetadata = map[string]string{"foo": "bar", "bar": "foo"}
Expand Down Expand Up @@ -158,6 +159,22 @@ func TestSignSuccessWithUserMetadata(t *testing.T) {
}
}

func TestSignWithDanglingReferrersIndex(t *testing.T) {
repo := mock.NewRepository()
repo.PushSignatureError = &remote.ReferrersError{
Op: "DeleteReferrersIndex",
Err: errors.New("error"),
}
opts := SignOptions{}
opts.ArtifactReference = mock.SampleArtifactUri
opts.SignatureMediaType = jws.MediaTypeEnvelope

_, err := Sign(context.Background(), &dummySigner{}, repo, opts)
if err == nil {
t.Fatalf("no error occurred, expected error")
}
}

func TestSignWithNilRepo(t *testing.T) {
opts := SignOptions{}
opts.ArtifactReference = mock.SampleArtifactUri
Expand Down
Loading