From da5cbb99e1cf651981016fdde1af8cee6501fe9b Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Sat, 12 Feb 2022 15:09:37 +0100 Subject: [PATCH] Triageing issue #640 --- .github/workflows/ruby.yml | 2 +- spec/actions/run_remote_command_spec.rb | 41 ++++++++++++++++++- spec/fixtures/movefiles/with_secrets_castilma | 23 +++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/movefiles/with_secrets_castilma diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 6d02b36..2af5119 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -34,4 +34,4 @@ jobs: - name: Install dependencies run : bundle install - name: Run tests - run: bundle exec rake + run: bundle exec rspec spec/actions/run_remote_command_spec.rb:95 diff --git a/spec/actions/run_remote_command_spec.rb b/spec/actions/run_remote_command_spec.rb index 4085248..ff64341 100644 --- a/spec/actions/run_remote_command_spec.rb +++ b/spec/actions/run_remote_command_spec.rb @@ -8,7 +8,6 @@ let(:bad_command) { 'exit 1' } before do - silence_logger! allow(context[:photocopier]) .to receive(:exec!).with(good_command) .and_return([nil, nil, 0]) @@ -18,6 +17,8 @@ end it 'works like it should' do + silence_logger! + result = described_class.execute( photocopier: context.fetch(:photocopier), cli_options: context.fetch(:cli_options), @@ -30,6 +31,8 @@ context 'when it fails' do it 'sets the expected error message into result' do + silence_logger! + result = described_class.execute( photocopier: context.fetch(:photocopier), cli_options: context.fetch(:cli_options), @@ -44,6 +47,8 @@ context 'when `--simulate`' do it 'does not execute the command and result is successful' do + silence_logger! + context[:cli_options][:simulate] = true result = described_class.execute( @@ -56,4 +61,38 @@ expect(result).to be_success end end + + context 'testing @castilma\'s big report' do + let(:command) do + 'mysqldump --host=remote_database_host --user=user ' \ + '--password=R4ndom#+Str1nG ' \ + '--result-file="/var/www/your_site/wp-content/dump.sql" database_name' + end + + let(:context) do + OrganizerContextFactory.make_for( + described_class, + :push, + cli_options: { + config: movefile_path_for('with_secrets_castilma'), + environment: :remote + } + ) + end + + it 'censors the password on STDOUT' do + allow(context[:photocopier]) + .to receive(:exec!).with(command) + .and_return([nil, nil, 0]) + + expect do + described_class.execute( + photocopier: context.fetch(:photocopier), + cli_options: context.fetch(:cli_options), + logger: context.fetch(:logger), + command: command + ) + end.to output(/--password=\[secret\]/).to_stdout_from_any_process + end + end end diff --git a/spec/fixtures/movefiles/with_secrets_castilma b/spec/fixtures/movefiles/with_secrets_castilma new file mode 100644 index 0000000..9cf6ad5 --- /dev/null +++ b/spec/fixtures/movefiles/with_secrets_castilma @@ -0,0 +1,23 @@ +global: + sql_adapter: "wpcli" +local: + wordpress_path: "~/dev/sites/your_site" +remote: + vhost: "http://secrets.example.com" + wordpress_path: "/var/www/your_site" + database: + name: "database_name" + user: "user" + password: "R4ndom#+Str1nG" + host: "remote_database_host" + ssh: + user: "user" + password: "ssh_password" + host: "ssh_host" + port: 30000 + ftp: + user: "user" + password: "ftp_password" + host: "ftp_host" +foo: + vhost: "https://foo.bar"