Beispiel #1
0
 def test_rejects_oversized_payload(self):
     # pkt-lines are limited to 65524 bytes, so the data must not
     # exceed 65520 bytes.
     data = b'a' * 65520
     self.assertEqual(b'fff4', helpers.encode_packet(data)[:4])
     data += b'a'
     self.assertRaises(ValueError, helpers.encode_packet, data)
Beispiel #2
0
 def backendConnectionFailed(self, msg):
     """Called when the backend fails to connect or returns an error."""
     # Rewrite virt errors as more friendly-looking ordinary errors.  The
     # distinction is for the benefit of the smart HTTP frontend, and is
     # not otherwise useful here.
     if msg.startswith(VIRT_ERROR_PREFIX):
         _, msg = msg[len(VIRT_ERROR_PREFIX):].split(b' ', 1)
     self.factory.ssh_protocol.outReceived(
         encode_packet(ERROR_PREFIX + msg))
Beispiel #3
0
    def packetReceived(self, data):
        """Check and forward the first packet from the backend.

        Assume that any non-error packet indicates a success response,
        so we can just forward raw data afterward.
        """
        self.raw = True
        if data is not None and data.startswith(ERROR_PREFIX):
            self.backendConnectionFailed(data[len(ERROR_PREFIX):])
        else:
            self.rawDataReceived(encode_packet(data))
Beispiel #4
0
 def test_flush(self):
     # None represents the special flush-pkt, a zero-length packet.
     self.assertEqual(b'0000', helpers.encode_packet(None))
Beispiel #5
0
 def test_data(self):
     # Encoding a string creates a data-pkt, prefixing it with a
     # four-byte length of the entire packet.
     self.assertEqual(TEST_PKT, helpers.encode_packet(TEST_DATA))
Beispiel #6
0
 def sendPacket(self, data):
     self.sendRawData(encode_packet(data))