Fix incorrect error handling in api4.downloadJob (#30410)

Этот коммит содержится в:
Claudio Costa
2025-03-06 15:04:39 +01:00
коммит произвёл GitHub
родитель dfca6c211d
Коммит e549aaffb0
2 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@@ -122,7 +122,7 @@ func downloadJob(c *Context, w http.ResponseWriter, r *http.Request) {
if !filepath.IsLocal(cleanedExportDir) {
c.Err = model.NewAppError("unableToDownloadJob", "api.job.unable_to_download_job", nil,
"job.Data did not include export_dir, export_dir was malformed, or jobId.zip wasn't found",
http.StatusNotFound).Wrap(err)
http.StatusNotFound)
return
}

Просмотреть файл

@@ -345,6 +345,30 @@ func TestDownloadJob(t *testing.T) {
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
require.Error(t, err)
CheckBadRequestStatus(t, resp)
// Test the case where export_dir is not valid
jobName = model.NewId()
job = &model.Job{
Id: jobName,
Type: model.JobTypeMessageExport,
Data: map[string]string{
"export_type": "csv",
"is_downloadable": "true",
"export_dir": "/bad/absolute/path",
},
Status: model.JobStatusSuccess,
}
_, err = th.App.Srv().Store().Job().Save(job)
require.NoError(t, err)
defer func() {
_, delErr := th.App.Srv().Store().Job().Delete(job.Id)
require.NoError(t, delErr, "Failed to delete job %s", job.Id)
}()
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
require.Error(t, err)
require.EqualError(t, err, "Unable to download this job")
CheckNotFoundStatus(t, resp)
}
func TestCancelJob(t *testing.T) {