FEATURE: update rails multisite
always allow /srv/status through even if host does not match
This commit is contained in:
parent
0efed546a1
commit
86e6732f78
2
Gemfile
2
Gemfile
|
@ -46,7 +46,7 @@ gem 'barber'
|
||||||
|
|
||||||
gem 'message_bus'
|
gem 'message_bus'
|
||||||
|
|
||||||
gem 'rails_multisite', '~> 1.1.0.rc4'
|
gem 'rails_multisite'
|
||||||
|
|
||||||
gem 'fast_xs'
|
gem 'fast_xs'
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ GEM
|
||||||
nokogiri (>= 1.6)
|
nokogiri (>= 1.6)
|
||||||
rails-html-sanitizer (1.0.3)
|
rails-html-sanitizer (1.0.3)
|
||||||
loofah (~> 2.0)
|
loofah (~> 2.0)
|
||||||
rails_multisite (1.1.0.rc4)
|
rails_multisite (1.1.1)
|
||||||
activerecord (> 4.2, < 6)
|
activerecord (> 4.2, < 6)
|
||||||
railties (> 4.2, < 6)
|
railties (> 4.2, < 6)
|
||||||
railties (5.1.4)
|
railties (5.1.4)
|
||||||
|
@ -473,7 +473,7 @@ DEPENDENCIES
|
||||||
r2 (~> 0.2.5)
|
r2 (~> 0.2.5)
|
||||||
rack-mini-profiler
|
rack-mini-profiler
|
||||||
rack-protection
|
rack-protection
|
||||||
rails_multisite (~> 1.1.0.rc4)
|
rails_multisite
|
||||||
railties (~> 5.1)
|
railties (~> 5.1)
|
||||||
rake
|
rake
|
||||||
rb-fsevent
|
rb-fsevent
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class RailsMultisite::DiscoursePatches
|
||||||
|
def self.config
|
||||||
|
{
|
||||||
|
db_lookup: lambda do |env|
|
||||||
|
env["PATH_INFO"] == "/srv/status" ? "default" : nil
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Rails.configuration.multisite
|
||||||
|
Rails.configuration.middleware.swap(
|
||||||
|
RailsMultisite::ConnectionManagement,
|
||||||
|
RailsMultisite::ConnectionManagement,
|
||||||
|
RailsMultisite::DiscoursePatches.config
|
||||||
|
)
|
||||||
|
end
|
|
@ -0,0 +1,67 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe 'multisite' do
|
||||||
|
|
||||||
|
class DBNameMiddleware
|
||||||
|
def initialize(app, config = {})
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
# note current_db is already being ruined on boot cause its not multisite
|
||||||
|
[200, {}, [RailsMultisite::ConnectionManagement.current_hostname]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let :session do
|
||||||
|
RailsMultisite::ConnectionManagement.config_filename = "spec/fixtures/multisite/two_dbs.yml"
|
||||||
|
RailsMultisite::ConnectionManagement.load_settings!
|
||||||
|
|
||||||
|
stack = ActionDispatch::MiddlewareStack.new
|
||||||
|
stack.use RailsMultisite::ConnectionManagement, RailsMultisite::DiscoursePatches.config
|
||||||
|
stack.use DBNameMiddleware
|
||||||
|
|
||||||
|
routes = ActionDispatch::Routing::RouteSet.new
|
||||||
|
stack.build(routes)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should always allow /srv/status through" do
|
||||||
|
headers = {
|
||||||
|
"HTTP_HOST" => "unknown.com",
|
||||||
|
"REQUEST_METHOD" => "GET",
|
||||||
|
"PATH_INFO" => "/srv/status",
|
||||||
|
"rack.input" => StringIO.new
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _, body = session.call(headers)
|
||||||
|
expect(code).to eq(200)
|
||||||
|
expect(body.join).to eq("test.localhost")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should 404 on unknown routes" do
|
||||||
|
headers = {
|
||||||
|
"HTTP_HOST" => "unknown.com",
|
||||||
|
"REQUEST_METHOD" => "GET",
|
||||||
|
"PATH_INFO" => "/topics",
|
||||||
|
"rack.input" => StringIO.new
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _ = session.call(headers)
|
||||||
|
expect(code).to eq(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should hit correct site elsewise" do
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"HTTP_HOST" => "test2.localhost",
|
||||||
|
"REQUEST_METHOD" => "GET",
|
||||||
|
"PATH_INFO" => "/topics",
|
||||||
|
"rack.input" => StringIO.new
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _, body = session.call(headers)
|
||||||
|
expect(code).to eq(200)
|
||||||
|
expect(body.join).to eq("test2.localhost")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue