mirror of
https://github.com/ceph/ceph
synced 2025-02-21 18:17:42 +00:00
test: Add func. test for chmod in libcephfs
Signed-off-by: Sam Lang <sam.lang@inktank.com>
This commit is contained in:
parent
328bf48234
commit
8ed86eea3f
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user