diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2016-10-11 18:13:42 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2016-10-11 18:13:42 +0000 |
commit | 3d253e5cb3b9ccfe88ef97607399ff6fa7b7a48d (patch) | |
tree | 480e91db3c3b8c5d6d12df223a30a5ba7f1552b3 | |
parent | d57d892e3fd4d73a477ba5c1b0049864f7c9e6b2 (diff) | |
parent | d0c240b64fbb5f723a630fe96af380a9c82fd1b1 (diff) | |
download | gitlab-ce-3d253e5cb3b9ccfe88ef97607399ff6fa7b7a48d.tar.gz |
Merge branch '22211-500-instead-of-404' into 'master'
Respond with 404 Not Found for non-existent tags
## What does this MR do?
Handles the case when a non-existent tag is being viewed, and responds with 404 Not Found instead of 500 Internal Server Error.
## Are there points in the code the reviewer needs to double check?
The small changes should be clear from a simple diff.
## Why was this MR needed?
To resolve the issue #22211.
## Screenshots (if relevant)
## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
- [x] Added for this feature/bug
- [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
## What are the relevant issue numbers?
Closes #22211
See merge request !6699
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/projects/tags_controller.rb | 2 | ||||
-rw-r--r-- | spec/controllers/projects/tags_controller_spec.rb | 14 |
3 files changed, 17 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG index 0a81b68018a..2c88d2b2ac9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.13.0 (unreleased) + - Respond with 404 Not Found for non-existent tags (Linus Thiel) - Truncate long labels with ellipsis in labels page - Update runner version only when updating contacted_at - Add link from system note to compare with previous version diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index 6ea8ee62bc5..8fea20cefef 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -20,6 +20,8 @@ class Projects::TagsController < Projects::ApplicationController def show @tag = @repository.find_tag(params[:id]) + return render_404 unless @tag + @release = @project.releases.find_or_initialize_by(tag: @tag.name) @commit = @repository.commit(@tag.target) end diff --git a/spec/controllers/projects/tags_controller_spec.rb b/spec/controllers/projects/tags_controller_spec.rb index a6995145cc1..5e661c2c41d 100644 --- a/spec/controllers/projects/tags_controller_spec.rb +++ b/spec/controllers/projects/tags_controller_spec.rb @@ -17,4 +17,18 @@ describe Projects::TagsController do expect(assigns(:releases)).not_to include(invalid_release) end end + + describe 'GET show' do + before { get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, id: id } + + context "valid tag" do + let(:id) { 'v1.0.0' } + it { is_expected.to respond_with(:success) } + end + + context "invalid tag" do + let(:id) { 'latest' } + it { is_expected.to respond_with(:not_found) } + end + end end |