Skip to content

Commit

Permalink
Return 404 if keyId not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostlevels committed Sep 1, 2023
1 parent 5bb9820 commit 652c248
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions appvalidate/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

var (
ErrDuplicateKeyId = errors.New("duplicate key id")
ErrKeyIdNotFound = errors.New("key id not found")
)

type Filter struct {
Expand Down
4 changes: 4 additions & 0 deletions auth/service/api/v1/appvalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (r *Router) VerifyAttestation(res rest.ResponseWriter, req *rest.Request) {
"keyId": attestVerify.KeyID,
}
log.LoggerFromContext(ctx).WithFields(fields).WithError(err).Error("unable to verify attestation")
if errors.Is(err, appvalidate.ErrKeyIdNotFound) {
responder.Error(http.StatusNotFound, err)
return
}
if errors.Is(err, appvalidate.ErrAttestationVerificationFailed) {
responder.Error(http.StatusBadRequest, err)
return
Expand Down
5 changes: 4 additions & 1 deletion auth/store/mongo/app_validate_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (r *AppValidateRepository) GetAttestationChallenge(ctx context.Context, f a
WithError(err).
Debug("GetAttestationChallenge")
if err != nil {
if err == mongo.ErrNoDocuments {
return "", appvalidate.ErrKeyIdNotFound
}
return "", err
}
return av.AttestationChallenge, nil
Expand Down Expand Up @@ -124,7 +127,7 @@ func (r *AppValidateRepository) UpdateAttestation(ctx context.Context, f appvali
return err
}
if res.ModifiedCount == 0 {
return errors.New("unable to find app validation object")
return appvalidate.ErrKeyIdNotFound
}
return nil
}
Expand Down

0 comments on commit 652c248

Please sign in to comment.