From 59a9eed6dbaea22bac9ae65f59ee8d506ae79dd5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 26 Oct 2017 20:02:25 +0100 Subject: Tidy up permissions tests --- netfs/unittests/testCore.cpp | 60 ++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index a55081c..fbca658 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -152,6 +152,26 @@ nameListAdd(void *buf, const char *name, const struct stat *, off_t) return 0; } +void +enableWriteOnDir(const fuse_operations * fuse, const char * dir) +{ + struct stat st; + memset(&st, 0, sizeof(st)); + BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0700), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st), 0); + BOOST_REQUIRE_EQUAL(st.st_mode, 0700 | S_IFDIR); +} + +void +disableWriteOnDir(const fuse_operations * fuse, const char * dir) +{ + struct stat st; + memset(&st, 0, sizeof(st)); + BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0500), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st), 0); + BOOST_REQUIRE_EQUAL(st.st_mode, 0500 | S_IFDIR); +} + BOOST_AUTO_TEST_CASE( directories ) { struct fuse_file_info fi; @@ -291,45 +311,47 @@ BOOST_AUTO_TEST_CASE( access ) BOOST_REQUIRE_EQUAL(fuse->access("/dir", R_OK), -EACCES); BOOST_REQUIRE_EQUAL(fuse->access("/dir", W_OK), -EACCES); BOOST_REQUIRE_EQUAL(fuse->access("/dir", X_OK), -EACCES); - // Child permissions (directories) - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0700), 0); + enableWriteOnDir(fuse, "/dir"); + BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir"), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), -ENOENT); +} + +BOOST_AUTO_TEST_CASE( permissionsDirs ) +{ + struct stat st; + memset(&st, 0, sizeof(st)); + BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0); BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir/yes", 0000), 0); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st), 0); BOOST_REQUIRE_EQUAL(st.st_mode, 0000 | S_IFDIR); - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0500), 0); - BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), 0); - BOOST_REQUIRE_EQUAL(st.st_mode, 0500 | S_IFDIR); + disableWriteOnDir(fuse, "/dir"); BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir/no", 0700), -EACCES); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/no", &st), -ENOENT); BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir/yes"), -EACCES); - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0700), 0); - BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), 0); - BOOST_REQUIRE_EQUAL(st.st_mode, 0700 | S_IFDIR); + enableWriteOnDir(fuse, "/dir"); BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir/yes"), 0); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st), -ENOENT); - // Child permissions (files) +} + +BOOST_AUTO_TEST_CASE( permissionsFiles ) +{ + struct stat st; + memset(&st, 0, sizeof(st)); struct fuse_file_info fi; memset(&fi, 0, sizeof(fi)); fi.flags = O_RDWR; - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0700), 0); + BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0); BOOST_REQUIRE_NE(fuse->create("/dir/yes", 0000, &fi), -1); BOOST_REQUIRE_EQUAL(fuse->release("/dir/yes", &fi), 0); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st), 0); BOOST_REQUIRE_EQUAL(st.st_mode, 0000 | S_IFREG); - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0500), 0); - BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), 0); - BOOST_REQUIRE_EQUAL(st.st_mode, 0500 | S_IFDIR); + disableWriteOnDir(fuse, "/dir"); BOOST_REQUIRE_EQUAL(fuse->create("/dir/no", 0600, &fi), -EACCES); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/no", &st), -ENOENT); BOOST_REQUIRE_EQUAL(fuse->unlink("/dir/yes"), -EACCES); - BOOST_REQUIRE_EQUAL(fuse->chmod("/dir", 0700), 0); - BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), 0); - BOOST_REQUIRE_EQUAL(st.st_mode, 0700 | S_IFDIR); + enableWriteOnDir(fuse, "/dir"); BOOST_REQUIRE_EQUAL(fuse->unlink("/dir/yes"), 0); BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st), -ENOENT); - // Tidy up - BOOST_REQUIRE_EQUAL(fuse->rmdir("/dir"), 0); - BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), -ENOENT); } BOOST_AUTO_TEST_CASE( mknod ) -- cgit v1.2.3