diff --git a/server/channels/api4/job.go b/server/channels/api4/job.go index 815e063f3b..03afdb2071 100644 --- a/server/channels/api4/job.go +++ b/server/channels/api4/job.go @@ -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 } diff --git a/server/channels/api4/job_test.go b/server/channels/api4/job_test.go index 8142ff48cb..394f326080 100644 --- a/server/channels/api4/job_test.go +++ b/server/channels/api4/job_test.go @@ -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) {