Skip to content

Commit

Permalink
test: fix minitest/spec deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Oct 1, 2019
1 parent 6fba2c0 commit bdc89dd
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 63 deletions.
31 changes: 17 additions & 14 deletions spec/allow2ban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
33 changes: 17 additions & 16 deletions spec/fail2ban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rack_attack_instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rack_attack_path_normalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions spec/rack_attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit bdc89dd

Please sign in to comment.