rack-attack-recaptcha 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/rack/attack/recaptcha.rb +9 -5
- data/lib/rack/attack/recaptcha/client_helper.rb +1 -1
- data/lib/rack/attack/recaptcha/rails.rb +5 -3
- data/lib/rack/attack/recaptcha/verification_helper.rb +1 -1
- data/lib/rack/attack/recaptcha/version.rb +2 -2
- data/spec/client_helper_spec.rb +1 -1
- data/spec/rack_attack_recaptcha_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/verification_helper_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42e689dc0d03cdf5b116e1ab5ac3f723d053edf9
|
4
|
+
data.tar.gz: 8876a9603be91f09dd608366ca341693b6195339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4b2d4fcf482dc6495cf50b17965d3f8948d1cc229c2024d60d8406e165a98f3b812a701152a288bb550bd25beee0c8bf8364a755a3ca11ce81324605d90b0fe
|
7
|
+
data.tar.gz: f4ab497698bdabf287d794640158b51d7dc89523218188f509916c7994ab376568315e2489644eddb204038d454ac2f21ff8cf4149757eaf797af7b730a0eb30
|
data/README.md
CHANGED
@@ -31,7 +31,14 @@ Tell your app to use the Rack::Attack middleware. For Rails 3+ apps:
|
|
31
31
|
# In config/application.rb
|
32
32
|
config.middleware.use Rack::Attack::Recaptcha
|
33
33
|
|
34
|
-
To setup throttles,
|
34
|
+
To setup Recaptcha throttles, you should specify the throttle's type to
|
35
|
+
be `:recaptcha` as shown here:
|
36
|
+
|
37
|
+
Rack::Attack.throttle('req/ip', :limit => 5, :period => 1.second, :type => :recaptcha) do |req|
|
38
|
+
req.ip
|
39
|
+
end
|
40
|
+
|
41
|
+
Check out [rack-attack's](https://github.com/kickstarter/rack-attack)'s wiki for more details on setting throttles.
|
35
42
|
To setup Recaptcha credentials, check out [recaptcha](http://github.com/ambethia/recaptcha)'s wiki.
|
36
43
|
|
37
44
|
## Usage
|
@@ -2,17 +2,21 @@ require "rack/attack"
|
|
2
2
|
require "rack/attack/recaptcha/version"
|
3
3
|
require "rack/attack/recaptcha/client_helper"
|
4
4
|
require "rack/attack/recaptcha/verification_helper"
|
5
|
-
require "rack/attack/recaptcha/rails"
|
6
5
|
|
7
6
|
module Rack
|
8
|
-
|
7
|
+
class Attack
|
9
8
|
module Recaptcha
|
10
9
|
class << self
|
11
10
|
def new(app)
|
11
|
+
@default_response = Rack::Attack.throttled_response
|
12
12
|
@rack_attack = Rack::Attack.new(app).tap { |attack|
|
13
|
-
attack.throttled_response = lambda { |env|
|
14
|
-
env["rack.attack.
|
15
|
-
|
13
|
+
attack.class.throttled_response = lambda { |env|
|
14
|
+
if env["rack.attack.match_type"] == :recaptcha
|
15
|
+
env["rack.attack.use_recaptcha"] = true
|
16
|
+
app
|
17
|
+
else
|
18
|
+
@default_response
|
19
|
+
end.call(env)
|
16
20
|
}
|
17
21
|
}
|
18
22
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
if defined?(Rails)
|
2
|
+
require "recaptcha/rails"
|
2
3
|
|
3
|
-
ActionView::Base.send(:include, Rack::Attack::Recaptcha::ClientHelper)
|
4
|
-
ActionController::Base.send(:include, Rack::Attack::Recaptcha::VerificationHelper)
|
4
|
+
ActionView::Base.send(:include, Rack::Attack::Recaptcha::ClientHelper)
|
5
|
+
ActionController::Base.send(:include, Rack::Attack::Recaptcha::VerificationHelper)
|
6
|
+
end
|
data/spec/client_helper_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe "Rack::Attack::Recaptcha" do
|
|
18
18
|
before do
|
19
19
|
@bad_ip = "1.2.3.4"
|
20
20
|
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
21
|
-
Rack::Attack.throttle("req/ip", :limit => 1, :period => 1) { |req| req.ip }
|
21
|
+
Rack::Attack.throttle("req/ip", :limit => 1, :period => 1, :type => :recaptcha) { |req| req.ip }
|
22
22
|
end
|
23
23
|
|
24
24
|
it "always delegates request to the underlying app" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-attack-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omer Lachish-Rauchwerger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|