Non-archive artifacts give a 404 when downloaded

Summary

#23847 (closed) adds a variety of artifacts to the download dropdown on the pipelines page. Previously, that dropdown only included archive artifacts.

However, the download routes and controller assume that only one artifact per job will be downloadable, and when not given a file type it assumes that the artifact is of type archive. Currently, the frontend does not provide a file type, so whenever there is a request to download an artifact of a different type, the controller cannot find it and returns a 404.

Steps to reproduce

  1. Find a project that creates non-archive downloadable artifacts in its pipelines. Any security scan will work for this.
  2. Run a pipeline and make sure it is successful.
  3. In the pipelines page, click on "download" icon for the new pipeline.
  4. See that the non-archive artifact is listed in the download options.
  5. Open the browser's dev tools to the Network tab.
  6. Click on the non-archive artifact in the download dropdown.
  7. See that nothing is downloaded, and in the Network tab see that the request returns a 404.

Example Project

https://gitlab.com/sethgitlab/dvwa-dast/pipelines

What is the current bug behavior?

Attempting to download a non-archive artifact gives a 404.

What is the expected correct behavior?

Attempting to download a non-archive artifact downloads the artifact.

Relevant logs and/or screenshots

Screen_Recording_2020-05-20_at_1.48.17_PM

Output of checks

This bug happens on GitLab.com

Possible fixes

The current download route takes a project and a build, and uses the build to find the artifact. To do so, it makes the assumption that only one artifact per job will be downloadable. This is no longer an accurate assumption, which is holding up additional feature work and makes this bug difficult to fix quickly.

It would be better to have routes that use an artifact's database ID to find it. This will allow a job to support any number of downloadable artifacts and will make the finding the artifact less complicated.