FIX: do not treat ignore_redirects domains as blacklisted

This fix prevents domains present in `ignore_redirects` to be treated as
blacklisted domains and makes sure that onboxing happens for those domains.
Issue reported here: https://meta.discourse.org/t/steam-store-oneboxing-no-longer-works/97266
This commit is contained in:
Arpit Jalan 2018-09-17 23:30:16 +05:30
parent ce6a0a5e9e
commit fadcd36f92
2 changed files with 14 additions and 4 deletions

View File

@ -248,13 +248,15 @@ module Oneboxer
end
end
def self.blacklisted_domains
SiteSetting.onebox_domains_blacklist.split("|")
end
def self.external_onebox(url)
Rails.cache.fetch(onebox_cache_key(url), expires_in: 1.day) do
ignored = SiteSetting.onebox_domains_blacklist.split("|")
fd = FinalDestination.new(url, ignore_redirects: ignore_redirects, ignore_hostnames: ignored, force_get_hosts: force_get_hosts)
fd = FinalDestination.new(url, ignore_redirects: ignore_redirects, ignore_hostnames: blacklisted_domains, force_get_hosts: force_get_hosts)
uri = fd.resolve
return blank_onebox if uri.blank? || ignored.map { |hostname| uri.hostname.match?(hostname) }.any?
return blank_onebox if uri.blank? || blacklisted_domains.map { |hostname| uri.hostname.match?(hostname) }.any?
options = {
cache: {},

View File

@ -116,4 +116,12 @@ describe Oneboxer do
expect(Oneboxer.external_onebox('https://discourse.org/')[:onebox]).to be_empty
end
it "does not consider ignore_redirects domains as blacklisted" do
url = 'https://store.steampowered.com/app/271590/Grand_Theft_Auto_V/'
stub_request(:head, url).to_return(status: 200, body: "", headers: {})
stub_request(:get, url).to_return(status: 200, body: "", headers: {})
expect(Oneboxer.external_onebox(url)[:onebox]).to be_present
end
end