mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 17:17:46 +01:00
Merge pull request #11751 from wy65701436/fixes-11744
fix return code on getting non exist manifest
This commit is contained in:
commit
ef008fd4cf
@ -14,7 +14,9 @@
|
||||
|
||||
package lib
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package contenttrust
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/controller/artifact"
|
||||
@ -36,7 +35,7 @@ func Middleware() func(http.Handler) http.Handler {
|
||||
none := lib.ArtifactInfo{}
|
||||
af := lib.GetArtifactInfo(ctx)
|
||||
if af == none {
|
||||
return fmt.Errorf("artifactinfo middleware required before this middleware")
|
||||
return errors.New("artifactinfo middleware required before this middleware").WithCode(errors.NotFoundCode)
|
||||
}
|
||||
if len(af.Digest) == 0 {
|
||||
art, err := artifact.Ctl.GetByReference(ctx, af.Repository, af.Reference, nil)
|
||||
|
@ -131,6 +131,14 @@ func (suite *MiddlewareTestSuite) TestContentTrustDisabled() {
|
||||
suite.Equal(rr.Code, http.StatusOK)
|
||||
}
|
||||
|
||||
func (suite *MiddlewareTestSuite) TestNoneArtifact() {
|
||||
req := httptest.NewRequest("GET", "/v1/library/photon/manifests/nonexist", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
Middleware()(suite.next).ServeHTTP(rr, req)
|
||||
suite.Equal(rr.Code, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (suite *MiddlewareTestSuite) TestAuthenticatedUserPulling() {
|
||||
mock.OnAnything(suite.artifactController, "GetByReference").Return(suite.artifact, nil)
|
||||
mock.OnAnything(suite.projectController, "GetByName").Return(suite.project, nil)
|
||||
|
@ -40,7 +40,7 @@ func handlePush(req *http.Request) error {
|
||||
none := lib.ArtifactInfo{}
|
||||
art := lib.GetArtifactInfo(req.Context())
|
||||
if art == none {
|
||||
return errors.New("cannot get the manifest information from request context")
|
||||
return errors.New("cannot get the manifest information from request context").WithCode(errors.NotFoundCode)
|
||||
}
|
||||
|
||||
af, err := artifact.Ctl.GetByReference(req.Context(), art.Repository, art.Tag, &artifact.Option{
|
||||
|
@ -48,7 +48,7 @@ func Middleware() func(http.Handler) http.Handler {
|
||||
none := lib.ArtifactInfo{}
|
||||
info := lib.GetArtifactInfo(ctx)
|
||||
if info == none {
|
||||
return fmt.Errorf("artifactinfo middleware required before this middleware")
|
||||
return errors.New("artifactinfo middleware required before this middleware").WithCode(errors.NotFoundCode)
|
||||
}
|
||||
|
||||
art, err := artifactController.GetByReference(ctx, info.Repository, info.Reference, nil)
|
||||
|
@ -127,7 +127,7 @@ func (suite *MiddlewareTestSuite) TestNoArtifactInfo() {
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
Middleware()(suite.next).ServeHTTP(rr, req)
|
||||
suite.Equal(rr.Code, http.StatusInternalServerError)
|
||||
suite.Equal(rr.Code, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (suite *MiddlewareTestSuite) TestGetArtifactFailed() {
|
||||
|
Loading…
Reference in New Issue
Block a user