-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into move_all_deps_to_gemspec
- Loading branch information
Showing
14 changed files
with
136 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "activesupport", "~> 5.2.0.a" | ||
gem "actionpack", "~> 5.2.0.a" | ||
|
||
group :development do | ||
gem "pry" | ||
gem "guard" | ||
gem "guard-minitest" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative "../spec_helper" | ||
|
||
describe "#blocklist" do | ||
before do | ||
Rack::Attack.blocklist("block 1.2.3.4") do |request| | ||
request.ip == "1.2.3.4" | ||
end | ||
end | ||
|
||
it "forbids request if blocklist condition is true" do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 403, last_response.status | ||
end | ||
|
||
it "succeeds if blocklist condition is false" do | ||
get "/", {}, "REMOTE_ADDR" => "5.6.7.8" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative "../spec_helper" | ||
|
||
describe "#safelist" do | ||
before do | ||
Rack::Attack.blocklist("block 1.2.3.4") do |request| | ||
request.ip == "1.2.3.4" | ||
end | ||
|
||
Rack::Attack.safelist("safe path") do |request| | ||
request.path == "/safe_space" | ||
end | ||
end | ||
|
||
it "forbids request if blocklist condition is true and safelist is false" do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 403, last_response.status | ||
end | ||
|
||
it "succeeds if blocklist condition is false and safelist is false" do | ||
get "/", {}, "REMOTE_ADDR" => "5.6.7.8" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
|
||
it "succeeds request if blocklist condition is false and safelist is true" do | ||
get "/safe_space", {}, "REMOTE_ADDR" => "5.6.7.8" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
|
||
it "succeeds request if both blocklist and safelist conditions are true" do | ||
get "/safe_space", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require_relative "../spec_helper" | ||
require "timecop" | ||
|
||
describe "#throttle" do | ||
it "allows one request per minute by IP" do | ||
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new | ||
|
||
Rack::Attack.throttle("by ip", limit: 1, period: 60) do |request| | ||
request.ip | ||
end | ||
|
||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 200, last_response.status | ||
|
||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 429, last_response.status | ||
|
||
get "/", {}, "REMOTE_ADDR" => "5.6.7.8" | ||
|
||
assert_equal 200, last_response.status | ||
|
||
Timecop.travel(60) do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ def remote_ip | |
end | ||
end | ||
|
||
allow_ok_requests | ||
it_allows_ok_requests | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters