From 7c1121f36ee2f8a2302dd4a129dde5da81f09af3 Mon Sep 17 00:00:00 2001 From: Jonathan Hartman Date: Mon, 20 Nov 2017 13:30:07 -0800 Subject: [PATCH] Use the sanitized file path for remote linux files (#218) Had a test start failing recently and tracked it down to remote linux file resources no longer handling spaces in paths as of the refactor in 0.29.0. The test passes again after applying this change. Signed-off-by: Jonathan Hartman --- lib/train/file/remote/linux.rb | 2 +- test/integration/bootstrap.sh | 2 ++ test/integration/cookbooks/test/recipes/prep_files.rb | 4 ++++ test/integration/tests/path_file_test.rb | 7 +++++++ test/unit/file/remote/linux_test.rb | 8 +++++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/train/file/remote/linux.rb b/lib/train/file/remote/linux.rb index dc93de4e..2cf64cd4 100644 --- a/lib/train/file/remote/linux.rb +++ b/lib/train/file/remote/linux.rb @@ -8,7 +8,7 @@ class Remote class Linux < Train::File::Remote::Unix def content return @content if defined?(@content) - @content = @backend.run_command("cat #{@path} || echo -n").stdout + @content = @backend.run_command("cat #{@spath} || echo -n").stdout return @content unless @content.empty? @content = nil if directory? or size.nil? or size > 0 @content diff --git a/test/integration/bootstrap.sh b/test/integration/bootstrap.sh index dfcf7f5d..1fdfaeea 100644 --- a/test/integration/bootstrap.sh +++ b/test/integration/bootstrap.sh @@ -12,6 +12,8 @@ chmod 0765 /tmp/file echo -n 'hello suid/sgid/sticky' > /tmp/sfile chmod 7765 /tmp/sfile +echo -n 'hello space' > /tmp/spaced\ file + test ! -e /tmp/pipe && \ mkfifo /tmp/pipe diff --git a/test/integration/cookbooks/test/recipes/prep_files.rb b/test/integration/cookbooks/test/recipes/prep_files.rb index ca4a9a1d..69298917 100644 --- a/test/integration/cookbooks/test/recipes/prep_files.rb +++ b/test/integration/cookbooks/test/recipes/prep_files.rb @@ -21,6 +21,10 @@ content 'hello suid/sgid/sticky' end +file '/tmp/spaced file' do + content 'hello space' +end + directory '/tmp/folder' do mode '0567' owner 'root' diff --git a/test/integration/tests/path_file_test.rb b/test/integration/tests/path_file_test.rb index c4b9ca69..8a578f3e 100644 --- a/test/integration/tests/path_file_test.rb +++ b/test/integration/tests/path_file_test.rb @@ -89,4 +89,11 @@ file.mode.must_equal(07765) end end + + describe 'regular file' do + let(:file) { backend.file('/tmp/spaced file') } + it 'has content' do + file.content.must_equal('hello space') + end + end end diff --git a/test/unit/file/remote/linux_test.rb b/test/unit/file/remote/linux_test.rb index 28993ce4..c574ca75 100644 --- a/test/unit/file/remote/linux_test.rb +++ b/test/unit/file/remote/linux_test.rb @@ -42,6 +42,12 @@ def mock_stat(args, out, err = '', code = 0) cls.new(backend, 'path').content.must_be_nil end + it 'reads file contents' do + out = rand.to_s + backend.mock_command('cat /spaced\\ path || echo -n', out) + cls.new(backend, '/spaced path').content.must_equal out + end + it 'checks for file existance' do backend.mock_command('test -e path', true) cls.new(backend, 'path').exist?.must_equal true @@ -164,4 +170,4 @@ def mock_stat(args, out, err = '', code = 0) f.selinux_label.must_equal 'labels' end end -end \ No newline at end of file +end