mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00
FIX: Update global rate limiter keys/messages to clarify user vs ip (#25264)
This commit is contained in:
@ -307,9 +307,9 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, _ = middleware.call(env1)
|
||||
status, _ = middleware.call(env1)
|
||||
|
||||
expect(
|
||||
@fake_logger.warnings.count { |w| w.include?("Global IP rate limit exceeded") },
|
||||
).to eq(warn_count)
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global rate limit exceeded") }).to eq(
|
||||
warn_count,
|
||||
)
|
||||
expect(status).to eq(429)
|
||||
warn_count += 1
|
||||
end
|
||||
@ -398,9 +398,9 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, _ = middleware.call(env1)
|
||||
status, _ = middleware.call(env1)
|
||||
|
||||
expect(
|
||||
@fake_logger.warnings.count { |w| w.include?("Global IP rate limit exceeded") },
|
||||
).to eq(0)
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global rate limit exceeded") }).to eq(
|
||||
0,
|
||||
)
|
||||
expect(status).to eq(200)
|
||||
end
|
||||
end
|
||||
@ -412,9 +412,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, _ = middleware.call(env)
|
||||
status, headers = middleware.call(env)
|
||||
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global IP rate limit exceeded") }).to eq(
|
||||
1,
|
||||
)
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global rate limit exceeded") }).to eq(1)
|
||||
expect(status).to eq(429)
|
||||
expect(headers["Retry-After"]).to eq("10")
|
||||
end
|
||||
@ -426,9 +424,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, _ = middleware.call(env)
|
||||
status, _ = middleware.call(env)
|
||||
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global IP rate limit exceeded") }).to eq(
|
||||
1,
|
||||
)
|
||||
expect(@fake_logger.warnings.count { |w| w.include?("Global rate limit exceeded") }).to eq(1)
|
||||
expect(status).to eq(200)
|
||||
end
|
||||
|
||||
@ -495,6 +491,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
expect(status).to eq(429)
|
||||
expect(called).to eq(1)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("ip_10_secs_limit")
|
||||
expect(response.first).to include("too many requests from this IP address")
|
||||
expect(response.first).to include("Error code: ip_10_secs_limit.")
|
||||
end
|
||||
|
||||
@ -518,6 +515,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
expect(status).to eq(429)
|
||||
expect(called).to eq(1)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("ip_60_secs_limit")
|
||||
expect(response.first).to include("too many requests from this IP address")
|
||||
expect(response.first).to include("Error code: ip_60_secs_limit.")
|
||||
end
|
||||
|
||||
@ -542,6 +540,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
expect(status).to eq(429)
|
||||
expect(called).to eq(1)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("ip_assets_10_secs_limit")
|
||||
expect(response.first).to include("too many requests from this IP address")
|
||||
expect(response.first).to include("Error code: ip_assets_10_secs_limit.")
|
||||
end
|
||||
end
|
||||
@ -582,6 +581,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, headers, response = middleware.call(env)
|
||||
expect(status).to eq(429)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("id_60_secs_limit")
|
||||
expect(response.first).to include("too many requests from this user")
|
||||
expect(response.first).to include("Error code: id_60_secs_limit.")
|
||||
end
|
||||
expect(called).to eq(3)
|
||||
@ -617,6 +617,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, headers, response = middleware.call(env)
|
||||
expect(status).to eq(429)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("ip_60_secs_limit")
|
||||
expect(response.first).to include("too many requests from this IP address")
|
||||
expect(response.first).to include("Error code: ip_60_secs_limit.")
|
||||
end
|
||||
end
|
||||
@ -652,6 +653,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
status, headers, response = middleware.call(env)
|
||||
expect(status).to eq(429)
|
||||
expect(headers["Discourse-Rate-Limit-Error-Code"]).to eq("ip_60_secs_limit")
|
||||
expect(response.first).to include("too many requests from this IP address")
|
||||
expect(response.first).to include("Error code: ip_60_secs_limit.")
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user