Skip to content

Commit

Permalink
Fix stray whitelisted_ips invocations and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsamokovarov committed Mar 29, 2019
1 parent 0154e04 commit bba90ba
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/web_console/whiny_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class WhinyRequest < SimpleDelegator
def permitted?
whine_unless request.permitted? do
"Cannot render console from #{request.strict_remote_ip}! " \
"Allowed networks: #{request.whitelisted_ips}"
"Allowed networks: #{request.permissions}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/web_console/extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def call(env)
end

setup do
Request.stubs(:whitelisted_ips).returns(IPAddr.new("0.0.0.0/0"))
Request.stubs(:permissions).returns(IPAddr.new("0.0.0.0/0"))

@app = DebugExceptions.new(Application.new)
end
Expand Down
2 changes: 1 addition & 1 deletion test/web_console/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def call(env)
Thread.current[:__web_console_exception] = nil
Thread.current[:__web_console_binding] = nil

Request.stubs(:whitelisted_ips).returns(IPAddr.new("0.0.0.0/0"))
Request.stubs(:permissions).returns(IPAddr.new("0.0.0.0/0"))

@app = Middleware.new(SingleConsoleApplication.new)
end
Expand Down
4 changes: 2 additions & 2 deletions test/web_console/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def headers
Thread.current[:__web_console_exception] = nil
Thread.current[:__web_console_binding] = nil
Rails.stubs(:root).returns Pathname(__FILE__).parent
Request.stubs(:whitelisted_ips).returns(IPAddr.new("0.0.0.0/0"))
Request.stubs(:permissions).returns(IPAddr.new("0.0.0.0/0"))

Middleware.mount_point = ""
@app = Middleware.new(Application.new)
Expand Down Expand Up @@ -141,7 +141,7 @@ def headers

test "doesn't render console from non whitelisted IP" do
Thread.current[:__web_console_binding] = binding
Request.stubs(:whitelisted_ips).returns(IPAddr.new("127.0.0.1"))
Request.stubs(:permissions).returns(IPAddr.new("127.0.0.1"))

silence(:stderr) do
get "/", params: nil, headers: { "REMOTE_ADDR" => "1.1.1.1" }
Expand Down
24 changes: 12 additions & 12 deletions test/web_console/permissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
module WebConsole
class PermissionsTest < ActiveSupport::TestCase
test "localhost is always whitelisted" do
whitelisted_ips = permit("8.8.8.8")
permissions = permit("8.8.8.8")

assert_includes whitelisted_ips, "127.0.0.1"
assert_includes whitelisted_ips, "::1"
assert_includes permissions, "127.0.0.1"
assert_includes permissions, "::1"
end

test "permits single IPs" do
whitelisted_ips = permit("8.8.8.8")
permissions = permit("8.8.8.8")

assert_includes whitelisted_ips, "8.8.8.8"
assert_includes permissions, "8.8.8.8"
end

test "permits whole networks" do
whitelisted_ips = permit("172.16.0.0/12")
permissions = permit("172.16.0.0/12")

1.upto(255).each do |n|
assert_includes whitelisted_ips, "172.16.0.#{n}"
assert_includes permissions, "172.16.0.#{n}"
end
end

test "permits multiple networks" do
whitelisted_ips = permit %w(172.16.0.0/12 192.168.0.0/16)
permissions = permit %w(172.16.0.0/12 192.168.0.0/16)

1.upto(255).each do |n|
assert_includes whitelisted_ips, "172.16.0.#{n}"
assert_includes whitelisted_ips, "192.168.0.#{n}"
assert_includes permissions, "172.16.0.#{n}"
assert_includes permissions, "192.168.0.#{n}"
end
end

test "ignores UNIX socket" do
whitelisted_ips = permit("8.8.8.8")
permissions = permit("8.8.8.8")

assert_not_includes whitelisted_ips, "unix:"
assert_not_includes permissions, "unix:"
end

test "human readable presentation" do
Expand Down
2 changes: 1 addition & 1 deletion test/web_console/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module WebConsole
class RequestTest < ActiveSupport::TestCase
setup do
Request.stubs(:whitelisted_ips).returns(IPAddr.new("127.0.0.1"))
Request.stubs(:permissions).returns(IPAddr.new("127.0.0.1"))
end

test "#permitted? is falsy for blacklisted IPs" do
Expand Down
2 changes: 1 addition & 1 deletion test/web_console/whiny_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module WebConsole
class WhinyRequestTest < ActiveSupport::TestCase
test "#permitted? logs out to stderr" do
Request.stubs(:whitelisted_ips).returns(IPAddr.new("127.0.0.1"))
Request.stubs(:permissions).returns(IPAddr.new("127.0.0.1"))
WebConsole.logger.expects(:info)

req = request("http://example.com", "REMOTE_ADDR" => "0.0.0.0")
Expand Down

0 comments on commit bba90ba

Please sign in to comment.