class GetPasswordTest(unittest.TestCase):
    if not IReactorProcess.providedBy(reactor):
        skip = "Process support required to test getPassword"

    def test_stdin(self):
        """
        Making sure getPassword accepts a password from standard input by
        running a child process which uses getPassword to read in a string
        which it then writes it out again.  Write a string to the child
        process and then read one and make sure it is the right string.
        """
        p = PasswordTestingProcessProtocol()
        p.finished = Deferred()
        reactor.spawnProcess(
            p,
            sys.executable, [
                sys.executable, '-c',
                ('import sys\n'
                 'from twisted.python.util import getPassword\n'
                 'sys.stdout.write(getPassword())\n'
                 'sys.stdout.flush()\n')
            ],
            env={'PYTHONPATH': os.pathsep.join(sys.path)})

        def processFinished((reason, output)):
            reason.trap(ProcessDone)
            self.assertIn((1, 'secret'), output)

        return p.finished.addCallback(processFinished)
Пример #2
0
    def test_noCompatibilityLayer(self):
        """
        If no compatiblity layer is present, imports of gobject and friends
        are disallowed.

        We do this by running a process where we make sure gi.pygtkcompat
        isn't present.
        """
        from twisted.internet import reactor
        if not IReactorProcess.providedBy(reactor):
            raise SkipTest("No process support available in this reactor.")

        result = Deferred()
        class Stdout(ProcessProtocol):
            data = b""

            def errReceived(self, err):
                print(err)

            def outReceived(self, data):
                self.data += data

            def processExited(self, reason):
                result.callback(self.data)

        path = FilePath(__file__.encode("utf-8")).sibling(
            b"process_gireactornocompat.py").path
        reactor.spawnProcess(Stdout(), sys.executable, [sys.executable, path],
                             env=os.environ)
        result.addCallback(self.assertEqual, b"success")
        return result
Пример #3
0
    def __init__(self,
                 reactor,
                 session,
                 id_,
                 router_uri,
                 privkey_fname,
                 workdir,
                 debug=True):
        """
        :param session: a WAMP ApplicationSession we may use. This will be
        a LauncherSession; see
        :meth:`.LauncherSession._create_process_controller` below.

        XXX maybe just roll all this into LauncherSession? I'm just
        trying to avoid that class being huge and have many concerns...
        """
        self._spawn = IReactorProcess(reactor).spawnProcess
        self._session = session
        self._processes = dict()
        self._prefix = 'io.crossbar.cts.launcher.{}'.format(id_)
        self._id = id_
        self._debug = debug
        self._router_uri = router_uri
        self._privkey_fname = privkey_fname
        self._workdir = workdir
Пример #4
0
    def test_noCompatibilityLayer(self):
        """
        If no compatibility layer is present, imports of gobject and friends
        are disallowed.

        We do this by running a process where we make sure gi.pygtkcompat
        isn't present.
        """
        if _PY3:
            raise SkipTest("Python3 always has the compatibility layer.")

        from twisted.internet import reactor
        if not IReactorProcess.providedBy(reactor):
            raise SkipTest("No process support available in this reactor.")

        result = Deferred()

        class Stdout(ProcessProtocol):
            data = b""

            def errReceived(self, err):
                print(err)

            def outReceived(self, data):
                self.data += data

            def processExited(self, reason):
                result.callback(self.data)

        path = FilePath(__file__).sibling(b"process_gireactornocompat.py").path
        pyExe = FilePath(sys.executable)._asBytesPath()
        # Pass in a PYTHONPATH that is the test runner's os.path, to make sure
        # we're running from a checkout
        reactor.spawnProcess(Stdout(),
                             pyExe, [pyExe, path],
                             env={"PYTHONPATH": ":".join(os.path)})
        result.addCallback(self.assertEqual, b"success")
        return result
Пример #5
0
    def test_noCompatibilityLayer(self):
        """
        If no compatibility layer is present, imports of gobject and friends
        are disallowed.

        We do this by running a process where we make sure gi.pygtkcompat
        isn't present.
        """
        if _PY3:
            raise SkipTest("Python3 always has the compatibility layer.")

        from twisted.internet import reactor
        if not IReactorProcess.providedBy(reactor):
            raise SkipTest("No process support available in this reactor.")

        result = Deferred()
        class Stdout(ProcessProtocol):
            data = b""

            def errReceived(self, err):
                print(err)

            def outReceived(self, data):
                self.data += data

            def processExited(self, reason):
                result.callback(self.data)

        path = FilePath(__file__).sibling(b"process_gireactornocompat.py").path
        pyExe = FilePath(sys.executable)._asBytesPath()
        # Pass in a PYTHONPATH that is the test runner's os.path, to make sure
        # we're running from a checkout
        reactor.spawnProcess(Stdout(), pyExe, [pyExe, path],
                             env={"PYTHONPATH": ":".join(sys.path)})
        result.addCallback(self.assertEqual, b"success")
        return result
Пример #6
0
    Write the string C{"secret\\n"} to a subprocess and then collect all of
    its output and fire a Deferred with it when the process ends.
    """
    def connectionMade(self):
        self.output = []
        self.transport.write(b'secret\n')

    def childDataReceived(self, fd, output):
        self.output.append((fd, output))

    def processEnded(self, reason):
        self.finished.callback((reason, self.output))



@skipIf(not IReactorProcess.providedBy(reactor),
        "Process support required to test getPassword")
class GetPasswordTests(TestCase):
    def test_stdin(self):
        """
        Making sure getPassword accepts a password from standard input by
        running a child process which uses getPassword to read in a string
        which it then writes it out again.  Write a string to the child
        process and then read one and make sure it is the right string.
        """
        p = PasswordTestingProcessProtocol()
        p.finished = Deferred()
        reactor.spawnProcess(
            p, pyExe,
            [pyExe,
             b'-c',