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 gid of user nobody for tests #25

Merged
merged 1 commit into from
Nov 15, 2015
Merged
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
63 changes: 32 additions & 31 deletions tests/test_bindfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def chown(user, group, list)

# Some useful shorthands
$nobody_uid = nobody_uid = Etc.getpwnam('nobody').uid
$nogroup_gid = nogroup_gid = Etc.getgrnam('nogroup').gid
$nobody_gid = nobody_gid = Etc.getpwnam('nobody').gid
$nobody_group = nobody_group = Etc.getgrgid(nobody_gid).name

$tests_dir = File.dirname(File.realpath(__FILE__))

Expand All @@ -45,11 +46,11 @@ def chown(user, group, list)
assert { File.basename(pwd) == TESTDIR_NAME }
end

testenv("-u nobody -g nogroup") do
testenv("-u nobody -g #{nobody_group}") do
touch('src/file')

assert { File.stat('mnt/file').uid == nobody_uid }
assert { File.stat('mnt/file').gid == nogroup_gid }
assert { File.stat('mnt/file').gid == nobody_gid }
end

testenv("-p 0600:u+D") do
Expand All @@ -73,24 +74,24 @@ def chown(user, group, list)

root_testenv("", :title => "--create-as-user should be default for root") do
chmod(0777, 'src')
`sudo -u nobody -g nogroup touch mnt/file`
`sudo -u nobody -g nogroup mkdir mnt/dir`
`sudo -u nobody -g nogroup ln -sf /tmp/foo mnt/lnk`
`sudo -u nobody -g #{nobody_group} touch mnt/file`
`sudo -u nobody -g #{nobody_group} mkdir mnt/dir`
`sudo -u nobody -g #{nobody_group} ln -sf /tmp/foo mnt/lnk`

assert { File.stat('mnt/file').uid == nobody_uid }
assert { File.stat('mnt/file').gid == nogroup_gid }
assert { File.stat('mnt/file').gid == nobody_gid }
assert { File.stat('src/file').uid == nobody_uid }
assert { File.stat('src/file').gid == nogroup_gid }
assert { File.stat('src/file').gid == nobody_gid }

assert { File.stat('mnt/dir').uid == nobody_uid }
assert { File.stat('mnt/dir').gid == nogroup_gid }
assert { File.stat('mnt/dir').gid == nobody_gid }
assert { File.stat('src/dir').uid == nobody_uid }
assert { File.stat('src/dir').gid == nogroup_gid }
assert { File.stat('src/dir').gid == nobody_gid }

assert { File.lstat('mnt/lnk').uid == nobody_uid }
assert { File.lstat('mnt/lnk').gid == nogroup_gid }
assert { File.lstat('mnt/lnk').gid == nobody_gid }
assert { File.lstat('src/lnk').uid == nobody_uid }
assert { File.lstat('src/lnk').gid == nogroup_gid }
assert { File.lstat('src/lnk').gid == nobody_gid }
end

testenv("--create-with-perms=og=r:ogd+x") do
Expand Down Expand Up @@ -168,8 +169,8 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
mntfile = 'mnt/file'
tests = [
lambda { chown('nobody', nil, mntfile) },
lambda { chown(nil, 'nogroup', mntfile) },
lambda { chown('nobody', 'nogroup', mntfile) }
lambda { chown(nil, nobody_group, mntfile) },
lambda { chown('nobody', nobody_group, mntfile) }
]

for testcase, expect in tests.zip expectations
Expand All @@ -185,16 +186,16 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
case expect
when :uid
assert { uid == $nobody_uid }
assert { gid != $nogroup_gid }
assert { gid != $nobody_gid }
when :gid
assert { uid != $nobody_uid }
assert { gid == $nogroup_gid }
assert { gid == $nobody_gid }
when :both
assert { uid == $nobody_uid }
assert { gid == $nogroup_gid }
assert { gid == $nobody_gid }
when nil
assert { uid != $nobody_uid }
assert { gid != $nogroup_gid }
assert { gid != $nobody_gid }
end
end
end
Expand All @@ -211,16 +212,16 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
touch('src/file')

assert_exception(EPERM) { chown('nobody', nil, 'mnt/file') }
assert_exception(EPERM) { chown('nobody', 'nogroup', 'mnt/file') }
chown(nil, 'nogroup', 'mnt/file')
assert_exception(EPERM) { chown('nobody', nobody_group, 'mnt/file') }
chown(nil, nobody_group, 'mnt/file')
end

root_testenv("--mirror=root") do
touch('src/file')
chown('nobody', 'nogroup', 'src/file')
chown('nobody', nobody_group, 'src/file')

assert { File.stat('mnt/file').uid == 0 }
assert { File.stat('mnt/file').gid == $nogroup_gid }
assert { File.stat('mnt/file').gid == $nobody_gid }
end

testenv("--chmod-allow-x --chmod-ignore") do
Expand Down Expand Up @@ -265,9 +266,9 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
assert { File.stat('src/file').mode & 0777 == 0640 }
end

root_testenv("--map=nobody/root:@nogroup/@root") do
root_testenv("--map=nobody/root:@nobody/@root") do
touch('src/file')
chown('nobody', 'nogroup', 'src/file')
chown('nobody', nobody_group, 'src/file')

assert { File.stat('mnt/file').uid == 0 }
assert { File.stat('mnt/file').gid == 0 }
Expand All @@ -276,19 +277,19 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
mkdir('mnt/newdir')

assert { File.stat('src/newfile').uid == $nobody_uid }
assert { File.stat('src/newfile').gid == $nogroup_gid }
assert { File.stat('src/newfile').gid == $nobody_gid }
assert { File.stat('src/newdir').uid == $nobody_uid }
assert { File.stat('src/newdir').gid == $nogroup_gid }
assert { File.stat('src/newdir').gid == $nobody_gid }

assert { File.stat('mnt/newfile').uid == 0 }
assert { File.stat('mnt/newfile').gid == 0 }
assert { File.stat('mnt/newdir').uid == 0 }
assert { File.stat('mnt/newdir').gid == 0 }
end

root_testenv("--map=@nogroup/@root") do
root_testenv("--map=@nobody/@root") do
touch('src/file')
chown('nobody', 'nogroup', 'src/file')
chown('nobody', nobody_group, 'src/file')

assert { File.stat('mnt/file').gid == 0 }
end
Expand Down Expand Up @@ -360,14 +361,14 @@ def run_chown_chgrp_test_case(chown_flag, chgrp_flag, expectations)
root_testenv("", :title => "setgid directories") do
mkdir('mnt/dir')
chmod("g+s", 'mnt/dir')
chown(nil, $nogroup_gid, 'mnt/dir')
chown(nil, $nobody_gid, 'mnt/dir')

touch('mnt/dir/file')

assert { File.stat('src/dir').mode & 07000 == 02000 }
assert { File.stat('src/dir/file').gid == $nogroup_gid }
assert { File.stat('src/dir/file').gid == $nobody_gid }
assert { File.stat('mnt/dir').mode & 07000 == 02000 }
assert { File.stat('mnt/dir/file').gid == $nogroup_gid }
assert { File.stat('mnt/dir/file').gid == $nobody_gid }
end

testenv("", :title => "utimens on symlinks") do
Expand Down