test: fix minitest/spec deprecation warnings

This commit is contained in:
Gonzalo Rodriguez 2019-10-01 17:19:44 -03:00
parent 6fba2c010d
commit bdc89dde7b
No known key found for this signature in database
GPG key ID: 5DB8B81B049B8AB1
8 changed files with 71 additions and 63 deletions

View file

@ -20,7 +20,8 @@ describe 'Rack::Attack.Allow2Ban' do
describe 'making ok request' do describe 'making ok request' do
it 'succeeds' do it 'succeeds' do
get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' get '/', {}, 'REMOTE_ADDR' => '1.2.3.4'
last_response.status.must_equal 200
_(last_response.status).must_equal 200
end end
end end
@ -29,17 +30,18 @@ describe 'Rack::Attack.Allow2Ban' do
before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' } before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' }
it 'succeeds' do it 'succeeds' do
last_response.status.must_equal 200 _(last_response.status).must_equal 200
end end
it 'increases fail count' do it 'increases fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" 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 end
it 'is not banned' do it 'is not banned' do
key = "rack::attack:allow2ban:1.2.3.4" key = "rack::attack:allow2ban:1.2.3.4"
@cache.store.read(key).must_be_nil _(@cache.store.read(key)).must_be_nil
end end
end end
@ -51,17 +53,17 @@ describe 'Rack::Attack.Allow2Ban' do
end end
it 'succeeds' do it 'succeeds' do
last_response.status.must_equal 200 _(last_response.status).must_equal 200
end end
it 'increases fail count' do it 'increases fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" 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 end
it 'is banned' do it 'is banned' do
key = "rack::attack:allow2ban:ban:1.2.3.4" 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 end
end end
@ -77,7 +79,8 @@ describe 'Rack::Attack.Allow2Ban' do
describe 'making request for other discriminator' do describe 'making request for other discriminator' do
it 'succeeds' do it 'succeeds' do
get '/', {}, 'REMOTE_ADDR' => '2.2.3.4' get '/', {}, 'REMOTE_ADDR' => '2.2.3.4'
last_response.status.must_equal 200
_(last_response.status).must_equal 200
end end
end end
@ -87,17 +90,17 @@ describe 'Rack::Attack.Allow2Ban' do
end end
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'does not increase fail count' do it 'does not increase fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" 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 end
it 'is still banned' do it 'is still banned' do
key = "rack::attack:allow2ban:ban:1.2.3.4" 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 end
@ -107,17 +110,17 @@ describe 'Rack::Attack.Allow2Ban' do
end end
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'does not increase fail count' do it 'does not increase fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:allow2ban:count:1.2.3.4" 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 end
it 'is still banned' do it 'is still banned' do
key = "rack::attack:allow2ban:ban:1.2.3.4" 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 end
end end

View file

