Example #1
0
def test_parse_line_hosts_negated():
    """Negated line hosts should remove the negation."""
    assert KnownHostsQuery.parse_line_hosts('!host1') == ({'host1'}, set())
    expected = ({'host1', 'host2'}, set())
    assert KnownHostsQuery.parse_line_hosts('!host1,host2') == expected
    assert KnownHostsQuery.parse_line_hosts('host1,!host2') == expected
    assert KnownHostsQuery.parse_line_hosts('!host1,!host2') == expected
Example #2
0
def test_parse_line_hosts_neg_port():
    """Line hosts with custom ports and negated entries should remove the additional syntax."""
    assert KnownHostsQuery.parse_line_hosts('![host1]:2222') == ({'host1'},
                                                                 set())
    expected = ({'host1', 'host2'}, set())
    assert KnownHostsQuery.parse_line_hosts('![host1]:2222,!host2') == expected
    assert KnownHostsQuery.parse_line_hosts('!host1,![host2]:2222') == expected
    assert KnownHostsQuery.parse_line_hosts(
        '![host1]:2222,![host2]:2222') == expected
Example #3
0
def test_parse_line_hosts_port():
    """Line hosts with custom ports should remove the additional syntax."""
    assert KnownHostsQuery.parse_line_hosts('[host1]:2222') == ({'host1'},
                                                                set())
    expected = ({'host1', 'host2'}, set())
    assert KnownHostsQuery.parse_line_hosts('[host1]:2222,host2') == expected
    assert KnownHostsQuery.parse_line_hosts('host1,[host2]:2222') == expected
    assert KnownHostsQuery.parse_line_hosts(
        '[host1]:2222,[host2]:2222') == expected
Example #4
0
def test_parse_line_hosts_patterns():
    """Line hosts with patterns should skip the patterns entries."""
    assert KnownHostsQuery.parse_line_hosts('host?') == (set(), {'host?'})
    assert KnownHostsQuery.parse_line_hosts('host*') == (set(), {'host*'})
    assert KnownHostsQuery.parse_line_hosts('host?,host2') == ({'host2'},
                                                               {'host?'})
    assert KnownHostsQuery.parse_line_hosts('host*,host2') == ({'host2'},
                                                               {'host*'})
    assert KnownHostsQuery.parse_line_hosts('host*,host2,host?') == ({
        'host2'
    }, {'host?', 'host*'})
Example #5
0
def test_parse_line_hosts_ips():
    """Line hosts with IPs should skip the IP entries."""
    assert KnownHostsQuery.parse_line_hosts('127.0.1.1') == (set(),
                                                             {'127.0.1.1'})
    assert KnownHostsQuery.parse_line_hosts('fe80::1') == (set(), {'fe80::1'})
    assert KnownHostsQuery.parse_line_hosts('host1,127.0.1.1') == ({'host1'}, {
        '127.0.1.1'
    })
    assert KnownHostsQuery.parse_line_hosts('host1,fe80::1') == ({'host1'},
                                                                 {'fe80::1'})
    assert KnownHostsQuery.parse_line_hosts('host1,127.0.1.1,fe80::1') == ({
        'host1'
    }, {'127.0.1.1', 'fe80::1'})
Example #6
0
def test_parse_line_hosts_empty():
    """Empty line hosts should be skipped."""
    assert KnownHostsQuery.parse_line_hosts(',') == (set(), set())
    assert KnownHostsQuery.parse_line_hosts('host1,,') == ({'host1'}, set())