mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: don't block api requests when whitelisted_crawler_user_agents is set
This commit is contained in:
@ -26,6 +26,8 @@ module Middleware
|
|||||||
!@request.xhr? &&
|
!@request.xhr? &&
|
||||||
!@request.path.ends_with?('robots.txt') &&
|
!@request.path.ends_with?('robots.txt') &&
|
||||||
!@request.path.ends_with?('srv/status') &&
|
!@request.path.ends_with?('srv/status') &&
|
||||||
|
@request[Auth::DefaultCurrentUserProvider::API_KEY].nil? &&
|
||||||
|
@env[Auth::DefaultCurrentUserProvider::USER_API_KEY].nil? &&
|
||||||
CrawlerDetection.is_blocked_crawler?(@request.env['HTTP_USER_AGENT'])
|
CrawlerDetection.is_blocked_crawler?(@request.env['HTTP_USER_AGENT'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -189,6 +189,16 @@ describe Middleware::AnonymousCache::Helper do
|
|||||||
expect(@status).to eq(200)
|
expect(@status).to eq(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't block api requests" do
|
||||||
|
SiteSetting.whitelisted_crawler_user_agents = 'Googlebot'
|
||||||
|
api_key = Fabricate(:api_key)
|
||||||
|
|
||||||
|
get "/latest?api_key=#{api_key.key}&api_username=system", headers: {
|
||||||
|
"QUERY_STRING" => "api_key=#{api_key.key}&api_username=system"
|
||||||
|
}
|
||||||
|
expect(@status).to eq(200)
|
||||||
|
end
|
||||||
|
|
||||||
it "applies blacklisted_crawler_user_agents correctly" do
|
it "applies blacklisted_crawler_user_agents correctly" do
|
||||||
SiteSetting.blacklisted_crawler_user_agents = 'Googlebot'
|
SiteSetting.blacklisted_crawler_user_agents = 'Googlebot'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user