Fix ActivityPub handling of replies with WEB_DOMAIN (#4895) (#4904)

* Fix ActivityPub handling of replies when LOCAL_DOMAIN ≠ WEB_DOMAIN (#4895)

For all intents and purposes, `local_url?` is used to check if an URL refers
to the Web UI or the various API endpoints of the local instances. Those things
reside on `WEB_DOMAIN` and not `LOCAL_DOMAIN`.

* Change local_url? spec, as all URLs handled by Mastodon are based on WEB_DOMAIN
This commit is contained in:
ThibG 2017-09-13 14:22:16 +02:00 committed by Eugen Rochko
parent da77f65c46
commit 550ff677da
2 changed files with 6 additions and 6 deletions

View File

@ -87,7 +87,7 @@ class TagManager
def local_url?(url) def local_url?(url)
uri = Addressable::URI.parse(url).normalize uri = Addressable::URI.parse(url).normalize
domain = uri.host + (uri.port ? ":#{uri.port}" : '') domain = uri.host + (uri.port ? ":#{uri.port}" : '')
TagManager.instance.local_domain?(domain) TagManager.instance.web_domain?(domain)
end end
def uri_for(target) def uri_for(target)

View File

@ -63,23 +63,23 @@ RSpec.describe TagManager do
describe '#local_url?' do describe '#local_url?' do
around do |example| around do |example|
original_local_domain = Rails.configuration.x.local_domain original_web_domain = Rails.configuration.x.web_domain
example.run example.run
Rails.configuration.x.local_domain = original_local_domain Rails.configuration.x.web_domain = original_web_domain
end end
it 'returns true if the normalized string with port is local URL' do it 'returns true if the normalized string with port is local URL' do
Rails.configuration.x.local_domain = 'domain:42' Rails.configuration.x.web_domain = 'domain:42'
expect(TagManager.instance.local_url?('https://DoMaIn:42/')).to eq true expect(TagManager.instance.local_url?('https://DoMaIn:42/')).to eq true
end end
it 'returns true if the normalized string without port is local URL' do it 'returns true if the normalized string without port is local URL' do
Rails.configuration.x.local_domain = 'domain' Rails.configuration.x.web_domain = 'domain'
expect(TagManager.instance.local_url?('https://DoMaIn/')).to eq true expect(TagManager.instance.local_url?('https://DoMaIn/')).to eq true
end end
it 'returns false for string with irrelevant characters' do it 'returns false for string with irrelevant characters' do
Rails.configuration.x.local_domain = 'domain' Rails.configuration.x.web_domain = 'domain'
expect(TagManager.instance.local_url?('https://domainn/')).to eq false expect(TagManager.instance.local_url?('https://domainn/')).to eq false
end end
end end