aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2019-01-14 21:03:53 +0100
committerGitHub <noreply@github.com>2019-01-14 21:03:53 +0100
commit54d4a518d9a8079c9bc03bee454e966e93036942 (patch)
treeac44003e7cf1b3cb3fdcb3f648d32172bb2cbb8f /railties/test
parent2585e66b551a8b368425aad062e5f325985ab482 (diff)
parent37c948ce6715df8ecbcda2b64a1e6eee9c5d6bb6 (diff)
downloadrails-54d4a518d9a8079c9bc03bee454e966e93036942.tar.gz
rails-54d4a518d9a8079c9bc03bee454e966e93036942.tar.bz2
rails-54d4a518d9a8079c9bc03bee454e966e93036942.zip
Merge pull request #33962 from kaspth/restructure-environment-credentials
Restructure credentials after environment overrides.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/credentials_test.rb56
-rw-r--r--railties/test/application/multiple_applications_test.rb4
-rw-r--r--railties/test/credentials_test.rb65
3 files changed, 58 insertions, 67 deletions
diff --git a/railties/test/application/credentials_test.rb b/railties/test/application/credentials_test.rb
new file mode 100644
index 0000000000..2f6b109b50
--- /dev/null
+++ b/railties/test/application/credentials_test.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require "isolation/abstract_unit"
+require "env_helpers"
+
+class Rails::CredentialsTest < ActiveSupport::TestCase
+ include ActiveSupport::Testing::Isolation, EnvHelpers
+
+ setup :build_app
+ teardown :teardown_app
+
+ test "reads credentials from environment specific path" do
+ write_credentials_override(:production)
+
+ app("production")
+
+ assert_equal "revealed", Rails.application.credentials.mystery
+ end
+
+ test "reads credentials from customized path and key" do
+ write_credentials_override(:staging)
+ add_to_env_config("production", "config.credentials.content_path = config.root.join('config/credentials/staging.yml.enc')")
+ add_to_env_config("production", "config.credentials.key_path = config.root.join('config/credentials/staging.key')")
+
+ app("production")
+
+ assert_equal "revealed", Rails.application.credentials.mystery
+ end
+
+ test "reads credentials using environment variable key" do
+ write_credentials_override(:production, with_key: false)
+
+ switch_env("RAILS_MASTER_KEY", credentials_key) do
+ app("production")
+
+ assert_equal "revealed", Rails.application.credentials.mystery
+ end
+ end
+
+ private
+ def write_credentials_override(name, with_key: true)
+ Dir.chdir(app_path) do
+ Dir.mkdir "config/credentials"
+ File.write "config/credentials/#{name}.key", credentials_key if with_key
+
+ # secret_key_base: secret
+ # mystery: revealed
+ File.write "config/credentials/#{name}.yml.enc",
+ "vgvKu4MBepIgZ5VHQMMPwnQNsLlWD9LKmJHu3UA/8yj6x+3fNhz3DwL9brX7UA==--qLdxHP6e34xeTAiI--nrcAsleXuo9NqiEuhntAhw=="
+ end
+ end
+
+ def credentials_key
+ "2117e775dc2024d4f49ddf3aeb585919"
+ end
+end
diff --git a/railties/test/application/multiple_applications_test.rb b/railties/test/application/multiple_applications_test.rb
index d6c81c1fe2..432344bccc 100644
--- a/railties/test/application/multiple_applications_test.rb
+++ b/railties/test/application/multiple_applications_test.rb
@@ -165,12 +165,12 @@ module ApplicationTests
app.config.some_setting = "a_different_setting"
assert_equal "a_different_setting", app.config.some_setting, "The configuration's some_setting should be set."
- new_config = Rails::Application::Configuration.new("root_of_application")
+ new_config = Rails::Application::Configuration.new(Pathname.new("root_of_application"))
new_config.some_setting = "some_setting_dude"
app.config = new_config
assert_equal "some_setting_dude", app.config.some_setting, "The configuration's some_setting should have changed."
- assert_equal "root_of_application", app.config.root, "The root should have changed to the new config's root."
+ assert_equal "root_of_application", app.config.root.to_s, "The root should have changed to the new config's root."
assert_equal new_config, app.config, "The application's config should have changed to the new config."
end
end
diff --git a/railties/test/credentials_test.rb b/railties/test/credentials_test.rb
deleted file mode 100644
index 11765b0de5..0000000000
--- a/railties/test/credentials_test.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-# frozen_string_literal: true
-
-require "isolation/abstract_unit"
-require "env_helpers"
-
-class Rails::CredentialsTest < ActiveSupport::TestCase
- include ActiveSupport::Testing::Isolation, EnvHelpers
-
- setup :build_app
- teardown :teardown_app
-
- test "reads credentials from environment specific path" do
- with_credentials do |content, key|
- Dir.chdir(app_path) do
- Dir.mkdir("config/credentials")
- File.write("config/credentials/production.yml.enc", content)
- File.write("config/credentials/production.key", key)
- end
-
- app("production")
-
- assert_equal "revealed", Rails.application.credentials.mystery
- end
- end
-
- test "reads credentials from customized path and key" do
- with_credentials do |content, key|
- Dir.chdir(app_path) do
- Dir.mkdir("config/credentials")
- File.write("config/credentials/staging.yml.enc", content)
- File.write("config/credentials/staging.key", key)
- end
-
- add_to_env_config("production", "config.credentials.content_path = config.root.join('config/credentials/staging.yml.enc')")
- add_to_env_config("production", "config.credentials.key_path = config.root.join('config/credentials/staging.key')")
- app("production")
-
- assert_equal "revealed", Rails.application.credentials.mystery
- end
- end
-
- test "reads credentials using environment variable key" do
- with_credentials do |content, key|
- Dir.chdir(app_path) do
- Dir.mkdir("config/credentials")
- File.write("config/credentials/production.yml.enc", content)
- end
-
- switch_env("RAILS_MASTER_KEY", key) do
- app("production")
-
- assert_equal "revealed", Rails.application.credentials.mystery
- end
- end
- end
-
- private
- def with_credentials
- key = "2117e775dc2024d4f49ddf3aeb585919"
- # secret_key_base: secret
- # mystery: revealed
- content = "vgvKu4MBepIgZ5VHQMMPwnQNsLlWD9LKmJHu3UA/8yj6x+3fNhz3DwL9brX7UA==--qLdxHP6e34xeTAiI--nrcAsleXuo9NqiEuhntAhw=="
- yield(content, key)
- end
-end