Example #1
0
 def __init__(self, avatar):
     unittest.assert_(isinstance(avatar, ConchTestAvatar))
     self.avatar = avatar
     self.cmd = None
     self.proto = None
     self.ptyReq = False
     self.eof = 0
 def execCommand(self, proto, cmd):
     self.cmd = cmd
     unittest.assert_(
         cmd.split()[0] in ['false', 'echo', 'secho', 'eecho', 'jumboliah'],
         'invalid command: %s' % cmd.split()[0])
     if cmd == 'jumboliah':
         raise error.ConchError('bad exec')
     self.proto = proto
     f = cmd.split()[0]
     if f == 'false':
         t = FalseTransport(proto)
         # Avoid disconnecting this immediately.  If the channel is closed
         # before execCommand even returns the caller gets confused.
         reactor.callLater(0, t.loseConnection)
     elif f == 'echo':
         t = EchoTransport(proto)
         t.write(cmd[5:])
         t.loseConnection()
     elif f == 'secho':
         t = SuperEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     elif f == 'eecho':
         t = ErrEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     self.avatar.conn.transport.expectedLoseConnection = 1
Example #3
0
 def execCommand(self, proto, cmd):
     self.cmd = cmd
     unittest.assert_(cmd.split()[0] in ['false', 'echo', 'secho', 'eecho','jumboliah'],
             'invalid command: %s' % cmd.split()[0])
     if cmd == 'jumboliah':
         raise error.ConchError('bad exec')
     self.proto = proto
     f = cmd.split()[0]
     if f == 'false':
         t = FalseTransport(proto)
         # Avoid disconnecting this immediately.  If the channel is closed
         # before execCommand even returns the caller gets confused.
         reactor.callLater(0, t.loseConnection)
     elif f == 'echo':
         t = EchoTransport(proto)
         t.write(cmd[5:])
         t.loseConnection()
     elif f == 'secho':
         t = SuperEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     elif f == 'eecho':
         t = ErrEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     self.avatar.conn.transport.expectedLoseConnection = 1
Example #4
0
 def __init__(self, avatar):
     unittest.assert_(isinstance(avatar, ConchTestAvatar))
     self.avatar = avatar
     self.cmd = None
     self.proto = None
     self.ptyReq = False
     self.eof = 0
Example #5
0
 def closed(self):
     log.msg("calling shell closed")
     if self.status != 0:
         log.msg("shell exit status was not 0: %i" % self.status)
     unittest.assertEquals(self.testBuf, "testing the shell!\x00\r\n")
     unittest.assert_(self.eofCalled)
     log.msg("finished shell")
     self.conn.addResult()
Example #6
0
 def closed(self):
     log.msg('calling shell closed')
     if self.status != 0:
         log.msg('shell exit status was not 0: %i' % self.status)
     unittest.assertEquals(self.testBuf, 'testing the shell!\x00\r\n')
     unittest.assert_(self.eofCalled)
     log.msg('finished shell')
     self.conn.addResult()
Example #7
0
 def closed(self):
     log.msg('calling shell closed')
     if self.status != 0:
         log.msg('shell exit status was not 0: %i' % self.status)
     unittest.assertEquals(self.testBuf, 'testing the shell!\x00\r\n')
     unittest.assert_(self.eofCalled)
     log.msg('finished shell')
     self.conn.addResult()
Example #8
0
 def closed(self):
     if self.status != 0:
         unittest.fail('err exit status was not 0: %i' % self.status)
     if self.testBuf != "hello\r\n":
         unittest.fail('err did not return hello: %s' % repr(self.testBuf))
     unittest.assertEquals(self.localWindowLeft, 4)
     unittest.assert_(self.eofCalled)
     log.msg('finished err')
     self.conn.addResult()
     return 1
Example #9
0
 def closed(self):
     if self.status != 0:
         unittest.fail('echo exit status was not 0: %i' % self.status)
     unittest.assertEquals(self.testBuf, 'hello\r\n')
     unittest.assertEquals(self.testExtBuf, 'hello\r\n')
     unittest.assertEquals(self.localWindowLeft, 12)
     unittest.assert_(self.eofCalled)
     log.msg('finished max packet')
     self.conn.addResult()
     return 1
Example #10
0
 def closed(self):
     log.msg('closed cmd "%s"' % self.cmd)
     if self.cmd == 'echo hello':
         rwl = self.proto.session.remoteWindowLeft
         unittest.assertEquals(rwl, 4)
     elif self.cmd == 'eecho hello':
         rwl = self.proto.session.remoteWindowLeft
         unittest.assertEquals(rwl, 4)
     elif self.cmd == 'shell':
         unittest.assert_(self.eof)
