Skip to content

Commit

Permalink
Merge pull request #279 from patorash/fix-web_console-permissions
Browse files Browse the repository at this point in the history
Fix initializer "web_console.permissions"
  • Loading branch information
gsamokovarov authored May 28, 2019
2 parents ca62054 + aa67b70 commit 95bcf59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/web_console/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
module WebConsole
class Railtie < ::Rails::Railtie
config.web_console = ActiveSupport::OrderedOptions.new
config.web_console.permissions = %w( 127.0.0.1 ::1 )

initializer "web_console.initialize" do
require "bindex"
Expand Down Expand Up @@ -53,9 +52,8 @@ class Railtie < ::Rails::Railtie
end

initializer "web_console.permissions" do
if permissions = config.web_console.permissions || config.web_console.whitelisted_ips
Request.permissions = Permissions.new(permissions)
end
permissions = config.web_console.permissions || config.web_console.whitelisted_ips
Request.permissions = Permissions.new(permissions)
end

initializer "web_console.whiny_requests" do
Expand Down
12 changes: 12 additions & 0 deletions test/web_console/railtie_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class RailtieTest < ActiveSupport::TestCase
end
end

test "config.permissions sets whitelisted networks by whitelisted_ips" do
new_uninitialized_app do |app|
app.config.web_console.whitelisted_ips = %w( 172.16.0.0/12 192.168.0.0/16 )
app.initialize!

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

test "config.permissions always includes localhost" do
new_uninitialized_app do |app|
app.config.web_console.permissions = "8.8.8.8"
Expand Down

0 comments on commit 95bcf59

Please sign in to comment.