MCPcopy
hub / github.com/amoffat/sh / test_pass_fds

Method test_pass_fds

tests/sh_test.py:690–717  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

688 t.close()
689
690 def test_pass_fds(self):
691 # guarantee some extra fds in our parent process that don't close on exec.
692 # we have to explicitly do this because at some point (I believe python 3.4),
693 # python started being more stringent with closing fds to prevent security
694 # vulnerabilities. python 2.7, for example, doesn't set CLOEXEC on
695 # tempfile.TemporaryFile()s
696 #
697 # https://www.python.org/dev/peps/pep-0446/
698 tmp = [tempfile.TemporaryFile() for i in range(10)]
699 for t in tmp:
700 flags = fcntl.fcntl(t.fileno(), fcntl.F_GETFD)
701 flags &= ~fcntl.FD_CLOEXEC
702 fcntl.fcntl(t.fileno(), fcntl.F_SETFD, flags)
703 last_fd = tmp[-1].fileno()
704
705 py = create_tmp_test(
706 """
707import os
708print(os.listdir("/dev/fd"))
709"""
710 )
711 out = python(py.name, _pass_fds=[last_fd]).strip()
712 inherited = [0, 1, 2, 3, last_fd]
713 inherited_str = [str(i) for i in inherited]
714 self.assertEqual(out, str(inherited_str))
715
716 for t in tmp:
717 t.close()
718
719 def test_no_arg(self):
720 import pwd

Callers

nothing calls this directly

Calls 3

create_tmp_testFunction · 0.85
filenoMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected