Provide access to the application's KeyGenerator

Available both as an env entry for rack and an instance method on Rails::Application for other uses
This commit is contained in:
Michael Koziarski 2012-10-01 15:34:12 +13:00
parent def2ccb8e3
commit 0479bff32d
2 changed files with 11 additions and 1 deletions

@ -101,6 +101,14 @@ def reload_routes!
routes_reloader.reload!
end
# Return the application's KeyGenerator
def key_generator
# number of iterations selected based on consultation with the google security
# team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
@key_generator ||= ActiveSupport::KeyGenerator.new(config.secret_token, :iterations=>1000)
end
# Stores some of the Rails initial environment parameters which
# will be used by middlewares and engines to configure themselves.
# Currently stores:
@ -121,7 +129,8 @@ def env_config
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
"action_dispatch.logger" => Rails.logger,
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner,
"action_dispatch.key_generator" => key_generator
})
end

@ -634,6 +634,7 @@ def index
assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions
assert_equal app.env_config['action_dispatch.logger'], Rails.logger
assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner
assert_equal app.env_config['action_dispatch.key_generator'], Rails.application.key_generator
end
test "config.colorize_logging default is true" do