Beispiel #1
0
    def test_access_violation(self):
        tftp = TFTP(BackendFactory(AccessViolation("No!")), _clock=self.clock)
        tftp.transport = self.transport
        wrq_datagram = WRQDatagram('foobar', 'netascii', {})
        tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)

        self.transport.clear()
        rrq_datagram = RRQDatagram('foobar', 'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)
Beispiel #2
0
    def test_unsupported(self):
        tftp = TFTP(BackendFactory(Unsupported("I don't support you")), _clock=self.clock)
        tftp.transport = self.transport
        wrq_datagram = WRQDatagram('foobar', 'netascii', {})
        tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)

        self.transport.clear()
        rrq_datagram = RRQDatagram('foobar', 'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
Beispiel #3
0
    def test_generic_backend_error(self):
        tftp = TFTP(BackendFactory(BackendError("A backend that couldn't")), _clock=self.clock)
        tftp.transport = self.transport
        rrq_datagram = RRQDatagram('foobar', 'netascii', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)

        self.transport.clear()
        rrq_datagram = RRQDatagram('foobar', 'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)
Beispiel #4
0
 def test_bad_mode(self):
     tftp = TFTP(DummyBackend(), _clock=self.clock)
     tftp.transport = self.transport
     wrq_datagram = WRQDatagram('foobar', 'badmode', {})
     tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
     error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
Beispiel #5
0
 def test_file_exists(self):
     tftp = TFTP(BackendFactory(FileExists("Already have one")), _clock=self.clock)
     tftp.transport = self.transport
     wrq_datagram = WRQDatagram('foobar', 'netascii', {})
     tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
     error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_FILE_EXISTS)
Beispiel #6
0
 def test_invalid_tid(self):
     self.rs.startProtocol()
     data_datagram = DATADatagram(1, 'foobar')
     yield self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
     self.addCleanup(self.rs.cancel)
 def test_invalid_tid(self):
     self.rs.startProtocol()
     data_datagram = DATADatagram(1, 'foobar')
     yield self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
     self.addCleanup(self.rs.cancel)
Beispiel #8
0
 def test_ACK_invalid_blocknum(self):
     ack_datagram = ACKDatagram(3)
     yield self.rs.datagramReceived(ack_datagram)
     self.failIf(self.transport.disconnecting)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assert_(isinstance(err_dgram, ERRORDatagram))
     self.addCleanup(self.rs.cancel)
 def cb_(ign):
     self.clock.advance(0.1)
     self.failIf(self.transport.disconnecting)
     ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(ack_dgram.blocknum, 2)
     self.failIf(self.ws.completed,
                 "Data length is equal to blocksize, no reason to stop")
Beispiel #10
0
 def test_invalid_tid(self):
     bad_tid_dgram = ACKDatagram(123)
     yield self.ws.datagramReceived(bad_tid_dgram.to_wire(),
                                    ('127.0.0.1', 1111))
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
     self.addCleanup(self.ws.cancel)
Beispiel #11
0
 def test_invalid_tid(self):
     data_datagram = DATADatagram(1, b'foobar')
     self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
     self.clock.advance(0.1)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
     self.addCleanup(self.rs.cancel)
Beispiel #12
0
 def cb_(ign):
     self.clock.advance(0.1)
     self.failIf(self.transport.disconnecting)
     ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(ack_dgram.blocknum, 2)
     self.failIf(self.ws.completed,
                 "Data length is equal to blocksize, no reason to stop")
Beispiel #13
0
 def test_ACK_invalid_blocknum(self):
     ack_datagram = ACKDatagram(3)
     yield self.rs.datagramReceived(ack_datagram)
     self.assertFalse(self.transport.disconnecting)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertTrue(isinstance(err_dgram, ERRORDatagram))
     self.addCleanup(self.rs.cancel)
Beispiel #14
0
 def cb(ign):
     self.clock.advance(0.1)
     self.failIf(self.transport.disconnecting)
     data_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(data_datagram.data, 'line1')
     self.failIf(self.rs.completed,
                 "Got enough bytes from the reader, there is no reason to stop")
Beispiel #15
0
 def test_file_not_found(self):
     tftp = TFTP(BackendFactory(FileNotFound("Not found")), _clock=self.clock)
     tftp.transport = self.transport
     rrq_datagram = RRQDatagram('foobar', 'netascii', {})
     tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
     error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_FILE_NOT_FOUND)
Beispiel #16
0
 def cb(ign):
     self.clock.advance(0.1)
     self.failIf(self.transport.disconnecting)
     data_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(data_datagram.data, 'line1')
     self.failIf(self.rs.completed,
                 "Got enough bytes from the reader, there is no reason to stop")
