Ejemplo n.º 1
0
def test_supported_encode_tlv():
    '''Test inocybe_dhcp.options.Supported encodes tlv options'''
    supported = Supported()
    supported.add(_MockTlv('three', 3, 'foobar', b'\x05\x06\x07\x08'))
    ### encode of registered option with "good" value
    assert_equal([{
        'tag': 3,
        'length': 4,
        'value': b'\x05\x06\x07\x08',
    }], supported.encode([{
        'option': 'three',
        'value': 'baz',
    }]))
    ### encode of registered option with "bad" value
    assert_equal([{
        'option': 'three',
        'value': 'foobar',
    }], supported.encode([{
        'option': 'three',
        'value': 'foobar',
    }]))
    ### encode of unregistered option with arbitrary value
    assert_equal([{
        'tag': 4,
        'length': 4,
        'value': b'\x05\x06\x07\x08',
    }], supported.encode([{
        'tag': 4,
        'length': 4,
        'value': '05:06:07:08',
    }]))
Ejemplo n.º 2
0
def test_supported_decode_tag():
    '''Test inocybe_dhcp.options.Supported decodes tag options'''
    supported = Supported()
    supported.add(_MockTagOnly('two', 2))
    ### decode of registered option tag
    assert_equal([{'option': 'two'}], supported.decode([{'tag': 2}]))
    ### decode of unregistered option tag
    assert_equal([{'tag': 255}], supported.decode([{'tag': 255}]))
Ejemplo n.º 3
0
def test_supported_decode_tlv():
    '''Test inocybe_dhcp.options.Supported decodes tlv options'''
    supported = Supported()
    supported.add(_MockTlv('three', 3, b'\x00\x01\x02\x03', 'foo'))
    ### decode of registered option tag with "good" value
    assert_equal([{
        'option': 'three',
        'value': 'foo',
    }],
                 supported.decode([{
                     'tag': 3,
                     'length': 4,
                     'value': b'\x01\x02\x03\x04',
                 }]))
    ### decode of registered option tag with "bad" value
    assert_equal([{
        'tag': 3,
        'length': 4,
        'value': '00:01:02:03',
    }],
                 supported.decode([{
                     'tag': 3,
                     'length': 4,
                     'value': b'\x00\x01\x02\x03',
                 }]))
    ### decode of unregistered option tag with arbitrary value
    assert_equal([{
        'tag': 4,
        'length': 4,
        'value': '06:07:08:09',
    }],
                 supported.decode([{
                     'tag': 4,
                     'length': 4,
                     'value': b'\x06\x07\x08\x09',
                 }]))
Ejemplo n.º 4
0
def test_supported_decode_empty():
    '''Test inocybe_dhcp.options.Supported decodes empty options sequence'''
    supported = Supported()
    assert_equal([], supported.decode([]))
Ejemplo n.º 5
0
def test_supported_duplicate_tag():
    '''Test inocybe_dhcp.options.Supported rejects duplicate option tag'''
    supported = Supported()
    supported.add(_MockOption('first', 1))
    supported.add(_MockOption('second', 1))
Ejemplo n.º 6
0
def test_supported_duplicate_option():
    '''Test inocybe_dhcp.options.Supported rejects duplicate option name'''
    option = _MockOption('duplicate name', None)
    supported = Supported()
    supported.add(option)
    supported.add(option)