Commit graph

50 commits

Author SHA1 Message Date
thomas morgan
2fc8c7b65f support rails 7.0 2021-11-17 11:33:17 -07:00
fukayatsu
9020201ff5 Fix Ruby 2.7 kwargs warning in RedisCacheStoreProxy 2020-12-15 23:25:37 +09:00
Ryan Laughlin
31dd7a8d17 Override RedisCacheStoreProxy#read to always use raw: true 2020-05-20 10:34:58 -04:00
Ryan Laughlin
d5a240d9d2 Fix deprecation warning in Rails 5.2.4.3 2020-05-18 17:14:12 -04:00
fatkodima
edaa6c6a91 Make store proxies lookup dynamic 2019-10-25 01:41:24 +03:00
fatkodima
18e637aea8 Allow to reset state between tests 2019-10-23 01:33:49 +03:00
fatkodima
20ec4d31db Do not rescue all errors for redis backed stores 2019-10-18 02:31:05 +03:00
fatkodima
2fac6418f8 Fix rescuing errors in RedisProxy#increment 2019-10-15 22:54:33 +03:00
Gonzalo Rodriguez
f5a352b8f9
style: limit line length to 120 columns 2019-08-02 10:51:53 -03:00
Cristian Greco
dd6c09e581 Failsafe on Redis error replies in RedisCacheStoreProxy.
RedisCacheStoreProxy will blow up when RedisCacheStore raises a
CommandError exception. In fact, by default the proxied store only
handles BaseConnectionError exceptions, but will let bubble up any other
type of exception from the underlying client.

