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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d867b620635d9c9982cb3de3d29ea2ccfa31978e
4
- data.tar.gz: 5ae0d7485b457f2f3371b2ad1a56dbfdee35d2f7
3
+ metadata.gz: 42e689dc0d03cdf5b116e1ab5ac3f723d053edf9
4
+ data.tar.gz: 8876a9603be91f09dd608366ca341693b6195339
5
5
  SHA512:
6
- metadata.gz: c589069fdc7844543f70b124f8a06c0d30e65d30a5a82366b6b73191d01f8024ac6a16a558d55ade91ff79e4bf24b0e72753fe59589d1cf702c309c875068451
7
- data.tar.gz: 70ee51e0dc169413fac883117a1b9930bebc882ab94fc6b41f12b4206b3186ad263514efeec032c0c27bc12b63a8d0fbe4ced74bfb8ae35a5b07eff0785742d1
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, check out rack-attack's wiki.
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
- module Attack
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.use_recaptcha"] = true
15
- app.call(env)
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,5 +1,5 @@
1
1
  module Rack
2
- module Attack
2
+ class Attack
3
3
  module Recaptcha
4
4
  module ClientHelper
5
5
  def recaptcha_tags_if_under_attack(options={})
@@ -1,4 +1,6 @@
1
- require "recaptcha/rails"
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
- module Attack
2
+ class Attack
3
3
  module Recaptcha
4
4
  module VerificationHelper
5
5
  def verify_recaptcha_if_under_attack(options={})
@@ -1,7 +1,7 @@
1
1
  module Rack
2
- module Attack
2
+ class Attack
3
3
  module Recaptcha
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -14,7 +14,7 @@ class DummyView
14
14
  end
15
15
 
16
16
  module Rack
17
- module Attack
17
+ class Attack
18
18
  module Recaptcha
19
19
  describe ClientHelper do
20
20
  describe ".recaptcha_tags_if_under_attack" do
@@ -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
@@ -1,8 +1,8 @@
1
+ require "active_support"
1
2
  require "minitest/autorun"
2
3
  require "minitest/pride"
3
4
  require "rack/test"
4
5
  require "rack/attack/recaptcha"
5
- require "active_support"
6
6
 
7
7
  require 'rspec/mocks'
8
8
 
@@ -14,7 +14,7 @@ class DummyController
14
14
  end
15
15
 
16
16
  module Rack
17
- module Attack
17
+ class Attack
18
18
  module Recaptcha
19
19
  describe ClientHelper do
20
20
  describe ".verify_recaptcha_if_under_attack" do
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.1
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 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler