2019-06-21 06:54:21 +03:00
|
|
|
#!/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
|
|
|
|
|
2020-05-04 21:43:29 +03:00
|
|
|
from .lib import edenclient, testcase
|
2019-06-21 06:54:21 +03:00
|
|
|
from .lib.find_executables import FindExe
|
|
|
|
|
|
|
|
|
2020-05-04 21:43:29 +03:00
|
|
|
class UserInfoTest(testcase.IntegrationTestCase):
|
2019-06-21 06:54:21 +03:00
|
|
|
@unittest.skipIf(not edenclient.can_run_sudo(), "unable to run sudo")
|
|
|
|
def test_drop_privs(self):
|
|
|
|
expected_user = os.environ["USER"]
|
|
|
|
|
2020-05-04 21:43:29 +03:00
|
|
|
cmd = ["/usr/bin/sudo", FindExe.DROP_PRIVS, "/usr/bin/env"]
|
2019-06-21 06:54:21 +03:00
|
|
|
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)
|