Skip to content
Snippets Groups Projects
Commit 8dd6cae6 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix invalid path write attempt test

Actually since Gitlab CI is running as root, one must use ioctl to
make directory immutable. Otherwise, root can create the file which
invalidates the test.
parent a9a42d49
No related branches found
No related tags found
1 merge request!173Create missing directories when creating a file
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
#include <filesystem> #include <filesystem>
#ifdef __linux__
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif // __linux__
// clazy:excludeall=non-pod-global-static // clazy:excludeall=non-pod-global-static
TEST_CASE("OFStream", "[language]") TEST_CASE("OFStream", "[language]")
...@@ -49,6 +55,7 @@ TEST_CASE("OFStream", "[language]") ...@@ -49,6 +55,7 @@ TEST_CASE("OFStream", "[language]")
REQUIRE(not std::filesystem::exists(filename)); REQUIRE(not std::filesystem::exists(filename));
} }
#ifdef __linux__
SECTION("invalid filename") SECTION("invalid filename")
{ {
if (parallel::rank() == 0) { if (parallel::rank() == 0) {
...@@ -60,8 +67,14 @@ TEST_CASE("OFStream", "[language]") ...@@ -60,8 +67,14 @@ TEST_CASE("OFStream", "[language]")
std::filesystem::perms::others_all, std::filesystem::perms::others_all,
std::filesystem::perm_options::remove); std::filesystem::perm_options::remove);
int fd = open("tests/badpath/invalidpath", O_DIRECTORY);
int flags = FS_IMMUTABLE_FL;
ioctl(fd, FS_IOC_SETFLAGS, &flags);
REQUIRE_THROWS_WITH(std::make_shared<OFStream>(filename), "error: cannot create file " + filename); REQUIRE_THROWS_WITH(std::make_shared<OFStream>(filename), "error: cannot create file " + filename);
flags = 0;
ioctl(fd, FS_IOC_SETFLAGS, &flags);
std::filesystem::permissions(directory, std::filesystem::permissions(directory,
std::filesystem::perms::owner_all | std::filesystem::perms::group_all | std::filesystem::perms::owner_all | std::filesystem::perms::group_all |
std::filesystem::perms::others_all, std::filesystem::perms::others_all,
...@@ -69,4 +82,5 @@ TEST_CASE("OFStream", "[language]") ...@@ -69,4 +82,5 @@ TEST_CASE("OFStream", "[language]")
std::filesystem::remove_all("tests/badpath"); std::filesystem::remove_all("tests/badpath");
} }
} }
#endif // __linux__
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment