Browse files

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
  • Loading branch information...
1 parent def2ccb commit 0479bff32dfb26a420b9ab4e2c2e6c2ed17550a3 @NZKoz NZKoz committed Oct 1, 2012
Showing with 11 additions and 1 deletion.
  1. +10 −1 railties/lib/rails/application.rb
  2. +1 −0 railties/test/application/configuration_test.rb
View
11 railties/lib/rails/application.rb
@@ -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
View
1 railties/test/application/configuration_test.rb
@@ -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

0 comments on commit 0479bff

Please sign in to comment.