[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#808383: apt: fix FileUtlTest.GetTempDir failure when run as root



Source: apt
Version: 1.1.5
Severity: minor
Tags: patch

Hi,

yes, I know, running builds as root is bad. OTOH, testing things under
pbuilder might be handy.

FileUtlTest.GetTempDir fails when run as root, as one of the tests
assumes that the current user cannot write to /usr; since root can,
the check fails. Attached there is a simple patch to run that case
only when running as non-root.

Thanks,
-- 
Pino
>From 958ad64f27ec2a35ffdfe7c1bb0e7570f83d0c1e Mon Sep 17 00:00:00 2001
From: Pino Toscano <pino@debian.org>
Date: Sat, 19 Dec 2015 12:09:18 +0100
Subject: [PATCH] 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.
---
 test/libapt/fileutl_test.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 2bd090e..7d1368f 100644
--- a/test/libapt/fileutl_test.cc
+++ b/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);
-- 
2.6.4


Reply to: