2024-07-02 20:38:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Middleware order" do
|
2024-06-20 04:33:01 -04:00
|
|
|
let(:expected_middlewares) do
|
|
|
|
[
|
|
|
|
BlockRequestsMiddleware,
|
|
|
|
TestMultisiteMiddleware,
|
|
|
|
ActionDispatch::RemoteIp,
|
|
|
|
Middleware::RequestTracker,
|
|
|
|
MessageBus::Rack::Middleware,
|
|
|
|
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-02 20:38:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures that ActionDispatch::RemoteIp comes before Middleware::RequestTracker" do
|
2024-06-20 04:33:01 -04:00
|
|
|
expect(remote_ip_index).to be < request_tracker_index
|
2024-07-02 20:38:49 -04:00
|
|
|
end
|
|
|
|
end
|