]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Add func. test for chmod in libcephfs
authorSam Lang <sam.lang@inktank.com>
Wed, 17 Oct 2012 01:13:48 +0000 (20:13 -0500)
committerSage Weil <sage@inktank.com>
Wed, 17 Oct 2012 01:26:29 +0000 (18:26 -0700)
Signed-off-by: Sam Lang <sam.lang@inktank.com>
src/test/libcephfs/test.cc

index a8b73d466e814029cacf40cf63f9322ff4b7895b..77aa0cd59886dbcdbbf23dfbe99a3687fce6187d 100644 (file)
@@ -352,3 +352,58 @@ TEST(LibCephFS, Lstat_slashdot) {
 
   ceph_shutdown(cmount);
 }
+
+TEST(LibCephFS, Double_chmod) {
+
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+  char test_file[256];
+  sprintf(test_file, "test_perms_%d", getpid());
+
+  int fd = ceph_open(cmount, test_file, O_CREAT|O_RDWR, 0666);
+  ASSERT_GT(fd, 0);
+
+  // write some stuff
+  const char *bytes = "foobarbaz";
+  ASSERT_EQ(ceph_write(cmount, fd, bytes, strlen(bytes), 0), (int)strlen(bytes));
+
+  ceph_close(cmount, fd);
+
+  // set perms to read but can't write
+  ASSERT_EQ(ceph_chmod(cmount, test_file, 0400), 0);
+
+  fd = ceph_open(cmount, test_file, O_RDWR, 0);
+  ASSERT_EQ(fd, -EACCES);
+
+  fd = ceph_open(cmount, test_file, O_RDONLY, 0);
+  ASSERT_GT(fd, -1);
+
+  char buf[100];
+  int ret = ceph_read(cmount, fd, buf, 100, 0);
+  ASSERT_EQ(ret, (int)strlen(bytes));
+  buf[ret] = '\0';
+  ASSERT_STREQ(buf, bytes);
+
+  ASSERT_EQ(ceph_write(cmount, fd, bytes, strlen(bytes), 0), -EBADF);
+
+  ceph_close(cmount, fd);
+
+  // reset back to writeable
+  ASSERT_EQ(ceph_chmod(cmount, test_file, 0600), 0);
+
+  // ensure perms are correct
+  struct stat stbuf;
+  ASSERT_EQ(ceph_lstat(cmount, test_file, &stbuf), 0);
+  ASSERT_EQ(stbuf.st_mode, 0100600U);
+
+  fd = ceph_open(cmount, test_file, O_RDWR, 0);
+  ASSERT_GT(fd, 0);
+
+  ASSERT_EQ(ceph_write(cmount, fd, bytes, strlen(bytes), 0), (int)strlen(bytes));
+  ceph_close(cmount, fd);
+
+  ceph_shutdown(cmount);
+}