system_command: automatically find secrets from ENV
This commit is contained in:
parent
66697d4290
commit
1d957c2029
@ -56,6 +56,7 @@ class SystemCommand
|
||||
def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false,
|
||||
print_stdout: false, print_stderr: true, verbose: false, secrets: [], **options)
|
||||
|
||||
require "extend/ENV"
|
||||
@executable = executable
|
||||
@args = args
|
||||
@sudo = sudo
|
||||
@ -63,7 +64,7 @@ class SystemCommand
|
||||
@print_stdout = print_stdout
|
||||
@print_stderr = print_stderr
|
||||
@verbose = verbose
|
||||
@secrets = Array(secrets)
|
||||
@secrets = (Array(secrets) + ENV.sensitive_environment.values).uniq
|
||||
@must_succeed = must_succeed
|
||||
options.assert_valid_keys!(:chdir)
|
||||
@options = options
|
||||
|
@ -263,6 +263,20 @@ describe SystemCommand do
|
||||
secrets: %w[hunter2]
|
||||
end.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stdout
|
||||
end
|
||||
|
||||
it "does not leak the secrets set by environment" do
|
||||
redacted_msg = /#{Regexp.escape("username:******")}/
|
||||
expect do
|
||||
begin
|
||||
ENV["PASSWORD"] = "hunter2"
|
||||
described_class.run! "curl",
|
||||
args: %w[--user username:hunter2],
|
||||
verbose: true
|
||||
ensure
|
||||
ENV.delete "PASSWORD"
|
||||
end
|
||||
end.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stdout
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user