mirror of https://github.com/rails/rails
Merge pull request #50788 from Shopify/cleanup-file-store
`RateLimiting` Cleanups
This commit is contained in:
commit
8e0a702bf3
|
@ -4,13 +4,13 @@ require "abstract_unit"
|
|||
|
||||
class RateLimitedController < ActionController::Base
|
||||
self.cache_store = ActiveSupport::Cache::MemoryStore.new
|
||||
rate_limit to: 2, within: 2.seconds, by: -> { Thread.current[:redis_test_seggregation] }, only: :limited_to_two
|
||||
rate_limit to: 2, within: 2.seconds, only: :limited_to_two
|
||||
|
||||
def limited_to_two
|
||||
head :ok
|
||||
end
|
||||
|
||||
rate_limit to: 2, within: 2.seconds, by: -> { Thread.current[:redis_test_seggregation] }, with: -> { head :forbidden }, only: :limited_with
|
||||
rate_limit to: 2, within: 2.seconds, by: -> { params[:rate_limit_key] }, with: -> { head :forbidden }, only: :limited_with
|
||||
def limited_with
|
||||
head :ok
|
||||
end
|
||||
|
@ -44,6 +44,16 @@ class RateLimitingTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "limit by" do
|
||||
get :limited_with
|
||||
get :limited_with
|
||||
get :limited_with
|
||||
assert_response :forbidden
|
||||
|
||||
get :limited_with, params: { rate_limit_key: "other" }
|
||||
get :limited_with
|
||||
end
|
||||
|
||||
test "limited with" do
|
||||
get :limited_with
|
||||
get :limited_with
|
||||
|
|
|
@ -210,13 +210,12 @@ module ActiveSupport
|
|||
# Modifies the amount of an integer value that is stored in the cache.
|
||||
# If the key is not found it is created and set to +amount+.
|
||||
def modify_value(name, amount, options)
|
||||
file_name = normalize_key(name, options)
|
||||
options = merged_options(options)
|
||||
key = normalize_key(name, options)
|
||||
version = normalize_version(name, options)
|
||||
amount = Integer(amount)
|
||||
|
||||
lock_file(file_name) do
|
||||
lock_file(key) do
|
||||
entry = read_entry(key, **options)
|
||||
|
||||
if !entry || entry.expired? || entry.mismatched?(version)
|
||||
|
|
Loading…
Reference in New Issue