1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

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 @application.secrets.secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config) elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base @application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end end
end end

View file

@ -32,6 +32,24 @@ class Rails52Config
end end
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 class Rails41Secrets
def secrets def secrets
OpenStruct.new(secret_key_base: 'secrets') OpenStruct.new(secret_key_base: 'secrets')
@ -77,6 +95,12 @@ class SecretKeyFinderTest < ActiveSupport::TestCase
assert_equal 'config', secret_key_finder.find assert_equal 'config', secret_key_finder.find
end 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 test "rails 4.1 uses secrets" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new) secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new)