0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/spec/integrity/middleware_order_spec.rb
2026-08-03 16:36:14 +02:00

59 lines
2 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Middleware order" do
let(:expected_middlewares) do
[
BlockRequestsMiddleware,
TestMultisiteMiddleware,
Middleware::ProcessingRequest,
Middleware::OverloadProtections,
ActionDispatch::RemoteIp,
Middleware::RequestTracker,
MessageBus::Rack::Middleware,
Rack::Sendfile,
ActionDispatch::Static,
Propshaft::Server,
ActionDispatch::Executor,
Rack::MethodOverride,
Middleware::EnforceHostname,
ActionDispatch::RequestId,
SilenceLogger,
Middleware::DefaultHeaders,
ActionDispatch::ShowExceptions,
ActionDispatch::DebugExceptions,
ActionDispatch::Callbacks,
ActionDispatch::Cookies,
ActionDispatch::Session::DiscourseCookieStore,
Discourse::Cors,
ActionDispatch::Flash,
RspecErrorTracker,
Middleware::TrackViewSessionIdInjector,
Middleware::CspScriptNonceInjector,
Middleware::AnonymousCache,
ContentSecurityPolicy::Middleware,
ActionDispatch::PermissionsPolicy::Middleware,
Rack::Head,
Rack::ConditionalGet,
Rack::TempfileReaper,
Middleware::CrawlerHooks,
Middleware::OmniauthBypassMiddleware,
]
end
let(:actual_middlewares) { Rails.configuration.middleware.middlewares }
let(:remote_ip_index) { actual_middlewares.index(ActionDispatch::RemoteIp) }
let(:request_tracker_index) { actual_middlewares.index(Middleware::RequestTracker) }
it "has the correct order of middlewares" do
expect(actual_middlewares).to eq(expected_middlewares)
end
it "ensures that ActionDispatch::RemoteIp comes before Middleware::RequestTracker" do
expect(remote_ip_index).to be < request_tracker_index
end
it "ensures that Middleware::DefaultHeaders comes before ActionDispatch::ShowExceptions" do
default_headers_index = actual_middlewares.index(Middleware::DefaultHeaders)
show_exceptions_index = actual_middlewares.index(ActionDispatch::ShowExceptions)
expect(default_headers_index).to be < show_exceptions_index
end
end