Esempio n. 1
0
def test_ss_tulpn_get_port():
    ss = SsTULPN(context_wrap(Ss_TULPN))
    exp01 = [{
        'Netid': 'tcp',
        'Process': 'users:(("sshd",pid=1416,fd=4))',
        'Peer-Address-Port': ':::*',
        'Send-Q': '128',
        'Local-Address-Port': ':::2223',
        'State': 'LISTEN',
        'Recv-Q': '0'
    }]
    assert ss.get_localport("2223") == exp01
    exp02 = [{
        'Netid': 'udp',
        'Process': 'users:(("rpc.statd",pid=29559,fd=10))',
        'Peer-Address-Port': ':::12345',
        'Send-Q': '0',
        'Local-Address-Port': ':::37968',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert ss.get_peerport("12345") == exp02
    assert ss.get_port("12345") == exp02
    exp03 = [{
        'Netid': 'tcp',
        'Process': 'users:(("sshd",1231,3))',
        'Peer-Address-Port': '*:*',
        'Send-Q': '128',
        'Local-Address-Port': '*:22',
        'State': 'LISTEN',
        'Recv-Q': '0'
    }]
    assert ss.get_localport("22") == exp03
    assert ss.get_peerport("22") == []
    assert ss.get_port("22") == exp03
Esempio n. 2
0
def test_ss_tulpn_data():
    ss = SsTULPN(context_wrap(Ss_TULPN)).data
    assert len(ss) == 13
    assert ss[0] == {'Netid': 'udp', 'Peer-Address-Port': '*:*', 'Send-Q': '0', 'Local-Address-Port': '*:55898', 'State': 'UNCONN', 'Recv-Q': '0'}
    assert ss[1].get("Netid") == "udp"
    assert ss[9].get("Process") is None
    assert "sshd" in ss[-1].get("Process")
    assert "904" in ss[1].get("Local-Address-Port")
Esempio n. 3
0
def test_netstat_doc_examples():
    env = {
        'stats': NetstatS(context_wrap(NETSTAT_S)),
        'multicast': NetstatAGN(context_wrap(TEST_NETSTAT_AGN)),
        'ns': Netstat(context_wrap(NETSTAT_DOCS)),
        'traf': Netstat_I(context_wrap(NETSTAT_I)),
        'ss': SsTULPN(context_wrap(SS_TULPN_DOCS)),
    }
    failed, total = doctest.testmod(netstat, globs=env)
    assert failed == 0
Esempio n. 4
0
def test_ss_tulpn_get_service():
    ss = SsTULPN(context_wrap(Ss_TULPN))
    exp = [{
        'Netid': 'udp',
        'Process': 'users:(("rpcbind",pid=953,fd=9))',
        'Peer-Address-Port': '*:*',
        'Send-Q': '0',
        'Local-Address-Port': '*:111',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }, {
        'Netid': 'udp',
        'Process': 'users:(("rpcbind",pid=953,fd=11))',
        'Peer-Address-Port': ':::*',
        'Send-Q': '0',
        'Local-Address-Port': ':::111',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert ss.get_service("rpcbind") == exp
Esempio n. 5
0
def test_ss_tupnla_get_port():
    # Added test cases for testing two parser for one spec.
    # Used data from spec ss -tulpn and run parser SsTULPN(ss -tulpn)
    ssl = SsTULPN(context_wrap(SS_TULPN_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 22
    assert ssl.get_localport("34453") == exp02

    # Used data from spec ss -tupna and run parser SsTULPN(ss -tulpn)
    ssl = SsTULPN(context_wrap(SS_TUPNA_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 22
    assert ssl.get_localport("34453") == exp02

    # Used data from spec ss -tupna and run parser SsTUPNA(ss -tupna)
    ssl = SsTUPNA(context_wrap(SS_TUPNA_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 33
    assert ssl.get_localport("34453") == exp02