diff options
-rw-r--r-- | netfs/daemon/modeCheck.cpp | 14 | ||||
-rw-r--r-- | netfs/unittests/Jamfile.jam | 8 | ||||
-rw-r--r-- | netfs/unittests/testDaemon.cpp | 28 |
3 files changed, 48 insertions, 2 deletions
diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index d63163a..652d8a4 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -1,10 +1,20 @@ #include "modeCheck.h" #include <exceptions.h> +template<typename Ex, typename T, typename... ExP> +T && +assert_truthy(T && v, ExP &&... p) +{ + if (!v) { + throw Ex {std::forward<ExP>(p)...}; + } + return std::forward<T>(v); +} + ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntryResolver<User> & u, const EntryResolver<Group> & g) : - myu(u.getEntry(re.user)->id), - myg(g.getEntry(re.grp)->id), root(r), userLookup(u), groupLookup(g) + myu(assert_truthy<NetFS::SystemError>(u.getEntry(re.user), EPERM)->id), + myg(assert_truthy<NetFS::SystemError>(g.getEntry(re.grp), EPERM)->id), root(r), userLookup(u), groupLookup(g) { } diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index e811c57..1cd7d84 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -91,3 +91,11 @@ run testFuse.cpp <dependency>testCore ; +run testDaemon.cpp ../daemon/modeCheck.cpp + : -- : : + <define>BOOST_TEST_DYN_LINK + <library>boost_utf + <library>testMocks + <dependency>testCore + ; + diff --git a/netfs/unittests/testDaemon.cpp b/netfs/unittests/testDaemon.cpp new file mode 100644 index 0000000..5c6fbc9 --- /dev/null +++ b/netfs/unittests/testDaemon.cpp @@ -0,0 +1,28 @@ +#define BOOST_TEST_MODULE TestNetFSDaemon +#include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> + +#include <entCache.h> +#include <exceptions.h> +#include <modeCheck.h> + +struct ModeCheckHelper { + EntryResolverPtr<User> eru = std::make_shared<UserEntCache>(); + EntryResolverPtr<Group> erg = std::make_shared<GroupEntCache>(eru); +}; + +BOOST_FIXTURE_TEST_SUITE(mc, ModeCheckHelper) + +BOOST_AUTO_TEST_CASE(mode_check_valid) +{ + ModeCheck mc {{"root", "root"}, "/tmp", *eru, *erg}; +} + +BOOST_AUTO_TEST_CASE(mode_check_invalid) +{ + BOOST_CHECK_THROW({ ModeCheck({"root", ""}, "/tmp", *eru, *erg); }, NetFS::SystemError); + BOOST_CHECK_THROW({ ModeCheck({"", "root"}, "/tmp", *eru, *erg); }, NetFS::SystemError); + BOOST_CHECK_THROW({ ModeCheck({"", ""}, "/tmp", *eru, *erg); }, NetFS::SystemError); +} + +BOOST_AUTO_TEST_SUITE_END() |