Skip to content

Commit

Permalink
Merge pull request #14 from nmiyake/fixEnvelopeVerifyPanic
Browse files Browse the repository at this point in the history
Ensure that EnvelopeVerifier.Verify does not panic on nil envelope
  • Loading branch information
adityasaky authored Mar 11, 2022
2 parents e5b9b0e + afd7bcc commit 7438362
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dsse/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type AcceptedKey struct {
}

func (ev *EnvelopeVerifier) Verify(e *Envelope) ([]AcceptedKey, error) {
if e == nil {
return nil, errors.New("cannot verify a nil envelope")
}

if len(e.Signatures) == 0 {
return nil, ErrNoSignature
}
Expand Down
9 changes: 9 additions & 0 deletions dsse/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import (
"github.com/stretchr/testify/assert"
)

func TestEnvelopeVerifier_Verify_HandlesNil(t *testing.T) {
verifier, err := NewEnvelopeVerifier(&mockVerifier{})
assert.NoError(t, err)

acceptedKeys, err := verifier.Verify(nil)
assert.Empty(t, acceptedKeys)
assert.EqualError(t, err, "cannot verify a nil envelope")
}

type mockVerifier struct {
returnErr error
}
Expand Down

0 comments on commit 7438362

Please sign in to comment.