]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/pybind/cephfs.pyx: add tests for chown() 64999/head
authorRishabh Dave <ridave@redhat.com>
Tue, 12 Aug 2025 16:55:52 +0000 (22:25 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 13 Aug 2025 06:06:51 +0000 (11:36 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/test/pybind/test_cephfs.py

index 577cb9e4171536fca1a03802409170716aa2e42e..14814c1c53f42dd98b41400ee82d9ace7889906b 100644 (file)
@@ -569,6 +569,93 @@ def test_fchmod(testdir):
     cephfs.close(fd)
     cephfs.unlink(b'/file-fchmod')
 
+def test_chown(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+
+    uid = 1012
+    gid = 1012
+    cephfs.chown('file1', uid, gid)
+    st = cephfs.stat(b'/file1')
+    assert_equal(st.st_uid, uid)
+    assert_equal(st.st_gid, gid)
+
+def test_chown_change_uid_but_not_gid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+
+    st1 = cephfs.stat(b'/file1')
+
+    uid = 1012
+    cephfs.chown('file1', uid, -1)
+    st2 = cephfs.stat(b'/file1')
+    assert_equal(st2.st_uid, uid)
+
+    # ensure that gid is unchaged.
+    assert_equal(st1.st_gid, st2.st_gid)
+
+def test_chown_change_gid_but_not_uid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+
+    st1 = cephfs.stat(b'/file1')
+
+    gid = 1012
+    cephfs.chown('file1', -1, gid)
+    st2 = cephfs.stat(b'/file1')
+    assert_equal(st2.st_gid, gid)
+
+    # ensure that uid is unchaged.
+    assert_equal(st1.st_uid, st2.st_uid)
+
+def test_lchown(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+    cephfs.symlink('file1', 'slink1')
+
+    uid = 1012
+    gid = 1012
+    cephfs.lchown('slink1', uid, gid)
+    st = cephfs.lstat(b'/slink1')
+    assert_equal(st.st_uid, uid)
+    assert_equal(st.st_gid, gid)
+
+def test_lchown_change_uid_but_not_gid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+    cephfs.symlink('file1', 'slink1')
+
+    st1 = cephfs.lstat(b'slink1')
+
+    uid = 1012
+    cephfs.lchown('slink1', uid, -1)
+    st2 = cephfs.lstat(b'/slink1')
+    assert_equal(st2.st_uid, uid)
+
+    # ensure that gid is unchaged.
+    assert_equal(st1.st_gid, st2.st_gid)
+
+def test_lchown_change_gid_but_not_uid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+    cephfs.close(fd)
+    cephfs.symlink('file1', 'slink1')
+
+    st1 = cephfs.lstat(b'slink1')
+
+    gid = 1012
+    cephfs.lchown('slink1', -1, gid)
+    st2 = cephfs.lstat(b'/slink1')
+    assert_equal(st2.st_gid, gid)
+
+    # ensure that uid is unchaged.
+    assert_equal(st1.st_uid, st2.st_uid)
+
 def test_fchown(testdir):
     fd = cephfs.open(b'/file-fchown', 'w', 0o655)
     uid = os.getuid()
@@ -586,6 +673,38 @@ def test_fchown(testdir):
     cephfs.close(fd)
     cephfs.unlink(b'/file-fchown')
 
+def test_fchown_change_uid_but_not_gid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+
+    st1 = cephfs.stat(b'/file1')
+
+    uid = 1012
+    cephfs.fchown(fd, uid, -1)
+    st2 = cephfs.stat(b'/file1')
+    assert_equal(st2.st_uid, uid)
+
+    # ensure that uid is unchanged.
+    assert_equal(st1.st_gid, st2.st_gid)
+
+    cephfs.close(fd)
+
+def test_fchown_change_gid_but_not_uid(testdir):
+    fd = cephfs.open('file1', 'w', 0o755)
+    cephfs.write(fd, b'abcd', 0)
+
+    st1 = cephfs.stat(b'/file1')
+
+    gid = 1012
+    cephfs.chown('file1', -1, gid)
+    st2 = cephfs.stat(b'/file1')
+    assert_equal(st2.st_gid, gid)
+
+    # ensure that gid is unchanged.
+    assert_equal(st1.st_uid, st2.st_uid)
+
+    cephfs.close(fd)
+
 def test_truncate(testdir):
     fd = cephfs.open(b'/file-truncate', 'w', 0o755)
     cephfs.write(fd, b"1111", 0)