2024-07-03 08:38:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Middleware order" do
|
2024-06-20 16:33:01 +08:00
|
|
|
let(:expected_middlewares) do
|
|
|
|
[
|
|
|
|
BlockRequestsMiddleware,
|
|
|
|
TestMultisiteMiddleware,
|
|
|
|
ActionDispatch::RemoteIp,
|
|
|
|
Middleware::RequestTracker,
|
|
|
|
MessageBus::Rack::Middleware,
|
2024-08-06 07:12:42 +08:00
|
|
|
Middleware::ProcessingRequest,
|
2024-06-20 16:33:01 +08:00
|
|
|
Rack::Sendfile,
|
|
|
|
ActionDispatch::Static,
|
|
|
|
ActionDispatch::Executor,
|
|
|
|
Rack::MethodOverride,
|
|
|
|
Middleware::EnforceHostname,
|
|
|
|
ActionDispatch::RequestId,
|
|
|
|
SilenceLogger,
|
|
|
|
ActionDispatch::ShowExceptions,
|
|
|
|
ActionDispatch::DebugExceptions,
|
|
|
|
ActionDispatch::Callbacks,
|
|
|
|
ActionDispatch::Cookies,
|
|
|
|
ActionDispatch::Session::DiscourseCookieStore,
|
|
|
|
Discourse::Cors,
|
|
|
|
ActionDispatch::Flash,
|
|
|
|
RspecErrorTracker,
|
|
|
|
Middleware::CspScriptNonceInjector,
|
|
|
|
Middleware::AnonymousCache,
|
|
|
|
ContentSecurityPolicy::Middleware,
|
|
|
|
ActionDispatch::PermissionsPolicy::Middleware,
|
|
|
|
Rack::Head,
|
|
|
|
Rack::ConditionalGet,
|
|
|
|
Rack::TempfileReaper,
|
|
|
|
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)
|
2024-07-03 08:38:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures that ActionDispatch::RemoteIp comes before Middleware::RequestTracker" do
|
2024-06-20 16:33:01 +08:00
|
|
|
expect(remote_ip_index).to be < request_tracker_index
|
2024-07-03 08:38:49 +08:00
|
|
|
end
|
|
|
|
end
|