Beispiel #1
0
 def test_sessionChannel(self):
     """
     L{PantheonSite.lookupChannel} returns a L{SSHSession} when the
     I{session} channel is requested.
     """
     cwd = "/foo/bar"
     uid = 5812
     avatar = PantheonSite(None, cwd, uid)
     channel = avatar.lookupChannel("session", 2 ** 16, 2 ** 16, "")
     self.assertIsInstance(channel, SSHSession)
Beispiel #2
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)
Beispiel #3
0
    def test_logExecCommand(self):
        """
        L{PantheonSite.logExecCommand} emits a log event identifying the site it
        represents and a command which was executed on behalf of that site.
        """
        siteId = "example.com"
        cwd = "/random/path"
        uid = 1234
        command = "upload the files"
        avatar = PantheonSite(siteId, cwd, uid)

        messages = []
        addObserver(messages.append)
        self.addCleanup(removeObserver, messages.append)

        avatar.logExecCommand(command)
        self.assertEqual(
            [dict(event='execCommand', siteId=siteId,
                  cwd=cwd, uid=uid, command=command,
                  isError=False, message=(), system='-',
                  time=Anything())],
            messages)