File tree 3 files changed +20
-6
lines changed
actionpack/lib/action_dispatch/middleware/session
3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ module Session
27
27
# Rails.application.config.session_store :cookie_store, key: '_your_app_session'
28
28
#
29
29
# In the development and test environments your application's +secret_key_base+ is
30
- # generated by Rails and stored in a temporary file in <tt>tmp/development_secret .txt</tt>.
30
+ # generated by Rails and stored in a temporary file in <tt>tmp/local_secret .txt</tt>.
31
31
# In all other environments, it is stored encrypted in the
32
32
# <tt>config/credentials.yml.enc</tt> file.
33
33
#
Original file line number Diff line number Diff line change @@ -458,7 +458,7 @@ def secrets
458
458
# including the ones that sign and encrypt cookies.
459
459
#
460
460
# In development and test, this is randomly generated and stored in a
461
- # temporary file in <tt>tmp/development_secret .txt</tt>.
461
+ # temporary file in <tt>tmp/local_secret .txt</tt>.
462
462
#
463
463
# You can also set <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt> to trigger the use of a randomly generated
464
464
# secret_key_base that's stored in a temporary file. This is useful when precompiling assets for
@@ -471,7 +471,7 @@ def secrets
471
471
# the correct place to store it is in the encrypted credentials file.
472
472
def secret_key_base
473
473
if Rails . env . local? || ENV [ "SECRET_KEY_BASE_DUMMY" ]
474
- config . secret_key_base ||= generate_development_secret
474
+ config . secret_key_base ||= generate_local_secret
475
475
else
476
476
validate_secret_key_base (
477
477
ENV [ "SECRET_KEY_BASE" ] || credentials . secret_key_base || secrets . secret_key_base
@@ -645,9 +645,9 @@ def ensure_generator_templates_added
645
645
end
646
646
647
647
private
648
- def generate_development_secret
648
+ def generate_local_secret
649
649
if config . secret_key_base . nil?
650
- key_file = Rails . root . join ( "tmp/development_secret .txt" )
650
+ key_file = Rails . root . join ( "tmp/local_secret .txt" )
651
651
652
652
if File . exist? ( key_file )
653
653
config . secret_key_base = File . binread ( key_file )
Original file line number Diff line number Diff line change @@ -733,7 +733,21 @@ def index
733
733
app "development"
734
734
735
735
assert_not_nil app . secret_key_base
736
- assert File . exist? ( app_path ( "tmp/development_secret.txt" ) )
736
+ assert File . exist? ( app_path ( "tmp/local_secret.txt" ) )
737
+ end
738
+
739
+ test "application will generate secret_key_base in tmp file if blank in test" do
740
+ app_file "config/initializers/secret_token.rb" , <<-RUBY
741
+ Rails.application.credentials.secret_key_base = nil
742
+ RUBY
743
+
744
+ # For test that works even if tmp dir does not exist.
745
+ Dir . chdir ( app_path ) { FileUtils . remove_dir ( "tmp" ) }
746
+
747
+ app "test"
748
+
749
+ assert_not_nil app . secret_key_base
750
+ assert File . exist? ( app_path ( "tmp/local_secret.txt" ) )
737
751
end
738
752
739
753
test "application will not generate secret_key_base in tmp file if blank in production" do
You can’t perform that action at this time.
0 commit comments