]> source.dussan.org Git - gitea.git/commitdiff
Fix the wrong HTTP response status code for duplicate packages (#27480)
authorNanguan Lin <70063547+lng2020@users.noreply.github.com>
Tue, 10 Oct 2023 13:39:58 +0000 (21:39 +0800)
committerGitHub <noreply@github.com>
Tue, 10 Oct 2023 13:39:58 +0000 (15:39 +0200)
fix #27470
(hope there is nothing missing ðŸ˜¢ )

---------

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
27 files changed:
docs/content/usage/packages/alpine.en-us.md
docs/content/usage/packages/composer.en-us.md
docs/content/usage/packages/conan.en-us.md
docs/content/usage/packages/conda.en-us.md
docs/content/usage/packages/cran.en-us.md
docs/content/usage/packages/debian.en-us.md
docs/content/usage/packages/go.en-us.md
docs/content/usage/packages/swift.en-us.md
docs/content/usage/packages/vagrant.en-us.md
routers/api/packages/alpine/alpine.go
routers/api/packages/chef/chef.go
routers/api/packages/composer/composer.go
routers/api/packages/conan/conan.go
routers/api/packages/debian/debian.go
routers/api/packages/maven/maven.go
routers/api/packages/npm/npm.go
routers/api/packages/pub/pub.go
routers/api/packages/pypi/pypi.go
routers/api/packages/rubygems/rubygems.go
tests/integration/api_packages_chef_test.go
tests/integration/api_packages_composer_test.go
tests/integration/api_packages_debian_test.go
tests/integration/api_packages_maven_test.go
tests/integration/api_packages_npm_test.go
tests/integration/api_packages_pub_test.go
tests/integration/api_packages_pypi_test.go
tests/integration/api_packages_rubygems_test.go

index 1fcbe848537a39a3ca85b5c85784df3d61d96c83..00331f3bb1702135dfa909f2e79bacce06014d2a 100644 (file)
@@ -77,6 +77,7 @@ curl --user your_username:your_password_or_token \
 ```
 
 If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
+
 You cannot publish a file with the same name twice to a package. You must delete the existing package file first.
 
 The server responds with the following HTTP Status codes.
index 7fbd77ef5d73f54ed9e34a539afe197c1ab04063..60ad52ac2d44283880dadef2db7a99afa9375296 100644 (file)
@@ -25,6 +25,7 @@ To work with the Composer package registry, you can use [Composer](https://getco
 
 To publish a Composer package perform a HTTP PUT operation with the package content in the request body.
 The package content must be the zipped PHP project with the `composer.json` file.
+
 You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
 
 ```
@@ -64,7 +65,8 @@ The server responds with the following HTTP Status codes.
 | HTTP Status Code  | Meaning |
 | ----------------- | ------- |
 | `201 Created`     | The package has been published. |
-| `400 Bad Request` | The package name and/or version are invalid or a package with the same name and version already exist. |
+| `400 Bad Request` | The package is invalid. |
+| `409 Conflict`    | A package file with the same combination of parameters exists already. |
 
 ## Configuring the package registry
 
index 24c7077a88dcdf0ead5a48f9da8cf0dc8fdd713c..505460b31904b581a34c4725381ce342cf55ae16 100644 (file)
@@ -63,6 +63,8 @@ For example:
 conan upload --remote=gitea ConanPackage/1.2@gitea/final
 ```
 
+You cannot publish a file with the same name twice to a package. You must delete the existing package or file first.
+
 The Gitea Conan package registry has full [revision](https://docs.conan.io/en/latest/versioning/revisions.html) support.
 
 ## Install a package
index 5b6f97679c1d135bb25b8adb567ae6009454692d..a256dca51cb38d90ac039ed7c3e86667dce98c0a 100644 (file)
@@ -63,8 +63,18 @@ curl --user your_username:your_password_or_token \
      https://gitea.example.com/api/packages/testuser/conda/package-1.0.conda
 ```
 
+If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
+
 You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
 
+The server responds with the following HTTP Status codes.
+
+| HTTP Status Code  | Meaning |
+| ----------------- | ------- |
+| `201 Created`     | The package has been published. |
+| `400 Bad Request` | The package is invalid. |
+| `409 Conflict`    | A package file with the same combination of parameters exists already. |
+
 ## Install a package
 
 To install a package from the package registry, execute one of the following commands:
index 68de425d2167ea03f1dd49cbd8e5ab17e7753be0..a6b0d31856de0da334666f8e1ac0a3ef061ff7c6 100644 (file)
@@ -68,8 +68,18 @@ curl --user your_username:your_password_or_token \
      https://gitea.example.com/api/packages/testuser/cran/bin?platform=windows&rversion=4.2
 ```
 
+If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
+
 You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
 
+The server responds with the following HTTP Status codes.
+
+| HTTP Status Code  | Meaning |
+| ----------------- | ------- |
+| `201 Created`     | The package has been published. |
+| `400 Bad Request` | The package is invalid. |
+| `409 Conflict`    | A package file with the same combination of parameters exists already. |
+
 ## Install a package
 
 To install a R package from the package registry, execute the following command:
index 6bd7475dd6411ec62c291347d9f161a0366131b3..9ae1dc15c04311c25feee2e3bca16e7f9e828009 100644 (file)
@@ -77,14 +77,15 @@ curl --user your_username:your_password_or_token \
 ```
 
 If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
-You cannot publish a file with the same name twice to a package. You must delete the existing package version first.
+
+You cannot publish a package if a package of the same name, version, distribution, component and architecture already exists. You must delete the existing package first.
 
 The server responds with the following HTTP Status codes.
 
 | HTTP Status Code  | Meaning |
 | ----------------- | ------- |
 | `201 Created`     | The package has been published. |
-| `400 Bad Request` | The package name, version, distribution, component or architecture are invalid. |
+| `400 Bad Request` | The package is invalid. |
 | `409 Conflict`    | A package file with the same combination of parameters exists already. |
 
 ## Delete a package
index 7c4069248ea6e29fe77a8a226ed4c2693f8a68e2..ed3c1a87e9ae102405d2224f5beeeaef96c114ee 100644 (file)
@@ -41,6 +41,8 @@ curl --user your_username:your_password_or_token \
 
 If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
 
+You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
+
 The server responds with the following HTTP Status codes.
 
 | HTTP Status Code  | Meaning |
index 1bc271ddaef3d096fe1f9facd7875a20a8c24a1d..606fa20b362a8f90fbae153ce5edd658d5e54161 100644 (file)
@@ -67,6 +67,14 @@ curl -X PUT --user {username}:{password} \
 
 You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
 
+The server responds with the following HTTP Status codes.
+
+| HTTP Status Code  | Meaning |
+| ----------------- | ------- |
+| `201 Created`     | The package has been published. |
+| `400 Bad Request` | The package is invalid. |
+| `409 Conflict`    | A package file with the same combination of parameters exists already. |
+
 ## Install a package
 
 To install a Swift package from the package registry, add it in the `Package.swift` file dependencies list:
index 93cf5e3e78a10f79e58c488e7b935a8d3dd0f716..baa9c2b83e48741e661c75c22c0f356cb7c2bab6 100644 (file)
@@ -44,8 +44,18 @@ curl --user your_username:your_password_or_token \
      https://gitea.example.com/api/packages/testuser/vagrant/test_system/1.0.0/hyperv.box
 ```
 
+If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
+
 You cannot publish a box if a box of the same name, version and provider already exists. You must delete the existing package first.
 
+The server responds with the following HTTP Status codes.
+
+| HTTP Status Code  | Meaning |
+| ----------------- | ------- |
+| `201 Created`     | The package has been published. |
+| `400 Bad Request` | The package is invalid. |
+| `409 Conflict`    | A package with the same combination of parameters exists already. |
+
 ## Install a package
 
 To install a box from the package registry, execute the following command:
index c261eee2d22a7e337206a1c635349c89f7a8ce0a..bb14c5163a436564af093fccf57348d97a74f7ab 100644 (file)
@@ -164,7 +164,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion, packages_model.ErrDuplicatePackageFile:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index a1f5f49bd8aaecb5b7dc6f080b6d19ac158f1f5c..f1e9ae12d816cd42233e4aaef21c8ccbd27f2419 100644 (file)
@@ -310,7 +310,7 @@ func UploadPackage(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 313631d7d77d1dff00fcd6e0fef017e9f1ebe227..0551093cd19f2326c65cdf69e4815588c3c3a29a 100644 (file)
@@ -247,7 +247,7 @@ func UploadPackage(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index f440f83b243f682a71ef9be75d15b42a15e642d8..4bf13222dc793965911dcb271720a13d3e831556 100644 (file)
@@ -415,7 +415,7 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageFile:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index dc7ebab09687b2c116724a8e4b3e2a7af1bd4dc9..379137e87eb9c269bdc850110e369bba3bb20374 100644 (file)
@@ -189,7 +189,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion, packages_model.ErrDuplicatePackageFile:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 52e31e80338d60a1d60cd9182fd5bf3f9ac5acf8..0b93382b01177d0e7b72cfb9a6694f88314a7abc 100644 (file)
@@ -363,7 +363,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageFile:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index dd6b3f148b51b6f9785426d6077aa10349113d0e..170edfbe11cc1d1d87054486a79947810ee3a797 100644 (file)
@@ -214,7 +214,7 @@ func UploadPackage(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 8460f861cb7e5fcd507ef278d2642c24d6e6fd65..1f605c6c9f432fccae0dde9d9fad443a9f4eff95 100644 (file)
@@ -213,7 +213,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 8c7f9bbf38b569e90512db9028ec6dfceb850273..5718b1203b48b48bb846964f4c5383811d6db374 100644 (file)
@@ -177,7 +177,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageFile:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 061fb0871b18051c17fdbb3ab39147640e447618..01fd4dad669156e865c2c932d152a7c6d4891d5e 100644 (file)
@@ -258,7 +258,7 @@ func UploadPackageFile(ctx *context.Context) {
        if err != nil {
                switch err {
                case packages_model.ErrDuplicatePackageVersion:
-                       apiError(ctx, http.StatusBadRequest, err)
+                       apiError(ctx, http.StatusConflict, err)
                case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
                        apiError(ctx, http.StatusForbidden, err)
                default:
index 4a1fe2607e4cd6c95f449af97d9dedc3d5a6bc5d..7f55a84f09198a1e5d8684e1f5d40f248e95092a 100644 (file)
@@ -322,7 +322,7 @@ nwIDAQAB
                assert.Equal(t, fmt.Sprintf("%s.tar.gz", packageVersion), pfs[0].Name)
                assert.True(t, pfs[0].IsLead)
 
-               uploadPackage(t, packageVersion, http.StatusBadRequest)
+               uploadPackage(t, packageVersion, http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {
index ac125905619b76cd7f4436a71999c9a3341a3b36..896462d9a9fd098dba11f58ec9b603cd576098fc 100644 (file)
@@ -112,7 +112,7 @@ func TestPackageComposer(t *testing.T) {
 
                        req = NewRequestWithBody(t, "PUT", uploadURL, bytes.NewReader(content))
                        req = AddBasicAuthHeader(req, user.Name)
-                       MakeRequest(t, req, http.StatusBadRequest)
+                       MakeRequest(t, req, http.StatusConflict)
                })
        })
 
index 2d92b93159943894d603a82e19fd155835a3cc15..f796d617db9c418f144c290ec9224e402813fc45 100644 (file)
@@ -147,7 +147,7 @@ func TestPackageDebian(t *testing.T) {
 
                                                        req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(packageName, packageVersion, architecture))
                                                        AddBasicAuthHeader(req, user.Name)
-                                                       MakeRequest(t, req, http.StatusBadRequest)
+                                                       MakeRequest(t, req, http.StatusConflict)
                                                })
 
                                                t.Run("Download", func(t *testing.T) {
index 81112f305a62eda7fb81987a554a1385b551bb64..c78024563f4df05e16cbccf129d1bdb1d9174b13 100644 (file)
@@ -50,7 +50,7 @@ func TestPackageMaven(t *testing.T) {
                defer tests.PrintCurrentTest(t)()
 
                putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusCreated)
-               putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusBadRequest)
+               putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusConflict)
                putFile(t, "/maven-metadata.xml", "test", http.StatusOK)
 
                pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
@@ -78,7 +78,7 @@ func TestPackageMaven(t *testing.T) {
        t.Run("UploadExists", func(t *testing.T) {
                defer tests.PrintCurrentTest(t)()
 
-               putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusBadRequest)
+               putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {
index 433b183c295c9ac4192a4894756d95194219468e..bd3bfeeff067c711b1d083a0d39d50b89a7557b2 100644 (file)
@@ -121,7 +121,7 @@ func TestPackageNpm(t *testing.T) {
 
                req := NewRequestWithBody(t, "PUT", root, strings.NewReader(buildUpload(packageVersion)))
                req = addTokenAuthHeader(req, token)
-               MakeRequest(t, req, http.StatusBadRequest)
+               MakeRequest(t, req, http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {
index cae280c0ec6f3f8b3186a0604eed17b50b031bba..6e9d8742f472daf01112810a3c2bd0f2beb7ddfd 100644 (file)
@@ -121,7 +121,7 @@ description: ` + packageDescription
                assert.NoError(t, err)
                assert.Equal(t, int64(len(content)), pb.Size)
 
-               _ = uploadFile(t, result.URL, content, http.StatusBadRequest)
+               _ = uploadFile(t, result.URL, content, http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {
index c7c466e7308344832137ac58306629d9f376f926..76013b79c840f4226a6fe3975d76866cafa594d3 100644 (file)
@@ -129,8 +129,8 @@ func TestPackagePyPI(t *testing.T) {
        t.Run("UploadExists", func(t *testing.T) {
                defer tests.PrintCurrentTest(t)()
 
-               uploadFile(t, "test.whl", content, http.StatusBadRequest)
-               uploadFile(t, "test.tar.gz", content, http.StatusBadRequest)
+               uploadFile(t, "test.whl", content, http.StatusConflict)
+               uploadFile(t, "test.tar.gz", content, http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {
index 2099357cbb7776540c04f161a0b47994bfa5d706..a3df143209a5cdf03e05caeaf68e4771f2e2f33d 100644 (file)
@@ -150,7 +150,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`)
        t.Run("UploadExists", func(t *testing.T) {
                defer tests.PrintCurrentTest(t)()
 
-               uploadFile(t, http.StatusBadRequest)
+               uploadFile(t, http.StatusConflict)
        })
 
        t.Run("Download", func(t *testing.T) {