1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't load app environment when running encrypted commands

This extends the fix made by a39aa99c81 to the EncryptedCommand class
which suffers from the exact same issue.
This commit is contained in:
Paul Mannino 2020-05-11 18:29:02 -05:00
parent dd2acd5ec6
commit 4e8650f8b1
2 changed files with 12 additions and 2 deletions

View file

@ -21,7 +21,7 @@ module Rails
end
def edit(file_path)
require_application_and_environment!
require_application!
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
ensure_editor_available(command: "bin/rails encrypted:edit") || (return)
@ -38,7 +38,7 @@ module Rails
end
def show(file_path)
require_application_and_environment!
require_application!
encrypted = Rails.application.encrypted(file_path, key_path: options[:key])
say encrypted.read.presence || missing_encrypted_message(key: encrypted.key, key_path: options[:key], file_path: file_path)

View file

@ -87,6 +87,16 @@ class Rails::Command::EncryptedCommandTest < ActiveSupport::TestCase
assert_match(/access_key_id: 123/, run_show_command("config/tokens.yml.enc", key: "config/tokens.key"))
end
test "show command does not raise when an initializer tries to access non-existent credentials" do
app_file "config/initializers/raise_when_loaded.rb", <<-RUBY
Rails.application.credentials.missing_key!
RUBY
run_edit_command("config/tokens.yml.enc", key: "config/tokens.key")
assert_match(/access_key_id: 123/, run_show_command("config/tokens.yml.enc", key: "config/tokens.key"))
end
private
def run_edit_command(file, key: nil, editor: "cat", **options)
switch_env("EDITOR", editor) do