Esempio n. 1
0
def test_lsof_good_v2():
    ctx = context_wrap(LSOF_GOOD_V2)
    d = list(lsof.Lsof(ctx).parse(LSOF_GOOD_V2.splitlines()))
    assert d[0] == {
        'COMMAND': 'systemd',
        'PID': '1',
        'USER': '******',
        'FD': 'cwd',
        'TYPE': 'DIR',
        'DEVICE': '253,0',
        'SIZE/OFF': '251',
        'NODE': '128',
        'NAME': '/'
    }

    # wide and empty values checks
    assert d[2]['DEVICE'] == '0xffff998f20251f80'
    assert d[3]['DEVICE'] == ''

    assert d[-1] == {
        'COMMAND': 'rsyslogd',
        'PID': '772018',
        'USER': '******',
        'FD': '5w',
        'TYPE': 'REG',
        'DEVICE': '253,6',
        'SIZE/OFF': '151175680',
        'NODE': '1351',
        'NAME': '/var/log/messages-20210221 (deleted)'
    }
Esempio n. 2
0
def test_lsof():
    ctx = context_wrap(LSOF)
    d = list(lsof.Lsof(ctx).parse(LSOF.splitlines()))

    assert set(columns) == set([k for f in d for k in f.keys()])
    assert d[0] == {
        "COMMAND": "systemd",
        "PID": "1",
        "TID": "",
        "USER": "******",
        "FD": "cwd",
        "TYPE": "DIR",
        "DEVICE": "253,1",
        "SIZE/OFF": "4096",
        "NODE": "128",
        "NAME": "/"
    }

    # Spot checks
    assert d[3]["TID"] == ""
    assert d[4]["TID"] == "688"
    assert d[5]["TYPE"] == "REG"
    assert d[7]["NAME"] == "/proc/611/exe"

    assert d[-2] == {
        "COMMAND": "bioset",
        "PID": "611",
        "TID": "",
        "USER": "******",
        "FD": "txt",
        "TYPE": "unknown",
        "DEVICE": "",
        "SIZE/OFF": "",
        "NODE": "",
        "NAME": "/proc/611/exe"
    }
    assert d[-1] == {
        "COMMAND": "systemd",
        "PID": "1",
        "TID": "",
        "USER": "******",
        "FD": "cwd",
        "TYPE": "DIR",
        "DEVICE": "253,1",
        "SIZE/OFF": "4096",
        "NODE": "128",
        "NAME": "/"
    }
Esempio n. 3
0
def test_lsof_good():
    ctx = context_wrap(LSOF_GOOD_V1)
    d = list(lsof.Lsof(ctx).parse(LSOF_GOOD_V1.splitlines()))
    assert d[0] == {
        "COMMAND": "systemd-l",
        "PID": "602",
        "TID": "",
        "USER": "******",
        "FD": "14u",
        "TYPE": "CHR",
        "DEVICE": "13,64",
        "SIZE/OFF": "0t0",
        "NODE": "6406",
        "NAME": "/dev/input/event0"
    }

    # Spot checks
    assert d[3]["TID"] == ""
    assert d[4]["TID"] == "615"
    assert d[5]["COMMAND"] == "abrt-watc"
    assert d[5]["PID"] == "8619"
    assert d[5]["TYPE"] == "CHR"
    assert d[7]["NAME"] == "/dev/null"

    assert d[-1] == {
        "COMMAND": "JS",
        "PID": "642",
        "TID": "648",
        "USER": "******",
        "FD": "2u",
        "TYPE": "CHR",
        "DEVICE": "1,3",
        "SIZE/OFF": "0t0",
        "NODE": "4674",
        "NAME": "/dev/null"
    }
Esempio n. 4
0
def test_lsof_scan():
    ctx = context_wrap(LSOF_GOOD_V1)
    # Scannable provided `any` method
    lsof.Lsof.any('systemd_commands', lambda x: 'systemd' in x['COMMAND'])
    # Scannable provided `collect` method
    lsof.Lsof.collect('polkitd_user', lambda x: x['USER'] == 'polkitd')
    # Lsof provided `collect_keys` method
    lsof.Lsof.collect_keys('root_stdin', USER='******', FD='0r', SIZE_OFF='0t0')
    l = lsof.Lsof(ctx)
    assert l.systemd_commands
    assert len(l.polkitd_user) == 12

    assert hasattr(l, 'root_stdin')
    assert len(l.root_stdin) == 2

    assert l.root_stdin[0]['COMMAND'] == 'abrt-watc'
    assert l.root_stdin[0]['PID'] == '8619'
    assert l.root_stdin[0]['TID'] == ''
    assert l.root_stdin[0]['USER'] == 'root'
    assert l.root_stdin[0]['FD'] == '0r'
    assert l.root_stdin[0]['TYPE'] == 'CHR'
    assert l.root_stdin[0]['DEVICE'] == '1,3'
    assert l.root_stdin[0]['SIZE/OFF'] == '0t0'
    assert l.root_stdin[0]['NODE'] == '4674'
    assert l.root_stdin[0]['NAME'] == '/dev/null'

    assert l.root_stdin[1]['COMMAND'] == 'wpa_suppl'
    assert l.root_stdin[1]['PID'] == '641'
    assert l.root_stdin[1]['TID'] == ''
    assert l.root_stdin[1]['USER'] == 'root'
    assert l.root_stdin[1]['FD'] == '0r'
    assert l.root_stdin[1]['TYPE'] == 'CHR'
    assert l.root_stdin[1]['DEVICE'] == '1,3'
    assert l.root_stdin[1]['SIZE/OFF'] == '0t0'
    assert l.root_stdin[1]['NODE'] == '4674'
    assert l.root_stdin[1]['NAME'] == '/dev/null'
Esempio n. 5
0
def test_lsof_bad():
    with pytest.raises(SkipComponent) as e:
        lsof.Lsof(context_wrap(LSOF_BAD))
    assert e is not None