From: Jeff Layton Date: Mon, 10 May 2021 13:19:10 +0000 (-0400) Subject: test: add fscrypt attribute testcases X-Git-Tag: v18.0.0~1381^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5d09332c3637f1d9dcd017095c688db147710b74;p=ceph.git test: add fscrypt attribute testcases Create a file and set both fscrypt_auth and fscrypt_file on it. Verify that they are set, remount and verify it again. Signed-off-by: Jeff Layton --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 75b66798e240..2f08877f8d98 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -3573,6 +3573,38 @@ TEST(LibCephFS, SetMountTimeout) { ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); ASSERT_EQ(0, ceph_set_mount_timeout(cmount, 5)); ASSERT_EQ(ceph_mount(cmount, NULL), 0); + ceph_shutdown(cmount); +} + +TEST(LibCephFS, FsCrypt) { + struct ceph_mount_info *cmount; + ASSERT_EQ(ceph_create(&cmount, NULL), 0); + ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(ceph_mount(cmount, NULL), 0); + + char test_xattr_file[NAME_MAX]; + sprintf(test_xattr_file, "test_fscrypt_%d", getpid()); + int fd = ceph_open(cmount, test_xattr_file, O_RDWR|O_CREAT, 0666); + ASSERT_GT(fd, 0); + ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.auth", "foo", 3, CEPH_XATTR_CREATE)); + ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", "foo", 3, CEPH_XATTR_CREATE)); + + char buf[64]; + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + ASSERT_EQ(0, ceph_unmount(cmount)); + ASSERT_EQ(0, ceph_mount(cmount, NULL)); + + fd = ceph_open(cmount, test_xattr_file, O_RDWR, 0666); + ASSERT_GT(fd, 0); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); + + ASSERT_EQ(0, ceph_close(cmount, fd)); + ASSERT_EQ(0, ceph_unmount(cmount)); ceph_shutdown(cmount); }