From b961e17b508bae384f82b7b9e073470c237144b6 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 24 Jan 2022 14:45:40 +0100 Subject: [PATCH] Test: Set ownership of created dotfile test files to the current user --- test/testdotfile.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testdotfile.cpp b/test/testdotfile.cpp index aab50af..b6663f7 100644 --- a/test/testdotfile.cpp +++ b/test/testdotfile.cpp @@ -7,6 +7,7 @@ #include #include #include +#include // geteuid, setegid, seteuid #include #include @@ -25,6 +26,12 @@ void createTestDotfiles(const std::vector& fileNames, const std::ve { VERIFY(fileNames.size() == fileContents.size()); + bool root = !geteuid() ? true : false; + if (root) { + setegid(Machine::the().gid()); + seteuid(Machine::the().uid()); + } + for (size_t i = 0; i < fileNames.size(); ++i) { auto fileName = fileNames.at(i); @@ -38,6 +45,11 @@ void createTestDotfiles(const std::vector& fileNames, const std::ve file.append(fileContents.at(i).c_str()).flush(); } } + + if (root) { + seteuid(0); + setegid(0); + } } void removeTestDotfiles(const std::vector& files)