2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-27 14:55:36 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
describe 'multisite', type: [:multisite, :request] do
|
2020-04-27 14:55:36 -04:00
|
|
|
it "should always allow /srv/status through" do
|
2021-11-11 11:44:58 -05:00
|
|
|
get "http://unknown.com/srv/status"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(request.env["HTTP_HOST"]).to eq("test.localhost") # Rewritten by EnforceHostname middleware
|
|
|
|
end
|
2020-04-27 14:55:36 -04:00
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
it "should 404 for unknown domains" do
|
|
|
|
get "http://unknown.com/about.json"
|
|
|
|
expect(response.status).to eq(404)
|
2020-04-27 14:55:36 -04:00
|
|
|
end
|
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
it "should hit correct site otherwise" do
|
|
|
|
site_1_url = Fabricate(:topic, title: "Site 1 Topic Title", user: Discourse.system_user).relative_url
|
2020-04-27 14:55:36 -04:00
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
test_multisite_connection('second') do
|
|
|
|
site_2_url = Fabricate(:topic, title: "Site 2 Topic Title", user: Discourse.system_user).relative_url
|
2020-04-27 14:55:36 -04:00
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
get "http://test.localhost/#{site_1_url}.json"
|
|
|
|
expect(request.env["RAILS_MULTISITE_HOST"]).to eq("test.localhost")
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["title"]).to eq("Site 1 Topic Title")
|
2020-04-27 14:55:36 -04:00
|
|
|
|
2021-11-11 11:44:58 -05:00
|
|
|
get "http://test2.localhost/#{site_2_url}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(request.env["RAILS_MULTISITE_HOST"]).to eq("test2.localhost")
|
|
|
|
expect(response.parsed_body["title"]).to eq("Site 2 Topic Title")
|
|
|
|
end
|
2020-04-27 14:55:36 -04:00
|
|
|
end
|
|
|
|
end
|