From 6c916488af936655f896b8631d17ec0563326f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gencer=20W=2E=20Gen=C3=A7?= Date: Tue, 15 May 2018 00:09:25 +0300 Subject: [PATCH] find auto-generated secret_key_base in development (#4869) With this fix, we will try latest changes in Rails 5.2 together with standard auto-generated secret_key_base in development as a fallback. If no specified key found, auto-generated value will be used instead. --- lib/devise/secret_key_finder.rb | 2 ++ test/secret_key_finder_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/devise/secret_key_finder.rb b/lib/devise/secret_key_finder.rb index 5a2fbfa4..d07106c4 100644 --- a/lib/devise/secret_key_finder.rb +++ b/lib/devise/secret_key_finder.rb @@ -13,6 +13,8 @@ module Devise @application.secrets.secret_key_base elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config) @application.config.secret_key_base + elsif @application.respond_to?(:secret_key_base) && key_exists?(@application) + @application.secret_key_base end end diff --git a/test/secret_key_finder_test.rb b/test/secret_key_finder_test.rb index af421d4c..434dbc8d 100644 --- a/test/secret_key_finder_test.rb +++ b/test/secret_key_finder_test.rb @@ -32,6 +32,24 @@ class Rails52Config end end +class Rails52SecretKeyBase + def credentials + OpenStruct.new(secret_key_base: nil) + end + + def secrets + OpenStruct.new(secret_key_base: nil) + end + + def config + OpenStruct.new(secret_key_base: nil) + end + + def secret_key_base + 'secret_key_base' + end +end + class Rails41Secrets def secrets OpenStruct.new(secret_key_base: 'secrets') @@ -77,6 +95,12 @@ class SecretKeyFinderTest < ActiveSupport::TestCase assert_equal 'config', secret_key_finder.find end + test "rails 5.2 uses secret_key_base when config is empty" do + secret_key_finder = Devise::SecretKeyFinder.new(Rails52SecretKeyBase.new) + + assert_equal 'secret_key_base', secret_key_finder.find + end + test "rails 4.1 uses secrets" do secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new)