Merge pull request #11971 from wy65701436/fixes-11949

fix conformance issue on deleting manifest
This commit is contained in:
Daniel Jiang 2020-05-20 13:19:47 +08:00 committed by GitHub
commit b803975b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 7 deletions

View File

@ -25,6 +25,8 @@ const (
DIGESTINVALID = "DIGEST_INVALID" DIGESTINVALID = "DIGEST_INVALID"
// MANIFESTINVALID ... // MANIFESTINVALID ...
MANIFESTINVALID = "MANIFEST_INVALID" MANIFESTINVALID = "MANIFEST_INVALID"
// UNSUPPORTED is for digest UNSUPPORTED error
UNSUPPORTED = "UNSUPPORTED"
) )
// NotFoundError is error for the case of object not found // NotFoundError is error for the case of object not found

View File

@ -31,6 +31,7 @@ var (
errors.BadRequestCode: http.StatusBadRequest, errors.BadRequestCode: http.StatusBadRequest,
errors.DIGESTINVALID: http.StatusBadRequest, errors.DIGESTINVALID: http.StatusBadRequest,
errors.MANIFESTINVALID: http.StatusBadRequest, errors.MANIFESTINVALID: http.StatusBadRequest,
errors.UNSUPPORTED: http.StatusBadRequest,
errors.UnAuthorizedCode: http.StatusUnauthorized, errors.UnAuthorizedCode: http.StatusUnauthorized,
errors.ForbiddenCode: http.StatusForbidden, errors.ForbiddenCode: http.StatusForbidden,
errors.DENIED: http.StatusForbidden, errors.DENIED: http.StatusForbidden,

View File

@ -74,12 +74,8 @@ func deleteManifest(w http.ResponseWriter, req *http.Request) {
// Do not add the logic into GetByReference as it's a shared method for PUT/GET/DELETE/Internal call, // Do not add the logic into GetByReference as it's a shared method for PUT/GET/DELETE/Internal call,
// and NOT_FOUND satisfy PUT/GET/Internal call. // and NOT_FOUND satisfy PUT/GET/Internal call.
if _, err := digest.Parse(reference); err != nil { if _, err := digest.Parse(reference); err != nil {
switch err { serror.SendError(w, errors.Wrapf(err, "unsupported digest %s", reference).WithCode(errors.UNSUPPORTED))
case digest.ErrDigestInvalidFormat: return
serror.SendError(w, errors.New(nil).WithCode(errors.DIGESTINVALID).
WithMessage(digest.ErrDigestInvalidFormat.Error()))
return
}
} }
art, err := artifact.Ctl.GetByReference(req.Context(), repository, reference, nil) art, err := artifact.Ctl.GetByReference(req.Context(), repository, reference, nil)
if err != nil { if err != nil {

View File

@ -121,7 +121,7 @@ func (m *manifestTestSuite) TestDeleteManifest() {
}) })
req = httptest.NewRequest(http.MethodDelete, "/v2/library/hello-world/manifests/sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180", nil) req = httptest.NewRequest(http.MethodDelete, "/v2/library/hello-world/manifests/sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180", nil)
input := &beegocontext.BeegoInput{} input := &beegocontext.BeegoInput{}
input.SetParam(":reference", "sha527:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180") input.SetParam(":reference", "sha256:418fb88ec412e340cdbef913b8ca1bbe8f9e8dc705f9617414c1f2c8db980180")
*req = *(req.WithContext(context.WithValue(req.Context(), router.ContextKeyInput{}, input))) *req = *(req.WithContext(context.WithValue(req.Context(), router.ContextKeyInput{}, input)))
w = &httptest.ResponseRecorder{} w = &httptest.ResponseRecorder{}
mock.OnAnything(m.artCtl, "GetByReference").Return(&artifact.Artifact{}, nil) mock.OnAnything(m.artCtl, "GetByReference").Return(&artifact.Artifact{}, nil)