diff --git a/.travis.yml b/.travis.yml index 870debcb..d8185e5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ before_install: branches: only: - master + - release-0.29.2 matrix: include: diff --git a/appveyor.yml b/appveyor.yml index 433fcfc8..759d888e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,6 @@ platform: environment: winrm_user: test_user winrm_pass: Pass@word1 - bundler_url: https://rubygems.org/downloads/bundler-1.9.9.gem matrix: - ruby_version: "22" @@ -25,6 +24,7 @@ clone_depth: 1 branches: only: - master + - release-0.29.2 cache: - vendor/bundle -> appveyor.yml @@ -40,8 +40,6 @@ install: - ps: Write-Host $env:PATH - ruby --version - gem --version - - appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem - - gem install --local bundler --quiet --no-document - bundler --version - ruby -r rubygems -e "p Gem.path" diff --git a/lib/train/file/local/unix.rb b/lib/train/file/local/unix.rb index 0fe36ba4..6730a039 100644 --- a/lib/train/file/local/unix.rb +++ b/lib/train/file/local/unix.rb @@ -54,6 +54,16 @@ def grouped_into?(sth) group == sth end + def unix_mode_mask(owner, type) + o = UNIX_MODE_OWNERS[owner.to_sym] + return nil if o.nil? + + t = UNIX_MODE_TYPES[type.to_sym] + return nil if t.nil? + + t & o + end + private def pw_username(uid) @@ -67,6 +77,19 @@ def pw_groupname(gid) rescue ArgumentError => _ nil end + + UNIX_MODE_OWNERS = { + all: 00777, + owner: 00700, + group: 00070, + other: 00007, + }.freeze + + UNIX_MODE_TYPES = { + r: 00444, + w: 00222, + x: 00111, + }.freeze end end end 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/local/unix_test.rb b/test/unit/file/local/unix_test.rb index e4940856..65dbb2c3 100644 --- a/test/unit/file/local/unix_test.rb +++ b/test/unit/file/local/unix_test.rb @@ -5,7 +5,7 @@ describe Train::File::Local::Unix do let(:cls) { Train::File::Local::Unix } - + let(:backend) { backend = Train::Transports::Mock.new.connection backend.mock_os({ family: 'linux' }) @@ -86,8 +86,8 @@ def meta_stub(method, param, &block) it 'grouped_into' do meta_stub :stat, statres do connection.file(rand.to_s).grouped_into?('group').must_equal true - end - end + end + end it 'recognizes selinux label' do meta_stub :stat, statres do @@ -109,4 +109,38 @@ def meta_stub(method, param, &block) end end end + + describe '#unix_mode_mask' do + let(:file_tester) do + Class.new(cls) do + define_method :type do + :file + end + end.new(nil, nil, false) + end + + it 'check owner mode calculation' do + file_tester.unix_mode_mask('owner', 'x').must_equal 0100 + file_tester.unix_mode_mask('owner', 'w').must_equal 0200 + file_tester.unix_mode_mask('owner', 'r').must_equal 0400 + end + + it 'check group mode calculation' do + file_tester.unix_mode_mask('group', 'x').must_equal 0010 + file_tester.unix_mode_mask('group', 'w').must_equal 0020 + file_tester.unix_mode_mask('group', 'r').must_equal 0040 + end + + it 'check other mode calculation' do + file_tester.unix_mode_mask('other', 'x').must_equal 0001 + file_tester.unix_mode_mask('other', 'w').must_equal 0002 + file_tester.unix_mode_mask('other', 'r').must_equal 0004 + end + + it 'check all mode calculation' do + file_tester.unix_mode_mask('all', 'x').must_equal 0111 + file_tester.unix_mode_mask('all', 'w').must_equal 0222 + file_tester.unix_mode_mask('all', 'r').must_equal 0444 + end + end end \ No newline at end of file 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