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.
This commit is contained in:
Gencer W. Genç 2018-05-15 00:09:25 +03:00 committed by Leonardo Tegon
parent 246a50876a
commit 6c916488af
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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)