Skip to content

Commit

Permalink
find auto-generated secret_key_base in development (#4869)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gencer authored and tegon committed May 14, 2018
1 parent 246a508 commit 6c91648
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/devise/secret_key_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def find
@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

Expand Down
24 changes: 24 additions & 0 deletions test/secret_key_finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ def config
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')
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6c91648

Please sign in to comment.