mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 09:48:05 +03:00
73509a87f8
Summary: If edenfs was started using `sudo`, the `$USER` environment variable will be set to `root` rather than the actual user. When we drop privileges make sure we restore the value of `$USER` as well. The `$USER` variable isn't checked anywhere else in edenfs itself, but it matters for subprocesses we spawn, like `hg debugedenimporthelper`. I also changed the code to clear the `SUDO_*` variables as well, mostly just for good measure. Reviewed By: kulshrax Differential Revision: D15929539 fbshipit-source-id: e022c7ae762e2a5e86d0227058bb476aff17cf55
27 lines
855 B
Python
27 lines
855 B
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
import os
|
|
import subprocess
|
|
import unittest
|
|
|
|
from .lib import edenclient
|
|
from .lib.find_executables import FindExe
|
|
|
|
|
|
class UserInfoTest(unittest.TestCase):
|
|
@unittest.skipIf(not edenclient.can_run_sudo(), "unable to run sudo")
|
|
def test_drop_privs(self):
|
|
expected_user = os.environ["USER"]
|
|
|
|
cmd = ["/usr/bin/sudo", FindExe.DROP_PRIVS, "/bin/env"]
|
|
out = subprocess.check_output(cmd)
|
|
lines = out.splitlines()
|
|
self.assertIn(f"USER={expected_user}".encode("utf-8"), lines)
|
|
self.assertIn(f"USERNAME={expected_user}".encode("utf-8"), lines)
|
|
self.assertIn(f"LOGNAME={expected_user}".encode("utf-8"), lines)
|