Browse Source

Test: Set ownership of created dotfile test files to the current user

master
Riyyi 3 years ago
parent
commit
b961e17b50
  1. 12
      test/testdotfile.cpp

12
test/testdotfile.cpp

@ -7,6 +7,7 @@
#include <cstdio> #include <cstdio>
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <unistd.h> // geteuid, setegid, seteuid
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -25,6 +26,12 @@ void createTestDotfiles(const std::vector<std::string>& fileNames, const std::ve
{ {
VERIFY(fileNames.size() == fileContents.size()); 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) { for (size_t i = 0; i < fileNames.size(); ++i) {
auto fileName = fileNames.at(i); auto fileName = fileNames.at(i);
@ -38,6 +45,11 @@ void createTestDotfiles(const std::vector<std::string>& fileNames, const std::ve
file.append(fileContents.at(i).c_str()).flush(); file.append(fileContents.at(i).c_str()).flush();
} }
} }
if (root) {
seteuid(0);
setegid(0);
}
} }
void removeTestDotfiles(const std::vector<std::string>& files) void removeTestDotfiles(const std::vector<std::string>& files)

Loading…
Cancel
Save