Пример #1
0
def test_check_flags():
    parser = Parser()
    valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = parser._check_flags({
                                                                                                                                 'fields': 'all'}, '')
    assert fields == [
        'ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4',
        'IPv4 Subnet', 'IPv6', 'IPv6 Subnet', 'Ethernet Vendor', 'Ignored',
        'State', 'Next State', 'First Seen', 'Last Seen',
        'Previous States', 'IPv4 OS\n(p0f)', 'IPv6 OS\n(p0f)', 'Previous IPv4 OSes\n(p0f)',
        'Previous IPv6 OSes\n(p0f)', 'Role\n(PoseidonML)', 'Role Confidence\n(PoseidonML)', 'Previous Roles\n(PoseidonML)',
        'Previous Role Confidences\n(PoseidonML)', 'Behavior\n(PoseidonML)', 'Previous Behaviors\n(PoseidonML)',
        'IPv4 rDNS', 'IPv6 rDNS', 'SDN Controller Type', 'SDN Controller URI'
    ]
    valid, fields, sort_by, max_width, unique, nonzero, output_format, ipv4_only, ipv6_only, ipv4_and_ipv6 = parser._check_flags(
        {'fields': ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'], 'sort_by': 1, 'max_width': 100, 'unique': True, 'nonzero': True, 'output_format': 'csv', '4': True, '6': True, '4and6': True}, '')
    assert fields == [
        'ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4',
    ]
    assert sort_by == 1
    assert max_width == 100
    assert unique == True
    assert nonzero == True
    assert output_format == 'csv'
    assert ipv4_only == False
    assert ipv6_only == False
    assert ipv4_and_ipv6 == True
Пример #2
0
def test_display_ip():
    parser = Parser()
    fields = ['foo', 'bar', 'IPv4', 'IPv6']
    assert ['foo', 'bar',
            'IPv4'] == parser.display_ip_filter(fields, True, False, False)
    assert ['foo', 'bar',
            'IPv6'] == parser.display_ip_filter(fields, False, True, False)
    assert fields == parser.display_ip_filter(fields, False, False, True)
Пример #3
0
def test_get_flags():
    parser = Parser()
    valid, flags, not_flags = parser.get_flags(
        'show all --fields=[id, mac] --sort_by=2 -4 --output_format=csv')
    assert flags == {
        'fields': ['id', 'mac'],
        'sort_by': '2',
        '4': True,
        'output_format': 'csv'
    }
    assert not_flags == 'show all'
Пример #4
0
def test_display_results():
    parser = Parser()
    endpoint = Endpoint('foo')
    endpoint.endpoint_data = {
        'tenant': 'foo',
        'mac': '00:00:00:00:00:00',
        'segment': 'foo',
        'port': '1',
        'ipv4': '0.0.0.0',
        'ipv6': '1212::1'
    }
    endpoints = [endpoint]
    parser.display_results(
        endpoints,
        ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4', 'IPv6'],
        ipv4_only=False,
        ipv6_only=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv6'],
        ipv4_only=False,
        ipv4_and_ipv6=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True)
Пример #5
0
def test_completion():
    parser = Parser()
    words = parser.completion('this is a test', 'this is a test', ['this'])
    assert words == []
Пример #6
0
def test_display_results():
    parser = Parser()
    endpoint = endpoint_factory('foo')
    endpoint.endpoint_data = {
        'vlan': 'foo',
        'mac': '00:00:00:00:00:00',
        'segment': 'foo',
        'port': '1',
        'ipv4': '0.0.0.0',
        'ipv6': '1212::1'
    }
    endpoints = [endpoint]
    parser.display_results(
        endpoints,
        ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4', 'IPv6'],
        ipv4_only=False,
        ipv6_only=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv6'],
        ipv4_only=False,
        ipv4_and_ipv6=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True,
        unique=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True,
        nonzero=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True,
        nonzero=True,
        unique=True)
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True,
        nonzero=True,
        unique=True,
        output_format='csv')
    parser.display_results(
        endpoints, ['ID', 'MAC Address', 'Switch', 'Port', 'VLAN', 'IPv4'],
        ipv4_only=False,
        ipv4_and_ipv6=True,
        nonzero=True,
        unique=True,
        output_format='json')
Пример #7
0
def test_get_flags():
    parser = Parser()
    flags, not_flags = parser.get_flags(
        'show all --fields=[id, mac] --sort_by=2 -4')
    assert flags == {'fields': ['id', 'mac'], 'sort_by': '2', '4': True}
    assert not_flags == 'show all'