Feature #9292 ยป add_test_chown_with_root.patch
| test/fileutils/test_fileutils.rb (working copy) | ||
|---|---|---|
|
return true
|
||
|
end
|
||
|
def root_in_posix?
|
||
|
if Process.respond_to?('uid')
|
||
|
return Process.uid == 0
|
||
|
else
|
||
|
return False
|
||
|
end
|
||
|
end
|
||
|
begin
|
||
|
Dir.mkdir("\n")
|
||
|
Dir.rmdir("\n")
|
||
| ... | ... | |
|
Dir.chdir prevdir
|
||
|
Dir.rmdir tmproot
|
||
|
Etc.endpwent
|
||
|
class TestFileUtils
|
||
|
include FileUtils
|
||
| ... | ... | |
|
}
|
||
|
end if have_file_perm?
|
||
|
# FIXME: Need to add test for chown with root account
|
||
|
def test_chown_not_enough_permission
|
||
|
user_1 = Etc.getpwent
|
||
|
user_2 = Etc.getpwent
|
||
|
return unless user_1 and user_2
|
||
|
uid_1 = user_1.uid
|
||
|
uid_2 = user_2.uid
|
||
|
touch 'tmp/a'
|
||
|
exception = assert_raise(Errno::EPERM) {
|
||
|
chown uid_1, nil, 'tmp/a'
|
||
|
chown uid_2, nil, 'tmp/a'
|
||
|
}
|
||
|
end if have_file_perm? and not root_in_posix?
|
||
|
def test_chown_error
|
||
|
user = Etc.getpwent
|
||
|
return unless user
|
||
|
uid = user.uid
|
||
|
touch 'tmp/a'
|
||
|
exception = assert_raise(ArgumentError) {
|
||
|
chown '', @groups[0], 'tmp/a'
|
||
|
}
|
||
|
assert_equal exception.message, "can't find user for "
|
||
|
exception = assert_raise(ArgumentError) {
|
||
|
chown uid, '', 'tmp/a'
|
||
|
}
|
||
|
assert_equal exception.message, "can't find group for "
|
||
|
exception = assert_raise(Errno::ENOENT) {
|
||
|
chown nil, @groups[0], ''
|
||
|
}
|
||
|
assert_equal exception.message,
|
||
|
"No such file or directory @ chown_internal - "
|
||
|
end if have_file_perm?
|
||
|
def test_chown_with_root
|
||
|
user_1 = Etc.getpwent
|
||
|
user_2 = Etc.getpwent
|
||
|
return unless user_1 and user_2
|
||
|
uid_1 = user_1.uid
|
||
|
uid_2 = user_2.uid
|
||
|
gid = @groups[0] # Most of the time, root only has one group
|
||
|
files = ['tmp/a1', 'tmp/a2']
|
||
|
files.each {|file| touch file}
|
||
|
[uid_1, uid_2].each {|uid|
|
||
|
assert_output_lines(["chown #{uid}:#{gid} tmp/a1 tmp/a2"]) {
|
||
|
chown uid, gid, files, verbose: true
|
||
|
files.each {|file|
|
||
|
assert_ownership_group gid, file
|
||
|
assert_ownership_user uid, file
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
end if have_file_perm? and root_in_posix?
|
||
|
# FIXME: How can I test this method?
|
||
|
def test_chown_R
|
||
|
check_singleton :chown_R
|
||
| test/fileutils/fileasserts.rb (working copy) | ||
|---|---|---|
|
Actual: <#{actual}>
|
||
|
EOT
|
||
|
end
|
||
|
def assert_ownership_user(expected, file)
|
||
|
actual = File.stat(file).uid
|
||
|
assert expected == actual, <<EOT
|
||
|
File user ownership of "#{file}" unexpected:
|
||
|
Expected: <#{expected}>
|
||
|
Actual: <#{actual}>
|
||
|
EOT
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||