Skip to content

Commit

Permalink
Merge pull request #283 from veraison/greg-bug
Browse files Browse the repository at this point in the history
fix: error handling of malformed media types
  • Loading branch information
thomas-fossati authored Dec 10, 2024
2 parents 8811732 + 4b6eb25 commit cdeba76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions provisioning/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/veraison/services/capability"
"github.com/veraison/services/provisioning/provisioner"
"github.com/veraison/services/verification/verifier"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -70,11 +69,11 @@ func (o *Handler) Submit(c *gin.Context) {
isSupported, err := o.Provisioner.IsSupportedMediaType(mediaType)
if err != nil {
status := http.StatusInternalServerError
if errors.Unwrap(err) == verifier.ErrInputParam {
if errors.Unwrap(err) == provisioner.ErrInputParam {
status = http.StatusBadRequest
}

ReportProblem(c, status, fmt.Sprintf("could not check media type with verifier: %v", err))
ReportProblem(c, status, fmt.Sprintf("could not check media type with provisioner: %v", err))
return
}

Expand Down
4 changes: 2 additions & 2 deletions provisioning/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func New(vtsClient vtsclient.IVTSClient) IProvisioner {
}

func (p *Provisioner) IsSupportedMediaType(mt string) (bool, error) {
mt, err := api.NormalizeMediaType(mt)
normalizedMediaType, err := api.NormalizeMediaType(mt)
if err != nil {
return false, fmt.Errorf("%w: validation failed for %s (%v)", ErrInputParam, mt, err)
}
Expand All @@ -41,7 +41,7 @@ func (p *Provisioner) IsSupportedMediaType(mt string) (bool, error) {
}

for _, v := range mts.MediaTypes {
if v == mt {
if v == normalizedMediaType {
return true, nil
}
}
Expand Down

0 comments on commit cdeba76

Please sign in to comment.