Skip to content

Commit

Permalink
Merge pull request #444 from jdelStrother/allow-ipaddr
Browse files Browse the repository at this point in the history
Allow passing IPAddrs to allow_ip
  • Loading branch information
RobinDaugherty committed Oct 29, 2019
2 parents 1891ad8 + 361d506 commit 5e1d687
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/better_errors/middleware.rb
Expand Up @@ -33,7 +33,7 @@ class Middleware
# Adds an address to the set of IP addresses allowed to access Better
# Errors.
def self.allow_ip!(addr)
ALLOWED_IPS << IPAddr.new(addr)
ALLOWED_IPS << (addr.is_a?(IPAddr) ? addr : IPAddr.new(addr))
end

allow_ip! "127.0.0.0/8"
Expand Down
6 changes: 6 additions & 0 deletions spec/better_errors/middleware_spec.rb
Expand Up @@ -40,6 +40,12 @@ module BetterErrors
app.call("REMOTE_ADDR" => "77.55.33.11")
end

it "shows to a whitelisted IPAddr" do
BetterErrors::Middleware.allow_ip! IPAddr.new('77.55.33.0/24')
expect(app).to receive :better_errors_call
app.call("REMOTE_ADDR" => "77.55.33.11")
end

it "respects the X-Forwarded-For header" do
expect(app).not_to receive :better_errors_call
app.call(
Expand Down

0 comments on commit 5e1d687

Please sign in to comment.