summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-10-26 20:02:25 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-12-16 20:40:52 +0000
commit59a9eed6dbaea22bac9ae65f59ee8d506ae79dd5 (patch)
tree3f9bdadae2b421cc5f018592c508a1c1a022c560
parentAdd tests over permissions with creation of files (diff)
downloadnetfs-59a9eed6dbaea22bac9ae65f59ee8d506ae79dd5.tar.bz2
netfs-59a9eed6dbaea22bac9ae65f59ee8d506ae79dd5.tar.xz
netfs-59a9eed6dbaea22bac9ae65f59ee8d506ae79dd5.zip
Tidy up permissions tests
-rw-r--r--netfs/unittests/testCore.cpp60
1 files 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 )