2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-01 14:40:39 -05:00
|
|
|
require "isolation/abstract_unit"
|
2017-09-03 12:55:26 -04:00
|
|
|
require "env_helpers"
|
2017-03-01 14:40:39 -05:00
|
|
|
require "rails/command"
|
|
|
|
require "rails/commands/secrets/secrets_command"
|
|
|
|
|
|
|
|
class Rails::Command::SecretsCommandTest < ActiveSupport::TestCase
|
2017-09-03 12:55:26 -04:00
|
|
|
include ActiveSupport::Testing::Isolation, EnvHelpers
|
2017-03-01 14:40:39 -05:00
|
|
|
|
2017-11-12 11:32:52 -05:00
|
|
|
setup :build_app
|
|
|
|
teardown :teardown_app
|
|
|
|
|
|
|
|
test "edit without editor gives hint" do
|
|
|
|
assert_match "No $EDITOR to open decrypted secrets in", run_edit_command(editor: "")
|
2017-03-01 14:40:39 -05:00
|
|
|
end
|
|
|
|
|
2017-11-12 11:32:52 -05:00
|
|
|
test "encrypted secrets are deprecated when using credentials" do
|
|
|
|
assert_match "Encrypted secrets is deprecated", run_setup_command
|
|
|
|
assert_equal 1, $?.exitstatus
|
|
|
|
assert_not File.exist?("config/secrets.yml.enc")
|
2017-03-01 14:40:39 -05:00
|
|
|
end
|
|
|
|
|
2017-11-12 11:32:52 -05:00
|
|
|
test "encrypted secrets are deprecated when running edit without setup" do
|
|
|
|
assert_match "Encrypted secrets is deprecated", run_setup_command
|
|
|
|
assert_equal 1, $?.exitstatus
|
|
|
|
assert_not File.exist?("config/secrets.yml.enc")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "encrypted secrets are deprecated for 5.1 config/secrets.yml apps" do
|
|
|
|
Dir.chdir(app_path) do
|
|
|
|
FileUtils.rm("config/credentials.yml.enc")
|
|
|
|
FileUtils.touch("config/secrets.yml")
|
|
|
|
|
|
|
|
assert_match "Encrypted secrets is deprecated", run_setup_command
|
|
|
|
assert_equal 1, $?.exitstatus
|
|
|
|
assert_not File.exist?("config/secrets.yml.enc")
|
|
|
|
end
|
2017-03-01 14:40:39 -05:00
|
|
|
end
|
|
|
|
|
2017-03-09 19:21:53 -05:00
|
|
|
test "edit secrets" do
|
2017-11-12 11:32:52 -05:00
|
|
|
prevent_deprecation
|
2017-03-09 19:21:53 -05:00
|
|
|
|
|
|
|
# Run twice to ensure encrypted secrets can be reread after first edit pass.
|
|
|
|
2.times do
|
2017-05-24 14:43:01 -04:00
|
|
|
assert_match(/external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289/, run_edit_command)
|
2017-03-09 19:21:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-06 08:40:33 -04:00
|
|
|
test "show secrets" do
|
2017-11-12 11:32:52 -05:00
|
|
|
prevent_deprecation
|
|
|
|
|
2017-07-06 08:40:33 -04:00
|
|
|
assert_match(/external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289/, run_show_command)
|
|
|
|
end
|
|
|
|
|
2017-03-01 14:40:39 -05:00
|
|
|
private
|
2017-11-12 11:32:52 -05:00
|
|
|
def prevent_deprecation
|
|
|
|
Dir.chdir(app_path) do
|
|
|
|
File.write("config/secrets.yml.key", "f731758c639da2604dfb6bf3d1025de8")
|
|
|
|
File.write("config/secrets.yml.enc", "sEB0mHxDbeP1/KdnMk00wyzPFACl9K6t0cZWn5/Mfx/YbTHvnI07vrneqHg9kaH3wOS7L6pIQteu1P077OtE4BSx/ZRc/sgQPHyWu/tXsrfHqnPNpayOF/XZqizE91JacSFItNMWpuPsp9ynbzz+7cGhoB1S4aPNIU6u0doMrzdngDbijsaAFJmsHIQh6t/QHoJx--8aMoE0PvUWmw1Iqz--ldFqnM/K0g9k17M8PKoN/Q==")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-01 14:40:39 -05:00
|
|
|
def run_edit_command(editor: "cat")
|
2017-09-03 12:55:26 -04:00
|
|
|
switch_env("EDITOR", editor) do
|
2017-11-12 11:32:52 -05:00
|
|
|
rails "secrets:edit", allow_failure: true
|
2017-09-03 12:55:26 -04:00
|
|
|
end
|
2017-03-01 14:40:39 -05:00
|
|
|
end
|
2017-07-06 08:40:33 -04:00
|
|
|
|
|
|
|
def run_show_command
|
2017-11-12 11:32:52 -05:00
|
|
|
rails "secrets:show", allow_failure: true
|
2017-07-06 08:40:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_setup_command
|
2017-11-12 11:32:52 -05:00
|
|
|
rails "secrets:setup", allow_failure: true
|
2017-07-06 08:40:33 -04:00
|
|
|
end
|
2017-03-01 14:40:39 -05:00
|
|
|
end
|