Skip to content

Commit 5b6258a

Browse files
lng2020KN4CK3R
andauthored
Fix the wrong HTTP response status code for duplicate packages (#27480)
fix #27470 (hope there is nothing missing 😢 ) --------- Co-authored-by: KN4CK3R <[email protected]>
1 parent 2c7b6c3 commit 5b6258a

27 files changed

+69
-23
lines changed

docs/content/usage/packages/alpine.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ curl --user your_username:your_password_or_token \
7777
```
7878

7979
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
80+
8081
You cannot publish a file with the same name twice to a package. You must delete the existing package file first.
8182

8283
The server responds with the following HTTP Status codes.

docs/content/usage/packages/composer.en-us.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ To work with the Composer package registry, you can use [Composer](https://getco
2525

2626
To publish a Composer package perform a HTTP PUT operation with the package content in the request body.
2727
The package content must be the zipped PHP project with the `composer.json` file.
28+
2829
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
2930

3031
```
@@ -64,7 +65,8 @@ The server responds with the following HTTP Status codes.
6465
| HTTP Status Code | Meaning |
6566
| ----------------- | ------- |
6667
| `201 Created` | The package has been published. |
67-
| `400 Bad Request` | The package name and/or version are invalid or a package with the same name and version already exist. |
68+
| `400 Bad Request` | The package is invalid. |
69+
| `409 Conflict` | A package file with the same combination of parameters exists already. |
6870

6971
## Configuring the package registry
7072

docs/content/usage/packages/conan.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ For example:
6363
conan upload --remote=gitea ConanPackage/1.2@gitea/final
6464
```
6565

66+
You cannot publish a file with the same name twice to a package. You must delete the existing package or file first.
67+
6668
The Gitea Conan package registry has full [revision](https://docs.conan.io/en/latest/versioning/revisions.html) support.
6769

6870
## Install a package

docs/content/usage/packages/conda.en-us.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ curl --user your_username:your_password_or_token \
6363
https://gitea.example.com/api/packages/testuser/conda/package-1.0.conda
6464
```
6565

66+
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
67+
6668
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
6769

70+
The server responds with the following HTTP Status codes.
71+
72+
| HTTP Status Code | Meaning |
73+
| ----------------- | ------- |
74+
| `201 Created` | The package has been published. |
75+
| `400 Bad Request` | The package is invalid. |
76+
| `409 Conflict` | A package file with the same combination of parameters exists already. |
77+
6878
## Install a package
6979

7080
To install a package from the package registry, execute one of the following commands:

docs/content/usage/packages/cran.en-us.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,18 @@ curl --user your_username:your_password_or_token \
6868
https://gitea.example.com/api/packages/testuser/cran/bin?platform=windows&rversion=4.2
6969
```
7070

71+
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
72+
7173
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
7274

75+
The server responds with the following HTTP Status codes.
76+
77+
| HTTP Status Code | Meaning |
78+
| ----------------- | ------- |
79+
| `201 Created` | The package has been published. |
80+
| `400 Bad Request` | The package is invalid. |
81+
| `409 Conflict` | A package file with the same combination of parameters exists already. |
82+
7383
## Install a package
7484

7585
To install a R package from the package registry, execute the following command:

docs/content/usage/packages/debian.en-us.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ curl --user your_username:your_password_or_token \
7777
```
7878

7979
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
80-
You cannot publish a file with the same name twice to a package. You must delete the existing package version first.
80+
81+
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.
8182

8283
The server responds with the following HTTP Status codes.
8384

8485
| HTTP Status Code | Meaning |
8586
| ----------------- | ------- |
8687
| `201 Created` | The package has been published. |
87-
| `400 Bad Request` | The package name, version, distribution, component or architecture are invalid. |
88+
| `400 Bad Request` | The package is invalid. |
8889
| `409 Conflict` | A package file with the same combination of parameters exists already. |
8990

9091
## Delete a package

docs/content/usage/packages/go.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ curl --user your_username:your_password_or_token \
4141

4242
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
4343

44+
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
45+
4446
The server responds with the following HTTP Status codes.
4547

4648
| HTTP Status Code | Meaning |

docs/content/usage/packages/swift.en-us.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ curl -X PUT --user {username}:{password} \
6767

6868
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
6969

70+
The server responds with the following HTTP Status codes.
71+
72+
| HTTP Status Code | Meaning |
73+
| ----------------- | ------- |
74+
| `201 Created` | The package has been published. |
75+
| `400 Bad Request` | The package is invalid. |
76+
| `409 Conflict` | A package file with the same combination of parameters exists already. |
77+
7078
## Install a package
7179

7280
To install a Swift package from the package registry, add it in the `Package.swift` file dependencies list:

docs/content/usage/packages/vagrant.en-us.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ curl --user your_username:your_password_or_token \
4444
https://gitea.example.com/api/packages/testuser/vagrant/test_system/1.0.0/hyperv.box
4545
```
4646

47+
If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
48+
4749
You cannot publish a box if a box of the same name, version and provider already exists. You must delete the existing package first.
4850

51+
The server responds with the following HTTP Status codes.
52+
53+
| HTTP Status Code | Meaning |
54+
| ----------------- | ------- |
55+
| `201 Created` | The package has been published. |
56+
| `400 Bad Request` | The package is invalid. |
57+
| `409 Conflict` | A package with the same combination of parameters exists already. |
58+
4959
## Install a package
5060

5161
To install a box from the package registry, execute the following command:

routers/api/packages/alpine/alpine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func UploadPackageFile(ctx *context.Context) {
164164
if err != nil {
165165
switch err {
166166
case packages_model.ErrDuplicatePackageVersion, packages_model.ErrDuplicatePackageFile:
167-
apiError(ctx, http.StatusBadRequest, err)
167+
apiError(ctx, http.StatusConflict, err)
168168
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
169169
apiError(ctx, http.StatusForbidden, err)
170170
default:

routers/api/packages/chef/chef.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func UploadPackage(ctx *context.Context) {
310310
if err != nil {
311311
switch err {
312312
case packages_model.ErrDuplicatePackageVersion:
313-
apiError(ctx, http.StatusBadRequest, err)
313+
apiError(ctx, http.StatusConflict, err)
314314
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
315315
apiError(ctx, http.StatusForbidden, err)
316316
default:

routers/api/packages/composer/composer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func UploadPackage(ctx *context.Context) {
247247
if err != nil {
248248
switch err {
249249
case packages_model.ErrDuplicatePackageVersion:
250-
apiError(ctx, http.StatusBadRequest, err)
250+
apiError(ctx, http.StatusConflict, err)
251251
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
252252
apiError(ctx, http.StatusForbidden, err)
253253
default:

routers/api/packages/conan/conan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
415415
if err != nil {
416416
switch err {
417417
case packages_model.ErrDuplicatePackageFile:
418-
apiError(ctx, http.StatusBadRequest, err)
418+
apiError(ctx, http.StatusConflict, err)
419419
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
420420
apiError(ctx, http.StatusForbidden, err)
421421
default:

routers/api/packages/debian/debian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func UploadPackageFile(ctx *context.Context) {
189189
if err != nil {
190190
switch err {
191191
case packages_model.ErrDuplicatePackageVersion, packages_model.ErrDuplicatePackageFile:
192-
apiError(ctx, http.StatusBadRequest, err)
192+
apiError(ctx, http.StatusConflict, err)
193193
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
194194
apiError(ctx, http.StatusForbidden, err)
195195
default:

routers/api/packages/maven/maven.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func UploadPackageFile(ctx *context.Context) {
363363
if err != nil {
364364
switch err {
365365
case packages_model.ErrDuplicatePackageFile:
366-
apiError(ctx, http.StatusBadRequest, err)
366+
apiError(ctx, http.StatusConflict, err)
367367
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
368368
apiError(ctx, http.StatusForbidden, err)
369369
default:

routers/api/packages/npm/npm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func UploadPackage(ctx *context.Context) {
214214
if err != nil {
215215
switch err {
216216
case packages_model.ErrDuplicatePackageVersion:
217-
apiError(ctx, http.StatusBadRequest, err)
217+
apiError(ctx, http.StatusConflict, err)
218218
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
219219
apiError(ctx, http.StatusForbidden, err)
220220
default:

routers/api/packages/pub/pub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func UploadPackageFile(ctx *context.Context) {
213213
if err != nil {
214214
switch err {
215215
case packages_model.ErrDuplicatePackageVersion:
216-
apiError(ctx, http.StatusBadRequest, err)
216+
apiError(ctx, http.StatusConflict, err)
217217
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
218218
apiError(ctx, http.StatusForbidden, err)
219219
default:

routers/api/packages/pypi/pypi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func UploadPackageFile(ctx *context.Context) {
177177
if err != nil {
178178
switch err {
179179
case packages_model.ErrDuplicatePackageFile:
180-
apiError(ctx, http.StatusBadRequest, err)
180+
apiError(ctx, http.StatusConflict, err)
181181
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
182182
apiError(ctx, http.StatusForbidden, err)
183183
default:

routers/api/packages/rubygems/rubygems.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func UploadPackageFile(ctx *context.Context) {
258258
if err != nil {
259259
switch err {
260260
case packages_model.ErrDuplicatePackageVersion:
261-
apiError(ctx, http.StatusBadRequest, err)
261+
apiError(ctx, http.StatusConflict, err)
262262
case packages_service.ErrQuotaTotalCount, packages_service.ErrQuotaTypeSize, packages_service.ErrQuotaTotalSize:
263263
apiError(ctx, http.StatusForbidden, err)
264264
default:

tests/integration/api_packages_chef_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ nwIDAQAB
322322
assert.Equal(t, fmt.Sprintf("%s.tar.gz", packageVersion), pfs[0].Name)
323323
assert.True(t, pfs[0].IsLead)
324324

325-
uploadPackage(t, packageVersion, http.StatusBadRequest)
325+
uploadPackage(t, packageVersion, http.StatusConflict)
326326
})
327327

328328
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_composer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestPackageComposer(t *testing.T) {
112112

113113
req = NewRequestWithBody(t, "PUT", uploadURL, bytes.NewReader(content))
114114
req = AddBasicAuthHeader(req, user.Name)
115-
MakeRequest(t, req, http.StatusBadRequest)
115+
MakeRequest(t, req, http.StatusConflict)
116116
})
117117
})
118118

tests/integration/api_packages_debian_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestPackageDebian(t *testing.T) {
147147

148148
req = NewRequestWithBody(t, "PUT", uploadURL, createArchive(packageName, packageVersion, architecture))
149149
AddBasicAuthHeader(req, user.Name)
150-
MakeRequest(t, req, http.StatusBadRequest)
150+
MakeRequest(t, req, http.StatusConflict)
151151
})
152152

153153
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_maven_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestPackageMaven(t *testing.T) {
5050
defer tests.PrintCurrentTest(t)()
5151

5252
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusCreated)
53-
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusBadRequest)
53+
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusConflict)
5454
putFile(t, "/maven-metadata.xml", "test", http.StatusOK)
5555

5656
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeMaven)
@@ -78,7 +78,7 @@ func TestPackageMaven(t *testing.T) {
7878
t.Run("UploadExists", func(t *testing.T) {
7979
defer tests.PrintCurrentTest(t)()
8080

81-
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusBadRequest)
81+
putFile(t, fmt.Sprintf("/%s/%s", packageVersion, filename), "test", http.StatusConflict)
8282
})
8383

8484
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_npm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestPackageNpm(t *testing.T) {
121121

122122
req := NewRequestWithBody(t, "PUT", root, strings.NewReader(buildUpload(packageVersion)))
123123
req = addTokenAuthHeader(req, token)
124-
MakeRequest(t, req, http.StatusBadRequest)
124+
MakeRequest(t, req, http.StatusConflict)
125125
})
126126

127127
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_pub_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ description: ` + packageDescription
121121
assert.NoError(t, err)
122122
assert.Equal(t, int64(len(content)), pb.Size)
123123

124-
_ = uploadFile(t, result.URL, content, http.StatusBadRequest)
124+
_ = uploadFile(t, result.URL, content, http.StatusConflict)
125125
})
126126

127127
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_pypi_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func TestPackagePyPI(t *testing.T) {
129129
t.Run("UploadExists", func(t *testing.T) {
130130
defer tests.PrintCurrentTest(t)()
131131

132-
uploadFile(t, "test.whl", content, http.StatusBadRequest)
133-
uploadFile(t, "test.tar.gz", content, http.StatusBadRequest)
132+
uploadFile(t, "test.whl", content, http.StatusConflict)
133+
uploadFile(t, "test.tar.gz", content, http.StatusConflict)
134134
})
135135

136136
t.Run("Download", func(t *testing.T) {

tests/integration/api_packages_rubygems_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`)
150150
t.Run("UploadExists", func(t *testing.T) {
151151
defer tests.PrintCurrentTest(t)()
152152

153-
uploadFile(t, http.StatusBadRequest)
153+
uploadFile(t, http.StatusConflict)
154154
})
155155

156156
t.Run("Download", func(t *testing.T) {

0 commit comments

Comments
 (0)