Skip to content

Commit fd20970

Browse files
authored
Merge pull request rails#49839 from skipkayhil/hm-skb-deprecation
Fix config.secret_key_base warning about secrets
2 parents c37efa1 + 1abd331 commit fd20970

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

railties/lib/rails/application.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,21 @@ def secret_key_base
477477
config.secret_key_base ||= generate_local_secret
478478
else
479479
validate_secret_key_base(
480-
ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || secrets.secret_key_base
480+
ENV["SECRET_KEY_BASE"] || credentials.secret_key_base || begin
481+
secret_skb = secrets_secret_key_base
482+
483+
if secret_skb.equal?(config.secret_key_base)
484+
config.secret_key_base
485+
else
486+
Rails.deprecator.warn(<<~MSG.squish)
487+
Your `secret_key_base is configured in `Rails.application.secrets`,
488+
which is deprecated in favor of `Rails.application.credentials` and
489+
will be removed in Rails 7.2.
490+
MSG
491+
492+
secret_skb
493+
end
494+
end
481495
)
482496
end
483497
end

railties/test/application/configuration_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,20 @@ def index
965965
assert_equal "3b7cd727ee24e8444053437c36cc66c3", app.secret_key_base
966966
end
967967

968+
test "config.secret_key_base does not lead to a deprecation" do
969+
remove_file "config/secrets.yml"
970+
app_file "config/initializers/secret_token.rb", <<-RUBY
971+
Rails.application.credentials.secret_key_base = nil
972+
Rails.application.config.secret_key_base = "3b7cd727ee24e8444053437c36cc66c3"
973+
RUBY
974+
975+
app "production"
976+
977+
assert_not_deprecated(Rails.deprecator) do
978+
assert_equal "3b7cd727ee24e8444053437c36cc66c3", app.secret_key_base
979+
end
980+
end
981+
968982
test "custom secrets saved in config/secrets.yml are loaded in app secrets" do
969983
app_file "config/secrets.yml", <<-YAML
970984
development:

0 commit comments

Comments
 (0)