summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-15 14:48:16 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-15 14:48:16 +0000
commit5cf10240f9d8736923c57ff35c5c4acab7de37dc (patch)
treead90d0332f35f19e00158e0ec2bb8a944e4f67fe
parent8ef91a0ac78a0c95b616b54c2042e64fd0711f23 (diff)
parentb0622d657893b156ac0c265f397efeb28d5b0b4c (diff)
downloadgitlab-ce-5cf10240f9d8736923c57ff35c5c4acab7de37dc.tar.gz
Merge branch 'dz-handle-unmatched-routes' into 'master'
Handle unmatched routing with not_found method ## What does this MR do? Handle all unmatched routes with 404 method ## Why was this MR needed? We need this to prevent routing error when user access URL like /123 when there is no resource located under such name. ## What are the relevant issue numbers? Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/23378 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6733. See merge request !6905
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--config/routes.rb2
-rw-r--r--spec/requests/git_http_spec.rb5
3 files changed, 9 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b3455e04c29..705824502eb 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -45,6 +45,10 @@ class ApplicationController < ActionController::Base
redirect_to request.referer.present? ? :back : default, options
end
+ def not_found
+ render_404
+ end
+
protected
# This filter handles both private tokens and personal access tokens
diff --git a/config/routes.rb b/config/routes.rb
index 83c3a42c19f..659ea51bc75 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -88,4 +88,6 @@ Rails.application.routes.draw do
get ':username.keys' => 'profiles/keys#get_keys', constraints: { username: /.*/ }
root to: "root#index"
+
+ get '*unmatched_route', to: 'application#not_found'
end
diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb
index 5a1ed7d4a25..27f0fd22ae6 100644
--- a/spec/requests/git_http_spec.rb
+++ b/spec/requests/git_http_spec.rb
@@ -412,9 +412,10 @@ describe 'Git HTTP requests', lib: true do
context "when the params are anything else" do
let(:params) { { service: 'git-implode-pack' } }
+ before { get path, params }
- it "fails to find a route" do
- expect { get(path, params) }.to raise_error(ActionController::RoutingError)
+ it "redirects to the sign-in page" do
+ expect(response).to redirect_to(new_user_session_path)
end
end
end