FIX: Ensure MessageIdService can handle hostname changes and multisite (#15231)

This commit is contained in:
David Taylor 2021-12-08 11:17:20 +00:00 committed by GitHub
parent 74387e83b6
commit f799b8bfb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -80,11 +80,11 @@ module Email
end
def message_id_post_id_regexp
@message_id_post_id_regexp ||= Regexp.new "topic/\\d+/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}"
Regexp.new "topic/\\d+/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}"
end
def message_id_topic_id_regexp
@message_id_topic_id_regexp ||= Regexp.new "topic/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}"
Regexp.new "topic/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}"
end
def message_id_rfc_format(message_id)
@ -100,7 +100,7 @@ module Email
end
def host
@host ||= Email::Sender.host_for(Discourse.base_url)
Email::Sender.host_for(Discourse.base_url)
end
end
end

View File

@ -120,4 +120,12 @@ describe Email::MessageIdService do
expect(Email::MessageIdService.message_id_clean(message_id)).to eq(message_id)
end
end
describe "#host" do
it "handles hostname changes at runtime" do
expect(Email::MessageIdService.host).to eq("test.localhost")
SiteSetting.force_hostname = "other.domain.example.com"
expect(Email::MessageIdService.host).to eq("other.domain.example.com")
end
end
end