diff --git a/spec/allow2ban_spec.rb b/spec/allow2ban_spec.rb index 0b7e7805..105e0ad0 100644 --- a/spec/allow2ban_spec.rb +++ b/spec/allow2ban_spec.rb @@ -20,7 +20,8 @@ describe 'making ok request' do it 'succeeds' do get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' - last_response.status.must_equal 200 + + _(last_response.status).must_equal 200 end end @@ -29,17 +30,18 @@ before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' } it 'succeeds' do - last_response.status.must_equal 200 + _(last_response.status).must_equal 200 end it 'increases fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 1 + + _(@cache.store.read(key)).must_equal 1 end it 'is not banned' do key = "rack::attack:allow2ban:1.2.3.4" - @cache.store.read(key).must_be_nil + _(@cache.store.read(key)).must_be_nil end end @@ -51,17 +53,17 @@ end it 'succeeds' do - last_response.status.must_equal 200 + _(last_response.status).must_equal 200 end it 'increases fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is banned' do key = "rack::attack:allow2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end end @@ -77,7 +79,8 @@ describe 'making request for other discriminator' do it 'succeeds' do get '/', {}, 'REMOTE_ADDR' => '2.2.3.4' - last_response.status.must_equal 200 + + _(last_response.status).must_equal 200 end end @@ -87,17 +90,17 @@ end it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'does not increase fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is still banned' do key = "rack::attack:allow2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end @@ -107,17 +110,17 @@ end it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'does not increase fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is still banned' do key = "rack::attack:allow2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end end diff --git a/spec/fail2ban_spec.rb b/spec/fail2ban_spec.rb index 56c9ccc5..6a9d9bcf 100644 --- a/spec/fail2ban_spec.rb +++ b/spec/fail2ban_spec.rb @@ -20,7 +20,7 @@ describe 'making ok request' do it 'succeeds' do get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' - last_response.status.must_equal 200 + _(last_response.status).must_equal 200 end end @@ -29,17 +29,17 @@ before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' } it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'increases fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end it 'is not banned' do key = "rack::attack:fail2ban:1.2.3.4" - @cache.store.read(key).must_be_nil + _(@cache.store.read(key)).must_be_nil end end @@ -51,17 +51,17 @@ end it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'increases fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is banned' do key = "rack::attack:fail2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end @@ -73,7 +73,7 @@ end it 'succeeds' do - last_response.status.must_equal 200 + _(last_response.status).must_equal 200 end it 'resets fail count' do @@ -82,7 +82,7 @@ end it 'IP is not banned' do - Rack::Attack::Fail2Ban.banned?('1.2.3.4').must_equal false + _(Rack::Attack::Fail2Ban.banned?('1.2.3.4')).must_equal false end end end @@ -98,7 +98,8 @@ describe 'making request for other discriminator' do it 'succeeds' do get '/', {}, 'REMOTE_ADDR' => '2.2.3.4' - last_response.status.must_equal 200 + + _(last_response.status).must_equal 200 end end @@ -108,17 +109,17 @@ end it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'does not increase fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is still banned' do key = "rack::attack:fail2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end @@ -128,17 +129,17 @@ end it 'fails' do - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end it 'does not increase fail count' do key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" - @cache.store.read(key).must_equal 2 + _(@cache.store.read(key)).must_equal 2 end it 'is still banned' do key = "rack::attack:fail2ban:ban:1.2.3.4" - @cache.store.read(key).must_equal 1 + _(@cache.store.read(key)).must_equal 1 end end end diff --git a/spec/rack_attack_instrumentation_spec.rb b/spec/rack_attack_instrumentation_spec.rb index 50453205..a8b4527f 100644 --- a/spec/rack_attack_instrumentation_spec.rb +++ b/spec/rack_attack_instrumentation_spec.rb @@ -34,7 +34,7 @@ def throttle(_event) end it 'should instrument without error' do - last_response.status.must_equal 429 + _(last_response.status).must_equal 429 assert_equal 1, CustomSubscriber.notification_count end end diff --git a/spec/rack_attack_path_normalizer_spec.rb b/spec/rack_attack_path_normalizer_spec.rb index 961491d3..52fae263 100644 --- a/spec/rack_attack_path_normalizer_spec.rb +++ b/spec/rack_attack_path_normalizer_spec.rb @@ -6,14 +6,14 @@ subject { Rack::Attack::PathNormalizer } it 'should have a normalize_path method' do - subject.normalize_path('/foo').must_equal '/foo' + _(subject.normalize_path('/foo')).must_equal '/foo' end describe 'FallbackNormalizer' do subject { Rack::Attack::FallbackPathNormalizer } it '#normalize_path does not change the path' do - subject.normalize_path('').must_equal '' + _(subject.normalize_path('')).must_equal '' end end end diff --git a/spec/rack_attack_spec.rb b/spec/rack_attack_spec.rb index 39a09289..51d7cf44 100644 --- a/spec/rack_attack_spec.rb +++ b/spec/rack_attack_spec.rb @@ -12,7 +12,7 @@ it 'blocks requests with trailing slash' do get '/foo/' - last_response.status.must_equal 403 + _(last_response.status).must_equal 403 end end @@ -23,20 +23,20 @@ end it 'has a blocklist' do - Rack::Attack.blocklists.key?("ip #{@bad_ip}").must_equal true + _(Rack::Attack.blocklists.key?("ip #{@bad_ip}")).must_equal true end describe "a bad request" do before { get '/', {}, 'REMOTE_ADDR' => @bad_ip } it "should return a blocklist response" do - last_response.status.must_equal 403 - last_response.body.must_equal "Forbidden\n" + _(last_response.status).must_equal 403 + _(last_response.body).must_equal "Forbidden\n" end it "should tag the env" do - last_request.env['rack.attack.matched'].must_equal "ip #{@bad_ip}" - last_request.env['rack.attack.match_type'].must_equal :blocklist + _(last_request.env['rack.attack.matched']).must_equal "ip #{@bad_ip}" + _(last_request.env['rack.attack.match_type']).must_equal :blocklist end it_allows_ok_requests @@ -54,25 +54,25 @@ before { get '/', {}, 'REMOTE_ADDR' => @bad_ip, 'HTTP_USER_AGENT' => @good_ua } it "should allow safelists before blocklists" do - last_response.status.must_equal 200 + _(last_response.status).must_equal 200 end it "should tag the env" do - last_request.env['rack.attack.matched'].must_equal 'good ua' - last_request.env['rack.attack.match_type'].must_equal :safelist + _(last_request.env['rack.attack.matched']).must_equal 'good ua' + _(last_request.env['rack.attack.match_type']).must_equal :safelist end end end describe '#blocklisted_response' do it 'should exist' do - Rack::Attack.blocklisted_response.must_respond_to :call + _(Rack::Attack.blocklisted_response).must_respond_to :call end end describe '#throttled_response' do it 'should exist' do - Rack::Attack.throttled_response.must_respond_to :call + _(Rack::Attack.throttled_response).must_respond_to :call end end end diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index d760d942..8346611b 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -18,7 +18,7 @@ it 'should set the counter for one request' do key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" - Rack::Attack.cache.store.read(key).must_equal 1 + _(Rack::Attack.cache.store.read(key)).must_equal 1 end it 'should populate throttle data' do @@ -30,7 +30,7 @@ discriminator: "1.2.3.4" } - last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data + _(last_request.env['rack.attack.throttle_data']['ip/sec']).must_equal data end end @@ -40,14 +40,14 @@ end it 'should block the last request' do - last_response.status.must_equal 429 + _(last_response.status).must_equal 429 end it 'should tag the env' do - last_request.env['rack.attack.matched'].must_equal 'ip/sec' - last_request.env['rack.attack.match_type'].must_equal :throttle + _(last_request.env['rack.attack.matched']).must_equal 'ip/sec' + _(last_request.env['rack.attack.match_type']).must_equal :throttle - last_request.env['rack.attack.match_data'].must_equal( + _(last_request.env['rack.attack.match_data']).must_equal( count: 2, limit: 1, period: @period, @@ -55,11 +55,11 @@ discriminator: "1.2.3.4" ) - last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4') + _(last_request.env['rack.attack.match_discriminator']).must_equal('1.2.3.4') end it 'should set a Retry-After header' do - last_response.headers['Retry-After'].must_equal @period.to_s + _(last_response.headers['Retry-After']).must_equal @period.to_s end end end @@ -78,7 +78,7 @@ it 'should set the counter for one request' do key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" - Rack::Attack.cache.store.read(key).must_equal 1 + _(Rack::Attack.cache.store.read(key)).must_equal 1 end it 'should populate throttle data' do @@ -90,7 +90,7 @@ discriminator: "1.2.3.4" } - last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data + _(last_request.env['rack.attack.throttle_data']['ip/sec']).must_equal data end end end @@ -109,7 +109,7 @@ it 'should set the counter for one request' do key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" - Rack::Attack.cache.store.read(key).must_equal 1 + _(Rack::Attack.cache.store.read(key)).must_equal 1 end it 'should populate throttle data' do @@ -121,7 +121,7 @@ discriminator: "1.2.3.4" } - last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data + _(last_request.env['rack.attack.throttle_data']['ip/sec']).must_equal data end end end diff --git a/spec/rack_attack_track_spec.rb b/spec/rack_attack_track_spec.rb index bba70355..0db66e47 100644 --- a/spec/rack_attack_track_spec.rb +++ b/spec/rack_attack_track_spec.rb @@ -25,8 +25,9 @@ def self.check it "should tag the env" do get '/' - last_request.env['rack.attack.matched'].must_equal 'everything' - last_request.env['rack.attack.match_type'].must_equal :track + + _(last_request.env['rack.attack.matched']).must_equal 'everything' + _(last_request.env['rack.attack.match_type']).must_equal :track end describe "with a notification subscriber and two tracks" do @@ -43,21 +44,23 @@ def self.check end it "should notify twice" do - Counter.check.must_equal 2 + _(Counter.check).must_equal 2 end end describe "without limit and period options" do it "should assign the track filter to a Check instance" do track = Rack::Attack.track("homepage") { |req| req.path == "/" } - track.filter.class.must_equal Rack::Attack::Check + + _(track.filter.class).must_equal Rack::Attack::Check end end describe "with limit and period options" do it "should assign the track filter to a Throttle instance" do track = Rack::Attack.track("homepage", limit: 10, period: 10) { |req| req.path == "/" } - track.filter.class.must_equal Rack::Attack::Throttle + + _(track.filter.class).must_equal Rack::Attack::Throttle end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 553cb882..49d88731 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -56,8 +56,9 @@ def app def self.it_allows_ok_requests it "must allow ok requests" do get '/', {}, 'REMOTE_ADDR' => '127.0.0.1' - last_response.status.must_equal 200 - last_response.body.must_equal 'Hello World' + + _(last_response.status).must_equal 200 + _(last_response.body).must_equal 'Hello World' end end end