Parcourir la source

Fix FileUtlTest.GetTempDir failure when run as root

Testing /usr as TMPDIR assumes that GetTempDir() cannot use it
because it cannot write to it; this is true for non-root users, but
not so much for root.

Since root can access everything, perform this particular test case
only when not running as root.

Closes: #808383
Pino Toscano il y a 10 ans
Parent
commit
dbbe1e6393
1 fichiers modifiés avec 7 ajouts et 3 suppressions
  1. 7 3
      test/libapt/fileutl_test.cc

+ 7 - 3
test/libapt/fileutl_test.cc

@@ -222,9 +222,13 @@ TEST(FileUtlTest, GetTempDir)
    setenv("TMPDIR", "/not-there-no-really-not", 1);
    EXPECT_EQ("/tmp", GetTempDir());
 
-   // here but not accessible for non-roots
-   setenv("TMPDIR", "/usr", 1);
-   EXPECT_EQ("/tmp", GetTempDir());
+   // root can access everything, so /usr will be accepted
+   if (geteuid() != 0)
+   {
+       // here but not accessible for non-roots
+       setenv("TMPDIR", "/usr", 1);
+       EXPECT_EQ("/tmp", GetTempDir());
+   }
 
    // files are no good for tmpdirs, too
    setenv("TMPDIR", "/dev/null", 1);