rack-pooledthrottle 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rack/pooledthrottle/throttle.rb +10 -2
- data/lib/rack/pooledthrottle/version.rb +1 -1
- data/spec/memecached_spec.rb +24 -2
- 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: 93f678ed4ba1803eb76022038615a86360dcf110
|
4
|
+
data.tar.gz: 487c6c5332cc4469e6bba491a2233210d0db9468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c4f7308d1fa6628ce4fbfee90a68719de280646f5a47d4a79056cdd95d3835f906489a21c75f74213ceea3b1c6eb7eb49527b5d2fbdfaa80746964f57cf4328
|
7
|
+
data.tar.gz: 4d39db54a3c1a065ad50ece2638705639281fdedb982087ae1ecd8d334feaef1f20bb9228a0f5bd0f6af349a2e5edbd4b3affb32e548a7f7a78544083acac04a
|
data/.gitignore
CHANGED
@@ -28,11 +28,19 @@ module Rack
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def whitelisted?(request)
|
31
|
-
|
31
|
+
if wl = options[:whitelisted]
|
32
|
+
wl.call(request)
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def blacklisted?(request)
|
35
|
-
|
39
|
+
if bl = options[:blacklisted]
|
40
|
+
bl.call(request)
|
41
|
+
else
|
42
|
+
false
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
38
46
|
def cache_key(request)
|
data/spec/memecached_spec.rb
CHANGED
@@ -45,8 +45,30 @@ describe Rack::PooledThrottle::MemcachedThrottle do
|
|
45
45
|
expect(last_response.body).to show_throttled_response
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should allow blacklisted? to be overridden" do
|
49
|
+
@options[:blacklisted] = ->(request){true}
|
50
|
+
get "/foo"
|
51
|
+
expect(last_response.body).to show_throttled_response
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow whitelisted? to be overridden" do
|
55
|
+
@options[:whitelisted] = ->(request){true}
|
56
|
+
4.times {get "/foo"}
|
57
|
+
expect(last_response.body).to show_allowed_response
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should execute the rate_limit_exceeded_callback if it is defined' do
|
61
|
+
callback = Object.new
|
62
|
+
expect(callback).to receive(:call)
|
63
|
+
@options[:rate_limit_exceeded_callback] = callback
|
64
|
+
@options[:max] = 0
|
65
|
+
get '/foo'
|
66
|
+
expect(last_response.body).to show_throttled_response
|
67
|
+
|
68
|
+
end
|
69
|
+
|
48
70
|
|
49
|
-
it 'should allow the client_identifier to be
|
71
|
+
it 'should allow the client_identifier to be overridden and pass' do
|
50
72
|
@options[:max] = 2
|
51
73
|
@options[:client_identifier] = ->(request){request.params['email']}
|
52
74
|
2.times {get('/foo', email: 'scottwater@gmail.com')}
|
@@ -54,7 +76,7 @@ describe Rack::PooledThrottle::MemcachedThrottle do
|
|
54
76
|
expect(last_response.body).to show_allowed_response
|
55
77
|
end
|
56
78
|
|
57
|
-
it 'should allow the client_identifier to be
|
79
|
+
it 'should allow the client_identifier to be overridden and fail' do
|
58
80
|
@options[:max] = 2
|
59
81
|
@options[:client_identifier] = ->(request){request.params['email']}
|
60
82
|
2.times {get('/foo', email: 'scottwater@gmail.com')}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-pooledthrottle
|
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
|
- Scott Watermasysk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|