'Test that channel data messages are passed up to the channel, or
cause the channel to be closed if the data is too large.'

def test_CHANNEL_DATA(self):

    channel = TestChannel(localWindow=6, localMaxPacket=5)
    self._openChannel(channel)
    self.conn.ssh_CHANNEL_DATA(('\x00\x00\x00\x00' + common.NS('data')))
    self.assertEqual(channel.inBuffer, ['data'])
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_WINDOW_ADJUST, '\x00\x00\x00\xff\x00\x00\x00\x04')])
    self.transport.packets = []
    longData = ('a' * (channel.localWindowLeft + 1))
    self.conn.ssh_CHANNEL_DATA(('\x00\x00\x00\x00' + common.NS(longData)))
    self.assertEqual(channel.inBuffer, ['data'])
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_CLOSE, '\x00\x00\x00\xff')])
    channel = TestChannel()
    self._openChannel(channel)
    bigData = ('a' * (channel.localMaxPacket + 1))
    self.transport.packets = []
    self.conn.ssh_CHANNEL_DATA(('\x00\x00\x00\x01' + common.NS(bigData)))
    self.assertEqual(channel.inBuffer, [])
    self.assertEqual(self.transport.packets, [(connection.MSG_CHANNEL_CLOSE, '\x00\x00\x00\xff')])
