diff options
author | Yuji Yaginuma <yuuji.yaginuma@gmail.com> | 2018-01-08 12:16:53 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 12:16:53 +0900 |
commit | bd79c651e0fd5f41ae39dfe8cc46901cdaf3468c (patch) | |
tree | 87febcc0e62e623d3f23dec38f897a466a1caa6f | |
parent | 1ba8412607ae7190dc1c59718099e2f04372905d (diff) | |
parent | d2113777a137bb6740d576cd75061782703f075b (diff) | |
download | rails-bd79c651e0fd5f41ae39dfe8cc46901cdaf3468c.tar.gz rails-bd79c651e0fd5f41ae39dfe8cc46901cdaf3468c.tar.bz2 rails-bd79c651e0fd5f41ae39dfe8cc46901cdaf3468c.zip |
Merge pull request #31547 from eugeneius/use_authenticated_message_encryption_new_framework_defaults
Allow use_authenticated_message_encryption to be set in new_framework_defaults_5_2.rb
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/railtie.rb | 8 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 30 |
3 files changed, 34 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 27fd061947..5236c776dd 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -81,9 +81,9 @@ module ActiveSupport class MessageEncryptor prepend Messages::Rotator::Encryptor - class << self - attr_accessor :use_authenticated_message_encryption #:nodoc: + cattr_accessor :use_authenticated_message_encryption, instance_accessor: false, default: false + class << self def default_cipher #:nodoc: if use_authenticated_message_encryption "aes-256-gcm" diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 91872e29c8..635d98367e 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -10,9 +10,11 @@ module ActiveSupport config.eager_load_namespaces << ActiveSupport initializer "active_support.set_authenticated_message_encryption" do |app| - if app.config.active_support.respond_to?(:use_authenticated_message_encryption) - ActiveSupport::MessageEncryptor.use_authenticated_message_encryption = - app.config.active_support.use_authenticated_message_encryption + config.after_initialize do + unless app.config.active_support.use_authenticated_message_encryption.nil? + ActiveSupport::MessageEncryptor.use_authenticated_message_encryption = + app.config.active_support.use_authenticated_message_encryption + end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 907eb4fa58..437b1ded72 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1739,9 +1739,7 @@ module ApplicationTests test "default SQLite3Adapter.represent_boolean_as_integer for 5.1 is false" do remove_from_config '.*config\.load_defaults.*\n' - add_to_top_of_config <<-RUBY - config.load_defaults 5.1 - RUBY + app_file "app/models/post.rb", <<-RUBY class Post < ActiveRecord::Base end @@ -1890,6 +1888,32 @@ module ApplicationTests assert_equal "https://example.org/", last_response.location end + test "ActiveSupport::MessageEncryptor.use_authenticated_message_encryption is true by default for new apps" do + app "development" + + assert_equal true, ActiveSupport::MessageEncryptor.use_authenticated_message_encryption + end + + test "ActiveSupport::MessageEncryptor.use_authenticated_message_encryption is false by default for upgraded apps" do + remove_from_config '.*config\.load_defaults.*\n' + + app "development" + + assert_equal false, ActiveSupport::MessageEncryptor.use_authenticated_message_encryption + end + + test "ActiveSupport::MessageEncryptor.use_authenticated_message_encryption can be configured via config.active_support.use_authenticated_message_encryption" do + remove_from_config '.*config\.load_defaults.*\n' + + app_file "config/initializers/new_framework_defaults_5_2.rb", <<-RUBY + Rails.application.config.active_support.use_authenticated_message_encryption = true + RUBY + + app "development" + + assert_equal true, ActiveSupport::MessageEncryptor.use_authenticated_message_encryption + end + test "config.active_support.hash_digest_class is Digest::MD5 by default" do app "development" |