Commit 3075564a authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '258993-render-404-to-bots' into 'master'

Render 404 to search engine crawlers instead of redirecting to login

See merge request gitlab-org/gitlab!45552
parents 0a13f744 ebad3620
......@@ -121,7 +121,7 @@ class ApplicationController < ActionController::Base
end
def route_not_found
if current_user
if current_user || browser.bot.search_engine?
not_found
else
store_location_for(:user, request.fullpath) unless request.xhr?
......
---
title: Render 404 to search engine crawlers instead of redirecting to login
merge_request: 45552
author:
type: changed
......@@ -171,6 +171,8 @@ RSpec.describe ApplicationController do
describe '#route_not_found' do
controller(described_class) do
skip_before_action :authenticate_user!, only: :index
def index
route_not_found
end
......@@ -184,6 +186,14 @@ RSpec.describe ApplicationController do
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders 404 if client is a search engine crawler' do
request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
get :index
expect(response).to have_gitlab_http_status(:not_found)
end
it 'redirects to login page if not authenticated' do
get :index
......
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