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

Fix regressions in 0.29.1 #219

Merged
merged 4 commits into from
Nov 21, 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ before_install:
branches:
only:
- master
- release-0.29.2

matrix:
include:
Expand Down
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,6 +24,7 @@ clone_depth: 1
branches:
only:
- master
- release-0.29.2

cache:
- vendor/bundle -> appveyor.yml
Expand All @@ -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"

Expand Down
23 changes: 23 additions & 0 deletions lib/train/file/local/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
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
40 changes: 37 additions & 3 deletions test/unit/file/local/unix_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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
Expand All @@ -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
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