support nil ip

This commit is contained in:
Igor Wiedler 2016-07-05 12:46:32 +02:00
parent 0d90c21dbd
commit a210cf8661
2 changed files with 2 additions and 2 deletions

View File

@ -38,7 +38,7 @@ class Rack::Attack
# https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist/ # https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist/
whitelist('safelist anything coming from github') do |request| whitelist('safelist anything coming from github') do |request|
NetAddr::CIDR.create('192.30.252.0/22').contains?(request.ip) request.ip && NetAddr::CIDR.create('192.30.252.0/22').contains?(request.ip)
end end
#### ####

View File

@ -13,7 +13,7 @@ describe Rack::Attack do
describe 'request from GitHub ip' do describe 'request from GitHub ip' do
let(:request) { let(:request) {
env = Rack::MockRequest.env_for("https://api-test.travis-ci.org/repos/rails/rails/branches", { env = Rack::MockRequest.env_for("https://api-test.travis-ci.org/repos/rails/rails/branches", {
'REMOTE_ADDR' => '192.30.252.42' 'REMOTE_ADDR' => '192.30.252.42',
}) })
Rack::Attack::Request.new(env) Rack::Attack::Request.new(env)
} }