Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't load app environment when editing credentials #34789

Merged
merged 1 commit into from Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions railties/lib/rails/command/actions.rb
Expand Up @@ -11,10 +11,20 @@ def set_application_directory!
end

def require_application_and_environment!
require_application!
require_environment!
end

def require_application!
require ENGINE_PATH if defined?(ENGINE_PATH)

if defined?(APP_PATH)
require APP_PATH
end
end

def require_environment!
if defined?(APP_PATH)
Rails.application.require_environment!
end
end
Expand Down
Expand Up @@ -20,7 +20,7 @@ def help
end

def edit
require_application_and_environment!
require_application!

ensure_editor_available(command: "bin/rails credentials:edit") || (return)

Expand All @@ -39,7 +39,7 @@ def edit
end

def show
require_application_and_environment!
require_application!

encrypted = Rails.application.encrypted(content_path, key_path: key_path)

Expand Down
8 changes: 8 additions & 0 deletions railties/test/commands/credentials_test.rb
Expand Up @@ -63,6 +63,14 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
end
end

test "edit command does not raise when an initializer tries to acces non-existent credentials" do
app_file "config/initializers/raise_when_loaded.rb", <<-RUBY
Rails.application.credentials.missing_key!
RUBY

assert_match(/access_key_id: 123/, run_edit_command(environment: "qa"))
end

test "show credentials" do
assert_match(/access_key_id: 123/, run_show_command)
end
Expand Down