Browse Source

Test: Fix file permissions for system file tests

master
Riyyi 3 years ago
parent
commit
e2f9ed1176
  1. 8
      test/testdotfile.cpp

8
test/testdotfile.cpp

@ -21,12 +21,12 @@
const std::string homeDirectory = "/home/" + Machine::the().username(); const std::string homeDirectory = "/home/" + Machine::the().username();
const size_t homeDirectorySize = homeDirectory.size(); const size_t homeDirectorySize = homeDirectory.size();
void createTestDotfiles(const std::vector<std::string>& fileNames, const std::vector<std::string>& fileContents) void createTestDotfiles(const std::vector<std::string>& fileNames, const std::vector<std::string>& fileContents, bool asRoot = false)
{ {
VERIFY(fileNames.size() == fileContents.size()); VERIFY(fileNames.size() == fileContents.size());
bool root = !geteuid() ? true : false; bool root = !geteuid() ? true : false;
if (root) { if (root && !asRoot) {
setegid(Machine::the().gid()); setegid(Machine::the().gid());
seteuid(Machine::the().uid()); seteuid(Machine::the().uid());
} }
@ -45,7 +45,7 @@ void createTestDotfiles(const std::vector<std::string>& fileNames, const std::ve
} }
} }
if (root) { if (root && !asRoot) {
seteuid(0); seteuid(0);
setegid(0); setegid(0);
} }
@ -216,7 +216,7 @@ TEST_CASE(PullSystemDotfiles)
{ {
VERIFY(geteuid() == 0); VERIFY(geteuid() == 0);
createTestDotfiles({ "etc/group" }, { "" }); createTestDotfiles({ "etc/group" }, { "" }, true);
Dotfile::the().setSystemDirectories({ "/etc" }); Dotfile::the().setSystemDirectories({ "/etc" });
Dotfile::the().pull({ "etc/group" }); Dotfile::the().pull({ "etc/group" });

Loading…
Cancel
Save