adjust setattr expectations when run as root

Summary: Rather than EPERM we get EACCESS when running as root

Reviewed By: chadaustin

Differential Revision: D6853303

fbshipit-source-id: c6743c8d036a24255d2d31c560034c972a0253c7
This commit is contained in:
Wez Furlong 2018-01-30 21:40:56 -08:00 committed by Facebook Github Bot
parent f82026e4fb
commit 7ab70a5493

View File

@ -39,24 +39,25 @@ class SetAttrTest:
filename = os.path.join(self.mount, 'hello')
# Chown should fail with EPERM unless we are setting it
# to the same current ownership
# to the same current ownership.
# If we're running as root, this is EACCES instead.
st = os.lstat(filename)
os.chown(filename, st.st_uid, st.st_gid)
with self.assertRaises(OSError) as context:
os.chown(filename, st.st_uid + 1, st.st_gid)
self.assertEqual(
errno.EPERM,
errno.EACCES if os.geteuid() == 0 else errno.EPERM,
context.exception.errno,
msg="changing uid of a file should raise EPERM"
msg="changing uid of a file should raise EPERM/EACCES"
)
with self.assertRaises(OSError) as context:
os.chown(filename, st.st_uid, st.st_gid + 1)
self.assertEqual(
errno.EPERM,
errno.EACCES if os.geteuid() == 0 else errno.EPERM,
context.exception.errno,
msg="changing gid of a file should raise EPERM"
msg="changing gid of a file should raise EPERM/EACCES"
)
def test_truncate(self):