Commit 5cf10240 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents 8ef91a0a b0622d65
......@@ -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
......
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment