mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-04 00:04:43 +01:00
fix(repo): return code 400 instead of 500 for invalid archive type (#7029)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
The error handled might be non-nil only when format is bad, which is 400 (Bad Request) Fixes #7026 Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7029 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com> Co-committed-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
This commit is contained in:
parent
17db5f3793
commit
6fb069cc50
2 changed files with 6 additions and 2 deletions
|
@ -474,7 +474,7 @@ func Download(ctx *context.Context) {
|
|||
uri := ctx.Params("*")
|
||||
ext, tp, err := archiver_service.ParseFileName(uri)
|
||||
if err != nil {
|
||||
ctx.ServerError("ParseFileName", err)
|
||||
ctx.NotFound("ParseFileName", err)
|
||||
return
|
||||
}
|
||||
aReq, err := archiver_service.NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, strings.TrimSuffix(uri, ext), tp)
|
||||
|
@ -554,7 +554,7 @@ func InitiateDownload(ctx *context.Context) {
|
|||
uri := ctx.Params("*")
|
||||
ext, tp, err := archiver_service.ParseFileName(uri)
|
||||
if err != nil {
|
||||
ctx.ServerError("ParseFileName", err)
|
||||
ctx.NotFound("ParseFileName", err)
|
||||
return
|
||||
}
|
||||
aReq, err := archiver_service.NewRequest(ctx, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, strings.TrimSuffix(uri, ext), tp)
|
||||
|
|
|
@ -39,6 +39,10 @@ func TestRepoDownloadArchive(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Empty(t, resp.Header().Get("Content-Encoding"))
|
||||
assert.Len(t, bs, 320)
|
||||
|
||||
// Verify that unrecognized archive type returns 404
|
||||
req = NewRequest(t, "GET", "/user2/repo1/archive/master.invalid")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func TestRepoDownloadArchiveSubdir(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue