Skip to content

Commit

Permalink
Fix reset! when using namespaced cache store
Browse files Browse the repository at this point in the history
  • Loading branch information
santib committed Nov 4, 2024
1 parent 427fdfa commit f09caad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/attack/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def delete(unprefixed_key)

def reset!
if store.respond_to?(:delete_matched)
store.delete_matched("#{prefix}*")
store.delete_matched(/#{prefix}*/)
else
raise(
Rack::Attack::IncompatibleStoreError,
Expand Down
13 changes: 13 additions & 0 deletions spec/rack_attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,18 @@
_(redis.get("#{Rack::Attack.cache.prefix}::key")).must_be_nil
end
end

if defined?(ActiveSupport::Cache::MemoryStore)
it 'should delete rack attack keys' do
memory_store = ActiveSupport::Cache::MemoryStore.new(namespace: 'ns')
memory_store.write('key', 'value')
memory_store.write("#{Rack::Attack.cache.prefix}::key", 'value')
Rack::Attack.cache.store = memory_store
Rack::Attack.reset!

_(memory_store.read('key')).must_equal 'value'
_(memory_store.read("#{Rack::Attack.cache.prefix}::key")).must_be_nil
end
end
end
end

0 comments on commit f09caad

Please sign in to comment.