Example #11
0
 def closed(self):
     log.msg('closed cmd "%s"' % self.cmd)
     if self.cmd == 'echo hello':
         rwl = self.proto.session.remoteWindowLeft
         unittest.assertEquals(rwl, 4)
     elif self.cmd == 'eecho hello':
         rwl = self.proto.session.remoteWindowLeft
         unittest.assertEquals(rwl, 4)
     elif self.cmd == 'shell':
         unittest.assert_(self.eof)
Example #12
0
 def closed(self):
     if self.status != 0:
         unittest.fail('echo exit status was not 0: %i' % self.status)
     unittest.assertEquals(self.testBuf, 'hello\r\n')
     unittest.assertEquals(self.testExtBuf, 'hello\r\n')
     unittest.assertEquals(self.localWindowLeft, 12)
     unittest.assert_(self.eofCalled)
     log.msg('finished max packet')
     self.conn.addResult()
     return 1
Example #13
0
 def closed(self):
     if self.status != 0:
         unittest.fail('err exit status was not 0: %i' % self.status)
     if self.testBuf != "hello\r\n":
         unittest.fail('err did not return hello: %s' %
                       repr(self.testBuf))
     unittest.assertEquals(self.localWindowLeft, 4)
     unittest.assert_(self.eofCalled)
     log.msg('finished err')
     self.conn.addResult()
     return 1
Example #14
0
    def testConnectByService(self):
        serv = socket.getservbyname
        try:
            s = MyServerFactory()
            port = reactor.listenTCP(0, s, interface="127.0.0.1")
            self.n = port.getHost().port
            socket.getservbyname = (lambda s, p,n=self.n:
                                    s == 'http' and p == 'tcp' and n or 10)
            self.ports.append(port)
            cf = MyClientFactory()
            try:
                c = reactor.connectTCP('127.0.0.1', 'http', cf)
            except:
                socket.getservbyname = serv
                raise

            spinUntil(lambda :getattr(s, 'protocol', None) is not None)
            self.cleanPorts(port, c.transport, cf.protocol.transport)

        finally:
            socket.getservbyname = serv
        assert_(s.called, '%s was not called' % (s,))
 def execCommand(self, proto, cmd):
     self.cmd = cmd
     unittest.assert_(cmd.split()[0] in ['false', 'echo', 'secho', 'eecho','jumboliah'],
             'invalid command: %s' % cmd.split()[0])
     if cmd == 'jumboliah':
         raise error.ConchError('bad exec')
     self.proto = proto
     f = cmd.split()[0]
     if f == 'false':
         FalseTransport(proto)
     elif f == 'echo':
         t = EchoTransport(proto)
         t.write(cmd[5:])
         t.loseConnection()
     elif f == 'secho':
         t = SuperEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     elif f == 'eecho':
         t = ErrEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     self.avatar.conn.transport.expectedLoseConnection = 1
Example #16
0
 def execCommand(self, proto, cmd):
     self.cmd = cmd
     unittest.assert_(
         cmd.split()[0] in ["false", "echo", "secho", "eecho", "jumboliah"], "invalid command: %s" % cmd.split()[0]
     )
     if cmd == "jumboliah":
         raise error.ConchError("bad exec")
     self.proto = proto
     f = cmd.split()[0]
     if f == "false":
         FalseTransport(proto)
     elif f == "echo":
         t = EchoTransport(proto)
         t.write(cmd[5:])
         t.loseConnection()
     elif f == "secho":
         t = SuperEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     elif f == "eecho":
         t = ErrEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     self.avatar.conn.transport.expectedLoseConnection = 1
Example #17
0
 def execCommand(self, proto, cmd):
     self.cmd = cmd
     unittest.assert_(
         cmd.split()[0] in ['false', 'echo', 'secho', 'eecho', 'jumboliah'],
         'invalid command: %s' % cmd.split()[0])
     if cmd == 'jumboliah':
         raise error.ConchError('bad exec')
     self.proto = proto
     f = cmd.split()[0]
     if f == 'false':
         FalseTransport(proto)
     elif f == 'echo':
         t = EchoTransport(proto)
         t.write(cmd[5:])
         t.loseConnection()
     elif f == 'secho':
         t = SuperEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     elif f == 'eecho':
         t = ErrEchoTransport(proto)
         t.write(cmd[6:])
         t.loseConnection()
     self.avatar.conn.transport.expectedLoseConnection = 1