From 3eaa29840b92813f37adcc41d3d8c08d976480a4 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 10 Dec 2013 10:04:07 -0500 Subject: Load secret_key_base from tokens.yml, fallback to config.secret_key_base --- railties/test/application/configuration_test.rb | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'railties/test/application') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index b3fbceb0dc..1f3127b069 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -250,7 +250,7 @@ module ApplicationTests test "Use key_generator when secret_key_base is set" do make_basic_app do |app| - app.config.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' + app.secrets.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' app.config.session_store :disabled end @@ -270,7 +270,7 @@ module ApplicationTests test "application verifier can be used in the entire application" do make_basic_app do |app| - app.config.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' + app.secrets.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' app.config.session_store :disabled end @@ -285,7 +285,7 @@ module ApplicationTests test "application verifier can build different verifiers" do make_basic_app do |app| - app.config.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' + app.secrets.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33' app.config.session_store :disabled end @@ -303,6 +303,26 @@ module ApplicationTests assert_not_equal default_verifier.object_id, text_verifier.object_id end + test "secrets.secret_key_base is used when config/tokens.yml is present" do + app_file 'config/tokens.yml', <<-YAML + development: + secret_key_base: 3b7cd727ee24e8444053437c36cc66c3 + YAML + + require "#{app_path}/config/environment" + assert_equal '3b7cd727ee24e8444053437c36cc66c3', app.secrets.secret_key_base + end + + test "secret_key_base is copied from config to secrets when not set" do + remove_file "config/tokens.yml" + app_file 'config/initializers/secret_token.rb', <<-RUBY + Rails.application.config.secret_key_base = "3b7cd727ee24e8444053437c36cc66c3" + RUBY + + require "#{app_path}/config/environment" + assert_equal '3b7cd727ee24e8444053437c36cc66c3', app.secrets.secret_key_base + end + test "protect from forgery is the default in a new app" do make_basic_app -- cgit v1.2.3 From 404314779263e120ce0da5ae62f09c19114476d7 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 12 Dec 2013 11:07:31 -0500 Subject: Replace config.secret_key_base with secrets.secret_key_base in test --- railties/test/application/middleware/session_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test/application') diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index 14a56176f5..31a64c2f5a 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -318,7 +318,7 @@ module ApplicationTests add_to_config <<-RUBY config.secret_token = "3b7cd727ee24e8444053437c36cc66c4" - config.secret_key_base = nil + secrets.secret_key_base = nil RUBY require "#{app_path}/config/environment" -- cgit v1.2.3 From 39fd0be7660e2f666328af85c705c3df5a8ac09e Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 12 Dec 2013 11:39:15 -0500 Subject: Add test for custom tokens stored in config/tokens.yml --- railties/test/application/configuration_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 1f3127b069..6554e0e08a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -323,6 +323,19 @@ module ApplicationTests assert_equal '3b7cd727ee24e8444053437c36cc66c3', app.secrets.secret_key_base end + test "custom secrets saved in config/tokens.yml are loaded in app secrets" do + app_file 'config/tokens.yml', <<-YAML + development: + secret_key_base: 3b7cd727ee24e8444053437c36cc66c3 + aws_access_key_id: myamazonaccesskeyid + aws_secret_access_key: myamazonsecretaccesskey + YAML + + require "#{app_path}/config/environment" + assert_equal 'myamazonaccesskeyid', app.secrets.aws_access_key_id + assert_equal 'myamazonsecretaccesskey', app.secrets.aws_secret_access_key + end + test "protect from forgery is the default in a new app" do make_basic_app -- cgit v1.2.3 From bb7537bc872e0a724fa97468e5899de0c70c1fc1 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Thu, 12 Dec 2013 14:58:53 -0500 Subject: Rename tokens.yml to secrets.yml --- railties/test/application/configuration_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test/application') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6554e0e08a..e024ec8cef 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -304,7 +304,7 @@ module ApplicationTests end test "secrets.secret_key_base is used when config/tokens.yml is present" do - app_file 'config/tokens.yml', <<-YAML + app_file 'config/secrets.yml', <<-YAML development: secret_key_base: 3b7cd727ee24e8444053437c36cc66c3 YAML @@ -314,7 +314,7 @@ module ApplicationTests end test "secret_key_base is copied from config to secrets when not set" do - remove_file "config/tokens.yml" + remove_file "config/secrets.yml" app_file 'config/initializers/secret_token.rb', <<-RUBY Rails.application.config.secret_key_base = "3b7cd727ee24e8444053437c36cc66c3" RUBY @@ -324,7 +324,7 @@ module ApplicationTests end test "custom secrets saved in config/tokens.yml are loaded in app secrets" do - app_file 'config/tokens.yml', <<-YAML + app_file 'config/secrets.yml', <<-YAML development: secret_key_base: 3b7cd727ee24e8444053437c36cc66c3 aws_access_key_id: myamazonaccesskeyid -- cgit v1.2.3