예제 #1
0
 def setUp(self):
     self.proto = TFTPBootstrap(('127.0.0.1', 1111), None)
예제 #2
0
class TestOptionProcessing(unittest.TestCase):

    def setUp(self):
        self.proto = TFTPBootstrap(('127.0.0.1', 1111), None)

    def test_empty_options(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict())
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(self.s.timeout, (1, 3, 5))

    def test_blksize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'8'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 8)
        self.assertEqual(opts, OrderedDict({'blksize':'8'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'65464'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, MAX_BLOCK_SIZE)
        self.assertEqual(opts, OrderedDict({'blksize':str(MAX_BLOCK_SIZE)}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'65465'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'7'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

    def test_timeout(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 1, 1))
        self.assertEqual(opts, OrderedDict({'timeout':'1'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'0'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'255'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (255, 255, 255))
        self.assertEqual(opts, OrderedDict({'timeout':'255'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'256'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

    def test_tsize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.tsize, 1)
        self.assertEqual(opts, OrderedDict({'tsize':'1'}))

    def test_tsize_ignored_when_not_a_number(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertIsNone(self.s.tsize)
        self.assertEqual(opts, OrderedDict({}))

    def test_tsize_ignored_when_less_than_zero(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'-1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertIsNone(self.s.tsize)
        self.assertEqual(opts, OrderedDict({}))

    def test_multiple_options(self):
        got_options = OrderedDict()
        got_options['timeout'] = '123'
        got_options['blksize'] = '1024'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options['blksize'] = '1024'
        got_options['timeout'] = '123'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options['blksize'] = '1024'
        got_options['foobar'] = 'barbaz'
        got_options['timeout'] = '123'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        actual_options = OrderedDict()
        actual_options['blksize'] = '1024'
        actual_options['timeout'] = '123'
        self.assertEqual(opts.items(), actual_options.items())
예제 #3
0
class TestOptionProcessing(unittest.TestCase):

    def setUp(self):
        self.proto = TFTPBootstrap(('127.0.0.1', 1111), None)

    def test_empty_options(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict())
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(self.s.timeout, (1, 3, 5))

    def test_blksize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'8'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 8)
        self.assertEqual(opts, OrderedDict({'blksize':'8'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'65464'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, MAX_BLOCK_SIZE)
        self.assertEqual(opts, OrderedDict({'blksize':str(MAX_BLOCK_SIZE)}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'65465'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'blksize':'7'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

    def test_timeout(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 1, 1))
        self.assertEqual(opts, OrderedDict({'timeout':'1'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'0'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'255'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (255, 255, 255))
        self.assertEqual(opts, OrderedDict({'timeout':'255'}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'timeout':'256'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

    def test_tsize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.tsize, 1)
        self.assertEqual(opts, OrderedDict({'tsize':'1'}))

    def test_tsize_ignored_when_not_a_number(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'foo'}))
        self.proto.applyOptions(self.s, opts)
        self.assertTrue(self.s.tsize is None)
        self.assertEqual(opts, OrderedDict({}))

    def test_tsize_ignored_when_less_than_zero(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({'tsize':'-1'}))
        self.proto.applyOptions(self.s, opts)
        self.assertTrue(self.s.tsize is None)
        self.assertEqual(opts, OrderedDict({}))

    def test_multiple_options(self):
        got_options = OrderedDict()
        got_options['timeout'] = '123'
        got_options['blksize'] = '1024'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options['blksize'] = '1024'
        got_options['timeout'] = '123'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options['blksize'] = '1024'
        got_options['foobar'] = 'barbaz'
        got_options['timeout'] = '123'
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        actual_options = OrderedDict()
        actual_options['blksize'] = '1024'
        actual_options['timeout'] = '123'
        self.assertEqual(opts.items(), actual_options.items())
예제 #4
0
 def setUp(self):
     self.proto = TFTPBootstrap(('127.0.0.1', 1111), None)
예제 #5
0
class TestOptionProcessing(unittest.TestCase):
    def setUp(self):
        self.proto = TFTPBootstrap(("127.0.0.1", 1111), None)

    def test_empty_options(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict())
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(self.s.timeout, (1, 3, 5))

    def test_blksize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"blksize": "8"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 8)
        self.assertEqual(opts, OrderedDict({"blksize": "8"}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"blksize": "foo"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"blksize": "65464"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, MAX_BLOCK_SIZE)
        self.assertEqual(opts, OrderedDict({"blksize": str(MAX_BLOCK_SIZE)}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"blksize": "65465"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"blksize": "7"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.block_size, 512)
        self.assertEqual(opts, OrderedDict())

    def test_timeout(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"timeout": "1"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 1, 1))
        self.assertEqual(opts, OrderedDict({"timeout": "1"}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"timeout": "foo"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"timeout": "0"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"timeout": "255"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (255, 255, 255))
        self.assertEqual(opts, OrderedDict({"timeout": "255"}))

        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"timeout": "256"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (1, 3, 5))
        self.assertEqual(opts, OrderedDict())

    def test_tsize(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"tsize": "1"}))
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.tsize, 1)
        self.assertEqual(opts, OrderedDict({"tsize": "1"}))

    def test_tsize_ignored_when_not_a_number(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"tsize": "foo"}))
        self.proto.applyOptions(self.s, opts)
        self.assertTrue(self.s.tsize is None)
        self.assertEqual(opts, OrderedDict({}))

    def test_tsize_ignored_when_less_than_zero(self):
        self.s = MockSession()
        opts = self.proto.processOptions(OrderedDict({"tsize": "-1"}))
        self.proto.applyOptions(self.s, opts)
        self.assertTrue(self.s.tsize is None)
        self.assertEqual(opts, OrderedDict({}))

    def test_multiple_options(self):
        got_options = OrderedDict()
        got_options["timeout"] = "123"
        got_options["blksize"] = "1024"
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options["blksize"] = "1024"
        got_options["timeout"] = "123"
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        self.assertEqual(opts.items(), got_options.items())

        got_options = OrderedDict()
        got_options["blksize"] = "1024"
        got_options["foobar"] = "barbaz"
        got_options["timeout"] = "123"
        self.s = MockSession()
        opts = self.proto.processOptions(got_options)
        self.proto.applyOptions(self.s, opts)
        self.assertEqual(self.s.timeout, (123, 123, 123))
        self.assertEqual(self.s.block_size, 1024)
        actual_options = OrderedDict()
        actual_options["blksize"] = "1024"
        actual_options["timeout"] = "123"
        self.assertEqual(opts.items(), actual_options.items())