diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..1418a82 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--format doc --order random --color --fail-fast diff --git a/lib/vagrant-aws/action/sync_folders.rb b/lib/vagrant-aws/action/sync_folders.rb index f5d4656..9c53b23 100644 --- a/lib/vagrant-aws/action/sync_folders.rb +++ b/lib/vagrant-aws/action/sync_folders.rb @@ -86,7 +86,7 @@ module VagrantPlugins "rsync", "--verbose", "--archive", "-z", *excludes.map{|e|['--exclude', e]}.flatten, "-e", "ssh -p #{ssh_info[:port]} #{ssh_key_options(ssh_info)} " + - ssh_options.map { |ssh_option| "-o '#{ssh_option}' " }.join, + ssh_options_to_args(ssh_options).join(' '), hostpath, "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"] @@ -106,6 +106,18 @@ module VagrantPlugins end end + # Generate a ssh(1) command line list of options + # + # @param [Array] options An array of ssh options. E.g. + # `StrictHostKeyChecking=no` see ssh_config(5) for more + # @return [Array] Computed list of command line arguments + def ssh_options_to_args(options) + # Bail early if we get something that is not an array of options + return [] unless options + + return options.map { |o| "-o '#{o}'" } + end + private def ssh_key_options(ssh_info) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ + diff --git a/spec/vagrant-aws/actions/syncfolders_spec.rb b/spec/vagrant-aws/actions/syncfolders_spec.rb new file mode 100644 index 0000000..c80c52a --- /dev/null +++ b/spec/vagrant-aws/actions/syncfolders_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'vagrant-aws/action/sync_folders' + +describe VagrantPlugins::AWS::Action::SyncFolders do + let(:app) { nil } + let(:env) { {} } + subject(:action) { described_class.new(app, env) } + + describe '#ssh_options_to_args' do + subject(:args) { action.ssh_options_to_args(options) } + + context 'with no ssh options' do + let(:options) { [] } + + it { should eql [] } + end + + context 'with one option' do + let(:options) { ['StrictHostKeyChecking=no'] } + it { should eql ["-o 'StrictHostKeyChecking=no'"] } + end + + context 'with multiple options' do + let(:options) { ['SHKC=no', 'Port=222'] } + it { should eql ["-o 'SHKC=no'", "-o 'Port=222'"] } + end + end +end