File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -96,9 +96,16 @@ def reset!
9696
9797 attr_reader :configuration
9898
99- def initialize ( app )
99+ def initialize ( app , & block )
100100 @app = app
101- @configuration = self . class . configuration
101+ @configuration =
102+ if block_given?
103+ configuration = Configuration . new
104+ configuration . instance_exec ( &block )
105+ configuration
106+ else
107+ self . class . configuration
108+ end
102109 end
103110
104111 def call ( env )
Original file line number Diff line number Diff line change 1616 @app . initialize!
1717 assert @app . middleware . include? ( Rack ::Attack )
1818 end
19+
20+ it "can be configured via a block" do
21+ @app . middleware . delete ( Rack ::Attack )
22+ @app . middleware . use ( Rack ::Attack ) do
23+ blocklist_ip ( "1.2.3.4" )
24+ end
25+ get "/" , { } , "REMOTE_ADDR" => "1.2.3.4"
26+ assert_equal 403 , last_response . status
27+
28+ get "/" , { } , "REMOTE_ADDR" => "4.3.2.1"
29+ assert_equal 200 , last_response . status
30+ end
1931 end
2032end
You can’t perform that action at this time.
0 commit comments