rack-pooledthrottle 0.0.2 → 0.0.3

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: 93f678ed4ba1803eb76022038615a86360dcf110
4
- data.tar.gz: 487c6c5332cc4469e6bba491a2233210d0db9468
3
+ metadata.gz: 609e48e88cc5bdf316fc4c338d6a6ba797f3c47c
4
+ data.tar.gz: 4f4b687d62cdd26a8cb428a01b798c8d3ed274fb
5
5
  SHA512:
6
- metadata.gz: 8c4f7308d1fa6628ce4fbfee90a68719de280646f5a47d4a79056cdd95d3835f906489a21c75f74213ceea3b1c6eb7eb49527b5d2fbdfaa80746964f57cf4328
7
- data.tar.gz: 4d39db54a3c1a065ad50ece2638705639281fdedb982087ae1ecd8d334feaef1f20bb9228a0f5bd0f6af349a2e5edbd4b3affb32e548a7f7a78544083acac04a
6
+ metadata.gz: 93cdde36423b6acd0504b487a9f26668a338f9b9dc3e801373fd77b7a1f8ef09983cbe85b1429df5d20f6ebd695410583c7dea7b4de4f7152bdea069919b5933
7
+ data.tar.gz: 43429d571f259b333d9cb978c5708c70922e469c45b34e8ef03ce2b6f3590b7ce31a22c180e832329352d3dc2157664b4a1c83a1272b4a95b9d1ce5f8badfbb7
@@ -13,13 +13,25 @@ module Rack
13
13
  end
14
14
 
15
15
  protected
16
+
17
+ def throttled_request?(request)
18
+ if f = options[:throttled_request]
19
+ f.call(request)
20
+ else
21
+ true
22
+ end
23
+ end
16
24
 
17
25
  def allowed?(request)
18
- case
19
- when whitelisted?(request) then true
20
- when blacklisted?(request) then false
21
- else
22
- query_cache?(request)
26
+ if throttled_request?(request)
27
+ case
28
+ when whitelisted?(request) then true
29
+ when blacklisted?(request) then false
30
+ else
31
+ query_cache?(request)
32
+ end
33
+ else
34
+ true
23
35
  end
24
36
  end
25
37
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Pooledthrottle
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -28,11 +28,19 @@ describe Rack::PooledThrottle::MemcachedThrottle do
28
28
  expect(last_response.body).to show_allowed_response
29
29
  end
30
30
 
31
- it 'expect a passing message' do
31
+ it 'expect a failing message' do
32
32
  4.times {get '/foo'}
33
33
  expect(last_response.body).to show_throttled_response
34
34
  end
35
35
 
36
+ it 'expect a failing message' do
37
+ @options[:max] = 0
38
+ @options[:message] = 'GO AWAY!'
39
+ get '/foo'
40
+ expect(last_response.body).to match(/GO AWAY/)
41
+ end
42
+
43
+
36
44
  it "should return true if whitelisted" do
37
45
  allow(app).to receive(:whitelisted?).and_return(true)
38
46
  4.times {get "/foo"}
@@ -83,5 +91,12 @@ describe Rack::PooledThrottle::MemcachedThrottle do
83
91
  3.times {get '/foo', email: 'scott@kickofflabs.com'}
84
92
  expect(last_response.body).to show_throttled_response
85
93
  end
94
+
95
+ it 'should allow certain requests to not be throttled' do
96
+ @options[:max] = 0
97
+ @options[:throttled_request] = ->(request){!request.path.end_with?('foo')}
98
+ get '/foo'
99
+ expect(last_response.body).to show_allowed_response
100
+ end
86
101
 
87
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-pooledthrottle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Watermasysk