Fix incorrect error handling in api4.downloadJob (#30410)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dfca6c211d
Коммит
e549aaffb0
@@ -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) {
|
||||
|
||||
Ссылка в новой задаче
Block a user