sapling/eden/integration/userinfo_test.py
Xavier Deguillard 3d362fa62b test: skip userinfo test if USER env isn't set
Summary:
In the ASIC test environment, we've see cases where this isn't set, let's
simply skip the test in this case instead of failing.

Reviewed By: chadaustin

Differential Revision: D30353929

fbshipit-source-id: 956da6f8f12de025b8ca72e40097f1f9d50e6bf7
2021-08-16 17:50:38 -07:00

30 lines
1007 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, testcase
from .lib.find_executables import FindExe
class UserInfoTest(testcase.IntegrationTestCase):
@unittest.skipIf(not edenclient.can_run_sudo(), "unable to run sudo")
def test_drop_privs(self):
try:
expected_user = os.environ["USER"]
except KeyError:
self.skipTest("No USER environment variable available")
return
cmd = ["/usr/bin/sudo", FindExe.DROP_PRIVS, "/usr/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)