Beispiel #17
0
 def test_invalid_tid(self):
     data_datagram = DATADatagram(1, b'foobar')
     self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
     self.clock.advance(0.1)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
     self.addCleanup(self.rs.cancel)
Beispiel #18
0
 def datagramReceived(self, datagram, addr):
     if self.remote[1] != addr[1]:
         self.transport.write(ERRORDatagram.from_code(ERR_TID_UNKNOWN).to_wire())
         return# Does not belong to this transfer
     datagram = TFTPDatagramFactory(*split_opcode(datagram))
     if datagram.opcode == OP_ERROR:
         return self.tftp_ERROR(datagram)
     return self._datagramReceived(datagram)
Beispiel #19
0
    def test_invalid_tid(self):
        self.ws.startProtocol()
        bad_tid_dgram = ACKDatagram(123)
        self.ws.datagramReceived(bad_tid_dgram.to_wire(), ('127.0.0.1', 1111))

        err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
        self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
        self.addCleanup(self.ws.cancel)
 def test_bad_mode(self):
     tftp = TFTP(DummyBackend(), _clock=self.clock)
     tftp.transport = self.transport
     wrq_datagram = WRQDatagram(b'foobar', b'badmode', {})
     tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
     error_datagram = TFTPDatagramFactory(
         *split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
    def test_access_violation(self):
        tftp = TFTP(BackendFactory(AccessViolation("No!")), _clock=self.clock)
        tftp.transport = self.transport
        wrq_datagram = WRQDatagram(b'foobar', b'netascii', {})
        tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)

        self.transport.clear()
        rrq_datagram = RRQDatagram(b'foobar', b'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)
    def test_unsupported(self):
        tftp = TFTP(BackendFactory(Unsupported("I don't support you")),
                    _clock=self.clock)
        tftp.transport = self.transport
        wrq_datagram = WRQDatagram(b'foobar', b'netascii', {})
        tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)

        self.transport.clear()
        rrq_datagram = RRQDatagram(b'foobar', b'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
    def test_generic_backend_error(self):
        tftp = TFTP(BackendFactory(BackendError("A backend that couldn't")),
                    _clock=self.clock)
        tftp.transport = self.transport
        rrq_datagram = RRQDatagram(b'foobar', b'netascii', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)

        self.transport.clear()
        rrq_datagram = RRQDatagram(b'foobar', b'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)
Beispiel #24
0
 def test_DATA_invalid_blocknum(self):
     self.ws.block_size = 6
     data_datagram = DATADatagram(3, 'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.writer.finish()
     self.failIf(self.target.open('r').read())
     self.failIf(self.transport.disconnecting)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assert_(isinstance(err_dgram, ERRORDatagram))
     self.addCleanup(self.ws.cancel)
 def test_file_exists(self):
     tftp = TFTP(BackendFactory(FileExists("Already have one")),
                 _clock=self.clock)
     tftp.transport = self.transport
     wrq_datagram = WRQDatagram(b'foobar', b'netascii', {})
     tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
     self.clock.advance(1)
     error_datagram = TFTPDatagramFactory(
         *split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_FILE_EXISTS)
 def test_file_not_found(self):
     tftp = TFTP(BackendFactory(FileNotFound("Not found")),
                 _clock=self.clock)
     tftp.transport = self.transport
     rrq_datagram = RRQDatagram(b'foobar', b'netascii', {})
     tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
     self.clock.advance(1)
     error_datagram = TFTPDatagramFactory(
         *split_opcode(self.transport.value()))
     self.assertEqual(error_datagram.errorcode, ERR_FILE_NOT_FOUND)
Beispiel #27
0
 def test_failed_write(self):
     self.writer.cancel()
     self.ws.writer = FailingWriter()
     data_datagram = DATADatagram(1, 'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.flushLoggedErrors()
     self.clock.advance(0.1)
     err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.failUnless(isinstance(err_datagram, ERRORDatagram))
     self.failUnless(self.transport.disconnecting)
Beispiel #28
0
 def test_failed_write(self):
     self.writer.cancel()
     self.ws.writer = FailingWriter()
     data_datagram = DATADatagram(1, 'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.flushLoggedErrors()
     self.clock.advance(0.1)
     err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.failUnless(isinstance(err_datagram, ERRORDatagram))
     self.failUnless(self.transport.disconnecting)
Beispiel #29
0
 def test_DATA_invalid_blocknum(self):
     self.ws.block_size = 6
     data_datagram = DATADatagram(3, b'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.writer.finish()
     self.assertFalse(self.target.open('r').read())
     self.assertFalse(self.transport.disconnecting)
     err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertTrue(isinstance(err_dgram, ERRORDatagram))
     self.addCleanup(self.ws.cancel)
Beispiel #30
0
 def test_failed_read(self):
     self.reader.finish()
     self.rs.reader = FailingReader()
     self.rs.blocknum = 1
     ack_datagram = ACKDatagram(1)
     yield self.rs.datagramReceived(ack_datagram)
     self.flushLoggedErrors()
     self.clock.advance(0.1)
     err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.failUnless(isinstance(err_datagram, ERRORDatagram))
     self.failUnless(self.transport.disconnecting)
Beispiel #31
0
        def cb(res):
            self.clock.advance(0.1)
            self.assertEqual(self.target.open('r').read(), 'foo')
            ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.failUnless(isinstance(ack_dgram, ACKDatagram))
            self.failUnless(self.ws.completed,
                        "Data length is less, than blocksize, time to stop")
            self.transport.clear()

            # Send another datagram after the transfer is considered complete
            data_datagram = DATADatagram(2, 'foobar')
            self.ws.datagramReceived(data_datagram)
            self.assertEqual(self.target.open('r').read(), 'foo')
            err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.failUnless(isinstance(err_dgram, ERRORDatagram))

            # Check for proper disconnection after grace timeout expires
            self.clock.pump((4,)*4)
            self.failUnless(self.transport.disconnecting,
                "We are done and the grace timeout is over, should disconnect")
Beispiel #32
0
        def cb(res):
            self.clock.advance(0.1)
            self.assertEqual(self.target.open('r').read(), 'foo')
            ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.failUnless(isinstance(ack_dgram, ACKDatagram))
            self.failUnless(self.ws.completed,
                        "Data length is less, than blocksize, time to stop")
            self.transport.clear()

            # Send another datagram after the transfer is considered complete
            data_datagram = DATADatagram(2, 'foobar')
            self.ws.datagramReceived(data_datagram)
            self.assertEqual(self.target.open('r').read(), 'foo')
            err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.failUnless(isinstance(err_dgram, ERRORDatagram))

            # Check for proper disconnection after grace timeout expires
            self.clock.pump((4,)*4)
            self.failUnless(self.transport.disconnecting,
                "We are done and the grace timeout is over, should disconnect")
Beispiel #33
0
 def test_failed_read(self):
     self.reader.finish()
     self.rs.reader = FailingReader()
     self.rs.blocknum = 1
     ack_datagram = ACKDatagram(1)
     yield self.rs.datagramReceived(ack_datagram)
     self.flushLoggedErrors()
     self.clock.advance(0.1)
     err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.failUnless(isinstance(err_datagram, ERRORDatagram))
     self.failUnless(self.transport.disconnecting)
Beispiel #34
0
 def test_DATA_stale_blocknum(self):
     self.ws.block_size = 6
     self.ws.blocknum = 2
     data_datagram = DATADatagram(1, 'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.writer.finish()
     self.failIf(self.target.open('r').read())
     self.failIf(self.transport.disconnecting)
     ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(ack_dgram.blocknum, 1)
     self.addCleanup(self.ws.cancel)
Beispiel #35
0
 def datagramReceived(self, datagram, addr):
     if self.remote[1] != addr[1]:
         self.transport.write(ERRORDatagram.from_code(ERR_TID_UNKNOWN).to_wire())
         return# Does not belong to this transfer
     datagram = TFTPDatagramFactory(*split_opcode(datagram))
     # TODO: Disabled for the time being. Performance degradation
     # and log file swamping was reported.
     # log.msg("Datagram received from %s: %s" % (addr, datagram))
     if datagram.opcode == OP_ERROR:
         return self.tftp_ERROR(datagram)
     return self._datagramReceived(datagram)
Beispiel #36
0
 def datagramReceived(self, datagram, addr):
     if self.remote[1] != addr[1]:
         self.transport.write(ERRORDatagram.from_code(ERR_TID_UNKNOWN).to_wire())
         return# Does not belong to this transfer
     datagram = TFTPDatagramFactory(*split_opcode(datagram))
     # TODO: Disabled for the time being. Performance degradation
     # and log file swamping was reported.
     # log.msg("Datagram received from %s: %s" % (addr, datagram))
     if datagram.opcode == OP_ERROR:
         return self.tftp_ERROR(datagram)
     return self._datagramReceived(datagram)
Beispiel #37
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                "Unknown transfer mode %s, - expected "
                "'netascii' or 'octet' (case-insensitive)" % mode).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
Beispiel #38
0
 def test_DATA_stale_blocknum(self):
     self.ws.block_size = 6
     self.ws.blocknum = 2
     data_datagram = DATADatagram(1, b'foobar')
     yield self.ws.datagramReceived(data_datagram)
     self.writer.finish()
     self.assertFalse(self.target.open('r').read())
     self.assertFalse(self.transport.disconnecting)
     ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
     self.assertEqual(ack_dgram.blocknum, 1)
     self.addCleanup(self.ws.cancel)
Beispiel #39
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if mode not in (b'netascii', b'octet'):
            errmsg = (
                u"Unknown transfer mode '%s', - expected 'netascii' or 'octet'"
                u"(case-insensitive)" % mode.decode("ascii"))
            return self.transport.write(ERRORDatagram.from_code(
                ERR_ILLEGAL_OP, errmsg.encode("ascii", "replace")).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
Beispiel #40
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(
                ERRORDatagram.from_code(
                    ERR_ILLEGAL_OP, "Unknown transfer mode %s, - expected "
                    "'netascii' or 'octet' (case-insensitive)" %
                    mode).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
Beispiel #41
0
        def cb(ign):
            self.clock.advance(0.1)
            # self.writer.finish()
            # self.assertEqual(self.target.open('r').read(), 'foobar')
            self.failIf(self.transport.disconnecting)
            ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.assertEqual(ack_dgram.blocknum, 1)
            self.failIf(self.ws.completed, "Data length is equal to blocksize, no reason to stop")
            data_datagram = DATADatagram(2, "barbaz")

            self.transport.clear()
            d = self.ws.datagramReceived(data_datagram)
            d.addCallback(cb_)
            self.clock.advance(3)
            return d
Beispiel #42
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if mode not in (b'netascii', b'octet'):
            errmsg = (
                u"Unknown transfer mode '%s', - expected 'netascii' or 'octet'"
                u"(case-insensitive)" % mode.decode("ascii"))
            return self.transport.write(
                ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                                        errmsg.encode("ascii",
                                                      "replace")).to_wire(),
                addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
Beispiel #43
0
        def cb(ign):
            self.clock.advance(0.1)
            #self.writer.finish()
            #self.assertEqual(self.target.open('r').read(), 'foobar')
            self.failIf(self.transport.disconnecting)
            ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
            self.assertEqual(ack_dgram.blocknum, 1)
            self.failIf(self.ws.completed,
                        "Data length is equal to blocksize, no reason to stop")
            data_datagram = DATADatagram(2, 'barbaz')

            self.transport.clear()
            d = self.ws.datagramReceived(data_datagram)
            d.addCallback(cb_)
            self.clock.advance(3)
            return d
Beispiel #44
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                "Unknown transfer mode %s, - expected "
                "'netascii' or 'octet' (case-insensitive)" % mode).to_wire(), addr)
        try:
            if datagram.opcode == OP_WRQ:
                fs_interface = self.backend.get_writer(datagram.filename)
            elif datagram.opcode == OP_RRQ:
                fs_interface = self.backend.get_reader(datagram.filename)
        except Unsupported, e:
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                                    str(e)).to_wire(), addr)
Beispiel #45
0
    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        if datagram.opcode not in (OP_WRQ, OP_RRQ):
            log.msg(
                "Datagram with unexpected opcode %s was received without establishing "
                "the session. Ignoring." % datagram.opcode)
            return

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(
                ERRORDatagram.from_code(
                    ERR_ILLEGAL_OP, "Unknown transfer mode %s, - expected "
                    "'netascii' or 'octet' (case-insensitive)" %
                    mode).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
Beispiel #46
0
 def test_wrq(self):
     self.assertEqual(TFTPDatagramFactory(*split_opcode('\x00\x02foo\x00bar')).to_wire(),
                      '\x00\x02foo\x00bar\x00')
Beispiel #47
0
 def test_non_empty_payload(self):
     self.assertEqual(split_opcode('\x00\x01foo'), (1, 'foo'))
Beispiel #48
0
 def test_empty_payload(self):
     self.assertEqual(split_opcode('\x00\x01'), (1, ''))
Beispiel #49
0
 def test_empty_payload(self):
     self.assertEqual(split_opcode('\x00\x01'), (1, ''))
 def test_non_empty_payload(self):
     self.assertEqual(split_opcode(b'\x00\x01foo'), (1, b'foo'))
 def test_wrq(self):
     self.assertEqual(
         TFTPDatagramFactory(
             *split_opcode(b'\x00\x02foo\x00bar')).to_wire(),
         b'\x00\x02foo\x00bar\x00')