check for os.PathError
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
7c405e8b6e
commit
57b20291bd
3 changed files with 19 additions and 3 deletions
|
|
@ -53,13 +53,21 @@ func GetLocalAttestations(path string) ([]*api.Attestation, error) {
|
|||
case ".json":
|
||||
attestations, err := loadBundleFromJSONFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bundle could not be loaded from JSON file at %s", path)
|
||||
var pathErr *os.PathError
|
||||
if errors.As(err, &pathErr) {
|
||||
return nil, fmt.Errorf("bundle could not be loaded from JSON file at %s", path)
|
||||
}
|
||||
return nil, fmt.Errorf("bundle content could not be parsed")
|
||||
}
|
||||
return attestations, nil
|
||||
case ".jsonl":
|
||||
attestations, err := loadBundlesFromJSONLinesFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bundles could not be loaded from JSON lines file at %s", path)
|
||||
var pathErr *os.PathError
|
||||
if errors.As(err, &pathErr) {
|
||||
return nil, fmt.Errorf("bundles could not be loaded from JSON lines file at %s", path)
|
||||
}
|
||||
return nil, fmt.Errorf("bundle content could not be parsed")
|
||||
}
|
||||
return attestations, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,14 @@ func TestGetLocalAttestations(t *testing.T) {
|
|||
require.ErrorIs(t, err, ErrUnrecognisedBundleExtension)
|
||||
require.Nil(t, attestations)
|
||||
})
|
||||
|
||||
t.Run("with non-existent bundle file", func(t *testing.T) {
|
||||
path := "../test/data/not-found-bundle.json"
|
||||
attestations, err := GetLocalAttestations(path)
|
||||
|
||||
require.ErrorContains(t, err, "bundle could not be loaded from JSON file")
|
||||
require.Nil(t, attestations)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilterAttestations(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ func (v *LiveSigstoreVerifier) Verify(attestations []*api.Attestation, policy ve
|
|||
verifier, issuer, err := v.chooseVerifier(apr.Attestation.Bundle)
|
||||
if err != nil {
|
||||
return &SigstoreResults{
|
||||
Error: fmt.Errorf("failed to find recognized issuer from bundle content: %v", err),
|
||||
Error: fmt.Errorf("failed to find recognized issuer from bundle content"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue