aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Platto <hinidu@gmail.com>2014-07-16 13:18:39 +0300
committerPavel Platto <hinidu@gmail.com>2014-08-13 09:13:59 +0300
commit64ea24bc17abc3d08025f21dfc4482a577957266 (patch)
treef03fdce04efb97b579fa11021638725bf6e0097b
parent94f3d30306ebe3856dc98b6afc4d29728ec3f3af (diff)
downloadrneovim-64ea24bc17abc3d08025f21dfc4482a577957266.tar.gz
rneovim-64ea24bc17abc3d08025f21dfc4482a577957266.tar.bz2
rneovim-64ea24bc17abc3d08025f21dfc4482a577957266.zip
os_fchown: add unit tests
-rw-r--r--test/unit/os/fs_spec.moon43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/os/fs_spec.moon b/test/unit/os/fs_spec.moon
index 52f587d6f9..e63674e2eb 100644
--- a/test/unit/os/fs_spec.moon
+++ b/test/unit/os/fs_spec.moon
@@ -112,6 +112,12 @@ describe 'fs function', ->
os_setperm = (filename, perm) ->
fs.os_setperm (to_cstr filename), perm
+ os_fchown = (filename, user_id, group_id) ->
+ fd = ffi.C.open filename, 0
+ res = fs.os_fchown fd, user_id, group_id
+ ffi.C.close fd
+ return res
+
os_file_is_readonly = (filename) ->
fs.os_file_is_readonly (to_cstr filename)
@@ -158,6 +164,43 @@ describe 'fs function', ->
perm = ffi.C.kS_IXUSR
eq FAIL, (os_setperm 'non-existing-file', perm)
+ describe 'os_fchown', ->
+ filename = 'unit-test-directory/test.file'
+
+ it 'does not change owner and group if respective IDs are equal to -1', ->
+ uid = lfs.attributes filename, 'uid'
+ gid = lfs.attributes filename, 'gid'
+ eq 0, os_fchown filename, -1, -1
+ eq uid, lfs.attributes filename, 'uid'
+ eq gid, lfs.attributes filename, 'gid'
+
+ it 'owner of a file may change the group of the file
+ to any group of which that owner is a member', ->
+ -- Some systems may not have `id` utility.
+ if (os.execute('id -G &> /dev/null') == 0)
+ file_gid = lfs.attributes filename, 'gid'
+
+ -- Gets ID of any group of which current user is a member except the
+ -- group that owns the file.
+ id_fd = io.popen('id -G')
+ new_gid = id_fd\read '*n'
+ if (new_gid == file_gid)
+ new_gid = id_fd\read '*n'
+ id_fd\close!
+
+ -- User can be a member of only one group (e.g., it is on Travis-CI).
+ -- In that case we can not perform this test.
+ if new_gid
+ eq 0, (os_fchown filename, -1, new_gid)
+ eq new_gid, (lfs.attributes filename, 'gid')
+
+ it 'returns nonzero if process has not enough permissions', ->
+ -- On Windows `os_fchown` always returns 0
+ -- because `uv_fs_chown` is no-op on this platform.
+ if (ffi.os != 'Windows' and ffi.C.geteuid! != 0)
+ -- chown to root
+ neq 0, os_fchown filename, 0, 0
+
describe 'os_file_is_readonly', ->
it 'returns true if the file is readonly', ->
perm = os_getperm 'unit-test-directory/test.file'