|
11 | 11 | end |
12 | 12 | end |
13 | 13 |
|
14 | | - it "can be customized" do |
15 | | - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
16 | | - |
17 | | - assert_equal 200, last_response.status |
18 | | - |
19 | | - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
20 | | - |
21 | | - assert_equal 429, last_response.status |
22 | | - |
| 14 | + it "can be customized with throttled_callback" do |
23 | 15 | Rack::Attack.throttled_callback = lambda do |_req| |
24 | 16 | [503, {}, ["Throttled"]] |
25 | 17 | end |
26 | 18 |
|
27 | 19 | get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
28 | 20 |
|
| 21 | + assert_equal 200, last_response.status |
| 22 | + |
| 23 | + get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
| 24 | + |
29 | 25 | assert_equal 503, last_response.status |
30 | 26 | assert_equal "Throttled", last_response.body |
31 | 27 | end |
|
59 | 55 | assert_equal 3, match_data[:count] |
60 | 56 | end |
61 | 57 |
|
62 | | - it "supports old style" do |
63 | | - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
64 | | - |
65 | | - assert_equal 200, last_response.status |
66 | | - |
67 | | - get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
68 | | - |
69 | | - assert_equal 429, last_response.status |
70 | | - |
| 58 | + it "can be customized with throttled_response" do |
71 | 59 | Rack::Attack.throttled_response = lambda do |_req| |
72 | 60 | [503, {}, ["Throttled"]] |
73 | 61 | end |
74 | 62 |
|
75 | 63 | get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
76 | 64 |
|
| 65 | + assert_equal 200, last_response.status |
| 66 | + |
| 67 | + get "/", {}, "REMOTE_ADDR" => "1.2.3.4" |
| 68 | + |
77 | 69 | assert_equal 503, last_response.status |
78 | 70 | assert_equal "Throttled", last_response.body |
79 | 71 | end |
|
0 commit comments