Esempio n. 1
0
 def test_eofReceived(self):
     """
     When the eof event is received, L{PantheonSession} closed the standard
     input of its child process.
     """
     mockos = MockProcessState(0, 0)
     session = PantheonSession(None)
     process = session._process = MemoryProcessTransport(mockos)
     session.eofReceived()
     self.assertTrue(process.stdinClosed)
Esempio n. 2
0
 def test_closed(self):
     """
     When the closed event is received, L{PantheonSession} closed the
     standard input of its child process and signals it with C{SIGHUP}.
     """
     mockos = MockProcessState(0, 0)
     mockos.seteuid(100)
     session = PantheonSession(None)
     session.os = mockos
     process = session._process = MemoryProcessTransport(mockos)
     session.closed()
     self.assertTrue(process.stdinClosed)
     self.assertEqual(process.signals, [SIGHUP])
     self.assertEqual(mockos.geteuid(), 100)
Esempio n. 3
0
 def test_alreadyExited(self):
     """
     No unhandled exceptions are raised if the channel receives eof or is
     closed after the child process has already exited.  stdin is still
     closed and the process's euid is still set back to its original value.
     """
     mockos = MockProcessState(0, 0)
     mockos.seteuid(100)
     session = PantheonSession(None)
     session.os = mockos
     process = session._process = MemoryProcessTransport(mockos)
     process._exited = True
     session.closed()
     self.assertTrue(process.stdinClosed)
     self.assertEqual(mockos.geteuid(), 100)
Esempio n. 4
0
    def test_execCommand(self):
        """
        L{PantheonSession.execCommand} launches the command as a child process,
        running it with the working directory and uid its avatar, the
        L{PantheonSite}, specifies.
        """
        cwd = "/some/path"
        expectedUID = 58927

        site = PantheonSite(None, cwd, expectedUID)
        messages = []
        site.logExecCommand = messages.append

        nobody = 99
        mockos = MockProcessState(0, 0)
        mockos.setegid(nobody)
        mockos.seteuid(nobody)
        proc = MemoryProcessReactor(mockos)
        session = PantheonSession(site)
        session.reactor = proc
        session.os = mockos
        expectedProto = object()
        session.execCommand(expectedProto, "echo 'hello, world'")
        self.assertIsInstance(session._process, MemoryProcessTransport)
        process = proc.processes.pop(0)
        proto, executable, args, env, path, uid, gid, usePTY, childFDs = process
        self.assertIdentical(expectedProto, proto)
        self.assertEqual("/bin/sh", executable)
        self.assertEqual(args, ["/bin/sh", "-c", "echo 'hello, world'"])
        # XXX What should really be in the environment?
        self.assertEqual({'HOME': cwd}, env)
        self.assertEqual(cwd, path)
        self.assertEqual(expectedUID, uid)
        # XXX What should the GID really be?
        self.assertEqual(80, gid)
        self.assertFalse(usePTY)
        self.assertIdentical(None, childFDs)

        # Ensure we end up in a good state, uid/gid-wise.
        self.assertEqual(nobody, mockos.geteuid())
        self.assertEqual(nobody, mockos.getegid())

        # Ensure the command is logged
        self.assertEqual(["echo 'hello, world'"], messages)
Esempio n. 5
0
 def test_windowChanged(self):
     """
     L{PantheonSession} disregards window change notifications.
     """
     session = PantheonSession(None)
     session.windowChanged((2, 3, 4, 5))