@ -20,7 +20,7 @@ describe 'Rack::Attack.Fail2Ban' do
describe 'making ok request' do describe 'making ok request' do
it 'succeeds' do it 'succeeds' do
get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' get '/', {}, 'REMOTE_ADDR' => '1.2.3.4'
last_response.status.must_equal 200 _(last_response.status).must_equal 200
end end
end end
@ -29,17 +29,17 @@ describe 'Rack::Attack.Fail2Ban' do
before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' } before { get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' }
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'increases fail count' do it 'increases fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" 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 end
it 'is not banned' do it 'is not banned' do
key = "rack::attack:fail2ban:1.2.3.4" key = "rack::attack:fail2ban:1.2.3.4"
@cache.store.read(key).must_be_nil _(@cache.store.read(key)).must_be_nil
end end
end end
@ -51,17 +51,17 @@ describe 'Rack::Attack.Fail2Ban' do
end end
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'increases fail count' do it 'increases fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" 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 end
it 'is banned' do it 'is banned' do
key = "rack::attack:fail2ban:ban:1.2.3.4" 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 end
@ -73,7 +73,7 @@ describe 'Rack::Attack.Fail2Ban' do
end end
it 'succeeds' do it 'succeeds' do
last_response.status.must_equal 200 _(last_response.status).must_equal 200
end end
it 'resets fail count' do it 'resets fail count' do
@ -82,7 +82,7 @@ describe 'Rack::Attack.Fail2Ban' do
end end
it 'IP is not banned' do 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 end
end end
@ -98,7 +98,8 @@ describe 'Rack::Attack.Fail2Ban' do
describe 'making request for other discriminator' do describe 'making request for other discriminator' do
it 'succeeds' do it 'succeeds' do
get '/', {}, 'REMOTE_ADDR' => '2.2.3.4' get '/', {}, 'REMOTE_ADDR' => '2.2.3.4'
last_response.status.must_equal 200
_(last_response.status).must_equal 200
end end
end end
@ -108,17 +109,17 @@ describe 'Rack::Attack.Fail2Ban' do
end end
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'does not increase fail count' do it 'does not increase fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" 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 end
it 'is still banned' do it 'is still banned' do
key = "rack::attack:fail2ban:ban:1.2.3.4" 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 end
@ -128,17 +129,17 @@ describe 'Rack::Attack.Fail2Ban' do
end end
it 'fails' do it 'fails' do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
it 'does not increase fail count' do it 'does not increase fail count' do
key = "rack::attack:#{Time.now.to_i / @findtime}:fail2ban:count:1.2.3.4" 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 end
it 'is still banned' do it 'is still banned' do
key = "rack::attack:fail2ban:ban:1.2.3.4" 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 end
end end

View file

@ -34,7 +34,7 @@ if ActiveSupport::VERSION::MAJOR > 3
end end
it 'should instrument without error' do it 'should instrument without error' do
last_response.status.must_equal 429 _(last_response.status).must_equal 429
assert_equal 1, CustomSubscriber.notification_count assert_equal 1, CustomSubscriber.notification_count
end end
end end

View file

@ -6,14 +6,14 @@ describe Rack::Attack::PathNormalizer do
subject { Rack::Attack::PathNormalizer } subject { Rack::Attack::PathNormalizer }
it 'should have a normalize_path method' do it 'should have a normalize_path method' do
subject.normalize_path('/foo').must_equal '/foo' _(subject.normalize_path('/foo')).must_equal '/foo'
end end
describe 'FallbackNormalizer' do describe 'FallbackNormalizer' do
subject { Rack::Attack::FallbackPathNormalizer } subject { Rack::Attack::FallbackPathNormalizer }
it '#normalize_path does not change the path' do it '#normalize_path does not change the path' do
subject.normalize_path('').must_equal '' _(subject.normalize_path('')).must_equal ''
end end
end end
end end

View file

@ -12,7 +12,7 @@ describe 'Rack::Attack' do
it 'blocks requests with trailing slash' do it 'blocks requests with trailing slash' do
get '/foo/' get '/foo/'
last_response.status.must_equal 403 _(last_response.status).must_equal 403
end end
end end
@ -23,20 +23,20 @@ describe 'Rack::Attack' do
end end
it 'has a blocklist' do 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 end
describe "a bad request" do describe "a bad request" do
before { get '/', {}, 'REMOTE_ADDR' => @bad_ip } before { get '/', {}, 'REMOTE_ADDR' => @bad_ip }
it "should return a blocklist response" do it "should return a blocklist response" do
last_response.status.must_equal 403 _(last_response.status).must_equal 403
last_response.body.must_equal "Forbidden\n" _(last_response.body).must_equal "Forbidden\n"
end end
it "should tag the env" do it "should tag the env" do
last_request.env['rack.attack.matched'].must_equal "ip #{@bad_ip}" _(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.match_type']).must_equal :blocklist
end end
it_allows_ok_requests it_allows_ok_requests
@ -54,25 +54,25 @@ describe 'Rack::Attack' do
before { get '/', {}, 'REMOTE_ADDR' => @bad_ip, 'HTTP_USER_AGENT' => @good_ua } before { get '/', {}, 'REMOTE_ADDR' => @bad_ip, 'HTTP_USER_AGENT' => @good_ua }
it "should allow safelists before blocklists" do it "should allow safelists before blocklists" do
last_response.status.must_equal 200 _(last_response.status).must_equal 200
end end
it "should tag the env" do it "should tag the env" do
last_request.env['rack.attack.matched'].must_equal 'good ua' _(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.match_type']).must_equal :safelist
end end
end end
end end
describe '#blocklisted_response' do describe '#blocklisted_response' do
it 'should exist' do it 'should exist' do
Rack::Attack.blocklisted_response.must_respond_to :call _(Rack::Attack.blocklisted_response).must_respond_to :call
end end
end end
describe '#throttled_response' do describe '#throttled_response' do
it 'should exist' do it 'should exist' do
Rack::Attack.throttled_response.must_respond_to :call _(Rack::Attack.throttled_response).must_respond_to :call
end end
end end
end end

View file

@ -18,7 +18,7 @@ describe 'Rack::Attack.throttle' do
it 'should set the counter for one request' do it 'should set the counter for one request' do
key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" 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 end
it 'should populate throttle data' do it 'should populate throttle data' do
@ -30,7 +30,7 @@ describe 'Rack::Attack.throttle' do
discriminator: "1.2.3.4" 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 end
@ -40,14 +40,14 @@ describe 'Rack::Attack.throttle' do
end end
it 'should block the last request' do it 'should block the last request' do
last_response.status.must_equal 429 _(last_response.status).must_equal 429
end end
it 'should tag the env' do it 'should tag the env' do
last_request.env['rack.attack.matched'].must_equal 'ip/sec' _(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_type']).must_equal :throttle
last_request.env['rack.attack.match_data'].must_equal( _(last_request.env['rack.attack.match_data']).must_equal(
count: 2, count: 2,
limit: 1, limit: 1,
period: @period, period: @period,
@ -55,11 +55,11 @@ describe 'Rack::Attack.throttle' do
discriminator: "1.2.3.4" 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 end
it 'should set a Retry-After header' do 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 end
end end
@ -78,7 +78,7 @@ describe 'Rack::Attack.throttle with limit as proc' do
it 'should set the counter for one request' do it 'should set the counter for one request' do
key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" 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 end
it 'should populate throttle data' do it 'should populate throttle data' do
@ -90,7 +90,7 @@ describe 'Rack::Attack.throttle with limit as proc' do
discriminator: "1.2.3.4" 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 end
end end
@ -109,7 +109,7 @@ describe 'Rack::Attack.throttle with period as proc' do
it 'should set the counter for one request' do it 'should set the counter for one request' do
key = "rack::attack:#{Time.now.to_i / @period}:ip/sec:1.2.3.4" 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 end
it 'should populate throttle data' do it 'should populate throttle data' do
@ -121,7 +121,7 @@ describe 'Rack::Attack.throttle with period as proc' do
discriminator: "1.2.3.4" 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 end
end end

View file

@ -25,8 +25,9 @@ describe 'Rack::Attack.track' do
it "should tag the env" do it "should tag the env" do
get '/' 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 end
describe "with a notification subscriber and two tracks" do describe "with a notification subscriber and two tracks" do
@ -43,21 +44,23 @@ describe 'Rack::Attack.track' do
end end
it "should notify twice" do it "should notify twice" do
Counter.check.must_equal 2 _(Counter.check).must_equal 2
end end
end end
describe "without limit and period options" do describe "without limit and period options" do
it "should assign the track filter to a Check instance" do it "should assign the track filter to a Check instance" do
track = Rack::Attack.track("homepage") { |req| req.path == "/" } 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
end end
describe "with limit and period options" do describe "with limit and period options" do
it "should assign the track filter to a Throttle instance" 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 = 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 end
end end

View file

@ -56,8 +56,9 @@ class MiniTest::Spec
def self.it_allows_ok_requests def self.it_allows_ok_requests
it "must allow ok requests" do it "must allow ok requests" do
get '/', {}, 'REMOTE_ADDR' => '127.0.0.1' 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 end
end end