This pull request uses the same approach from RedisProxy, where store
operations are wrapped in a `rescuing` block that rescues and ignores
BaseError exceptions (the most generic exception class that can be
raised by the Redis client).
2019-07-14 01:37:59 +01:00
Gonzalo Rodriguez
6541634fb0
style: enable Style/Semicolon rubocop 2019-03-01 22:25:27 -03:00
Gonzalo Rodriguez
a0259fb14a
style: enable Style/SingleLineMethods rubocop 2019-03-01 21:14:47 -03:00
Gonzalo Rodriguez
04eeeb9a33
refactor: avoid rescuing pattern repetition 2019-02-28 22:51:57 -03:00
Gonzalo Rodriguez
20d668211e
style: fix Lint/HandleExceptions rubocop 2019-02-28 21:17:36 -03:00
Gonzalo Rodriguez
014f74b95d
Merge pull request #387 from grzuy/fix_redis_3_and_memory_store
[Fixes #355] Fix unexpected error when using redis 3 and any store which is not proxied
2018-10-08 11:33:34 -03:00
Gonzalo Rodriguez
935f99a638
[Fixes #355] Avoid unexpected 'Gem::LoadError' for redis when not intented to be used
It seems that the original implementation accidentally autoloaded ActiveSupport::Cache::RedisCacheStore
which once evaluated asks for redis v4 generating Gem::LoadError.

In order to bypass any unnecessary constant autoloading we can just check class name string.
2018-09-30 22:13:30 -03:00
Gonzalo Rodriguez
91dbb52235
Remove unwrapping 2018-09-30 13:32:08 -03:00
Gonzalo Rodriguez
fc235c90c2
Merge pull request #382 from grzuy/cleanup_redis_cache_store_proxy
Remove unnecessary wrapping of ActiveSupport::Cache::RedisCacheStore#read
2018-09-03 23:15:39 -03:00
Gonzalo Rodriguez
55411e5e82
Remove MemCacheProxy which existed only for now obsolete memcache-client 2018-09-03 18:24:21 -03:00
Gonzalo Rodriguez
7001178b6d
Remove unnecessary wrapping of ActiveSupport::Cache::RedisCacheStore#read
`raw: true` isn't doing anything special for `read`, only for `write`
2018-09-03 17:55:29 -03:00
Jonathan del Strother
5cdc15b35a Add a proxy to deal with ActiveSupport::Cache::MemCacheStore
If connection pooling is used with AS::Cache::MemCacheStore,
unwrap_active_support_stores wouldn't return the underlying dalli instance(s),
and so Rack::Attack.store would be the bare unproxied MemCacheStore instance.

Calling write then increment would silently fail because :raw wasn't used.

With this commit, we no longer try to unwrap AS::Cache::MemCacheStore instances.
2018-09-03 12:00:02 +01:00
Gonzalo Rodriguez
673cf98157
Avoid as much repetition as possible between RedisProxy and RedisStoreProxy 2018-06-29 15:44:41 -03:00
Gonzalo Rodriguez
b40b5718dc
rubocop --auto-correct 2018-06-29 15:41:36 -03:00
Gonzalo Rodriguez
6fbb6c8b1c
Merge branch 'master' into support-redis-gem 2018-06-29 15:40:45 -03:00
Gonzalo Rodriguez
eb07d9789f
Prefer Gem::Version for version comparisons 2018-06-29 15:27:36 -03:00
Gonzalo Rodriguez
85c4c085c9
Remove duplicated #initialize 2018-06-29 15:27:20 -03:00
Gonzalo Rodriguez
d1682b19b4
Merge remote-tracking branch 'rfwatson/master' 2018-06-29 15:24:13 -03:00
Gonzalo Rodriguez
8315a1e7e1
Remove support for unmaintained ruby 2.2 2018-06-28 17:08:15 -03:00
Gonzalo Rodriguez
ee84079768
Fix 'redis is not part of the bundle' exception when using :memory_store
When RedisCacheStore constant is referenced, activesupport autoloads and
rails tries to require redis, throwing exception if not present
2018-06-25 17:42:45 -03:00
Gonzalo Rodriguez
d8b88cfb84
Honor amount argument instead of hard coding counter (part 2)
See commit ca2e752937
2018-06-21 11:25:47 -03:00
Gonzalo Rodriguez
2c1cbc323e
Default increment amount to 1 as RedisCacheStore 2018-06-20 19:14:37 -03:00
Gonzalo Rodriguez
ca2e752937
Honor amount argument instead of hard coding counter 2018-06-20 19:14:02 -03:00
Gonzalo Rodriguez
3af7394b6a
Refactor RedisCacheStoreProxy to unlearn everything about redis client details to make it less prone to bugs in the future
Let RedisCacheStoreProxy only know and assume things about
RedisCacheStore API. Don't let it know anything about the specific redis
client behind the scenes, that's the job of RedisCacheStore only, not
ours.
2018-06-20 18:33:00 -03:00
Alexey Vasiliev
3caee5c3ca
Fix usage of RedisCacheStore for rails 5.2.0 2018-06-20 18:06:45 -03:00
Gonzalo Rodriguez
86eb9f9e0a
Enable Style/BracesAroundHashParameters rubocop cop 2018-06-19 17:57:30 -03:00
Brian Kephart
4cc8d7d854
Support ActiveSupport::RedisCacheStore 2018-06-19 13:39:43 -03:00
Brian Kephart
b5b4164967 replace const_defined? with defined? 2018-05-13 17:45:12 -05:00
Gonzalo Rodriguez
52ec80692d
Enable Lint rubocop cops 2018-04-17 16:27:56 -04:00
Lucas Mansur
11e9557ccb [Fixes #302] Initial style guide adoption (#330)
* Initial Rubocop configuration

* Fix Rubocop layout offenses for lib

* Fix some spec offenses

* Fix leftover layout offenses
2018-03-30 16:08:00 -03:00
Brad Lindsay
0f6ef47683 Add a seperate cache-store proxy for the redis gem
While a cache-store proxy exists for the redis-store gem, no such proxy
existed for using the redis gem itself. This fills that gap by adding
such a proxy.

Resolves kickstarter/rack-attack#190
2018-02-06 09:33:02 -06:00
Gonzalo Rodriguez
6af29fb44e Avoid 'defined?' buggy behavior in ruby 2.5.0. Fixes #253
'defined?' is buggy in ruby 2.5.0, which under certain circumstances
users using rack-attack can hit. See issue #253.

I reported (https://bugs.ruby-lang.org/issues/14407) and
fixed (https://github.com/ruby/ruby/pull/1800) the issue in
ruby already, but i guess i would take some time before there's
a new ruby release including that fix.

So for now we would need to circumvent this bug by using
'const_defined?' instead of 'defined?' for this particular case.

More details:

Anyone using:
  * ruby 2.5.0
  * redis
  * rack-attack without redis-store and using at least one throttle
  * having a toplevel class named Store

will hit this ruby 2.5.0 bug https://bugs.ruby-lang.org/issues/14407

That's because of the following buggy behavior of 'defined?' under ruby
2.5:

```
$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

$ irb
> class Redis
> end
=> nil
> class Store
> end
=> nil
> defined?(::Redis::Store)
=> "constant"
> ::Redis::Store
  NameError (uninitialized constant Redis::Store
    Did you mean?  Store)
```
2018-01-29 12:25:18 -03:00
Gonzalo Rodriguez
b7eb7851cf Cleanup unnecessary self references 2018-01-25 15:52:20 -03:00
Rob Watson
69ab514477 Warn if Redis gem is < 3.0.0
Prefer printing a log message if this criteria is not met, instead of
failing silently.
2017-05-11 10:17:18 +01:00
Vincent Boisard
d880bd88e0 fix: workaround MemCacheClient + MemCache backend by using a dedicated proxy 2015-12-16 16:57:54 +01:00
Vincent Boisard
faa0638719 fix: Do not attempt to process Memcache clients with DalliProxy 2015-12-08 18:55:06 +01:00
Vincent Boisard
397a7ce7b4 feature: support for ActiveSupport::MemCacheStore 2015-12-08 10:53:53 +01:00
Aaron Suggs
0ec73d956b Merge pull request #119 from stanhu/add-delete-interface
Support delete method for Redis
2015-04-16 14:11:58 -04:00
Stan Hu
ff15447f3a Support delete method for Redis 2015-03-15 12:13:44 -07:00
Stan Hu
dc1b6bf687 Pass raw: true to prevent Ruby de/serialization. This is to make it possible
to implement something like:

```store.write(key, 0, :expires_in => expires_in)```

See #113
2015-03-15 07:18:18 -07:00
hakanensari
5d72c6e5f9 Move individual proxy classes to separate files 2014-04-15 16:19:43 +01:00