From 99fc419855b2e06a8e20d06dc68c86937a1ec8f7 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 3 Aug 2022 17:22:32 +0200 Subject: [PATCH] Send correct NuGet status codes (#20647) * Fixed status codes. * Fixed status codes. --- integrations/api_packages_nuget_test.go | 6 +++--- routers/api/packages/nuget/nuget.go | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/integrations/api_packages_nuget_test.go b/integrations/api_packages_nuget_test.go index e69dd0ff9b669..346f391f82fcc 100644 --- a/integrations/api_packages_nuget_test.go +++ b/integrations/api_packages_nuget_test.go @@ -122,7 +122,7 @@ func TestPackageNuGet(t *testing.T) { req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)) req = AddBasicAuthHeader(req, user.Name) - MakeRequest(t, req, http.StatusBadRequest) + MakeRequest(t, req, http.StatusConflict) }) t.Run("SymbolPackage", func(t *testing.T) { @@ -208,7 +208,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`) req = NewRequestWithBody(t, "PUT", fmt.Sprintf("%s/symbolpackage", url), createPackage(packageName, "SymbolsPackage")) req = AddBasicAuthHeader(req, user.Name) - MakeRequest(t, req, http.StatusBadRequest) + MakeRequest(t, req, http.StatusConflict) }) }) @@ -352,7 +352,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`) req := NewRequest(t, "DELETE", fmt.Sprintf("%s/%s/%s", url, packageName, packageVersion)) req = AddBasicAuthHeader(req, user.Name) - MakeRequest(t, req, http.StatusOK) + MakeRequest(t, req, http.StatusNoContent) pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNuGet) assert.NoError(t, err) diff --git a/routers/api/packages/nuget/nuget.go b/routers/api/packages/nuget/nuget.go index b7667a32225a2..4d630708b968c 100644 --- a/routers/api/packages/nuget/nuget.go +++ b/routers/api/packages/nuget/nuget.go @@ -217,7 +217,7 @@ func UploadPackage(ctx *context.Context) { ) if err != nil { if err == packages_model.ErrDuplicatePackageVersion { - apiError(ctx, http.StatusBadRequest, err) + apiError(ctx, http.StatusConflict, err) return } apiError(ctx, http.StatusInternalServerError, err) @@ -274,7 +274,7 @@ func UploadSymbolPackage(ctx *context.Context) { case packages_model.ErrPackageNotExist: apiError(ctx, http.StatusNotFound, err) case packages_model.ErrDuplicatePackageFile: - apiError(ctx, http.StatusBadRequest, err) + apiError(ctx, http.StatusConflict, err) default: apiError(ctx, http.StatusInternalServerError, err) } @@ -299,7 +299,7 @@ func UploadSymbolPackage(ctx *context.Context) { if err != nil { switch err { case packages_model.ErrDuplicatePackageFile: - apiError(ctx, http.StatusBadRequest, err) + apiError(ctx, http.StatusConflict, err) default: apiError(ctx, http.StatusInternalServerError, err) } @@ -414,4 +414,6 @@ func DeletePackage(ctx *context.Context) { } apiError(ctx, http.StatusInternalServerError, err) } + + ctx.Status(http.StatusNoContent) }