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

Use the sanitized file path for remote linux files #218

Merged
merged 2 commits into from
Nov 20, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/train/file/remote/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/integration/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/integration/cookbooks/test/recipes/prep_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions test/integration/tests/path_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion test/unit/file/remote/linux_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -164,4 +170,4 @@ def mock_stat(args, out, err = '', code = 0)
f.selinux_label.must_equal 'labels'
end
end
end
end