Esempio n. 1
0
def test_from_fs_to_wfn_errors():
    errors = [
        'cpe:2.3:a:hp:insight_diagnostics:7.4.*.1570:*:*:*:*:*:*',
    ]
    with pytest.raises(CpeParseException):
        for s in errors:
            CPE.from_string(s)
Esempio n. 2
0
def test_from_fs_to_wfn_errors():
    errors = [
        'cpe:2.3:a:hp:insight_diagnostics:7.4.*.1570:*:*:*:*:*:*',
    ]
    with pytest.raises(CpeParseException):
        for s in errors:
            CPE.from_string(s)
Esempio n. 3
0
def test_from_uri_to_wfn_error():
    errors = [
        'cpe:/a:foo%5cbar:big%24money_2010%07:::~~special~ipod_touch~80gb~',
        'cpe:/a:foo:bar:12.%02.1234',
    ]
    for s in errors:
        with pytest.raises(CpeParseException):
            CPE.from_string(s).to_uri_string()
Esempio n. 4
0
def test_from_uri_to_wfn_error():
    errors = [
        'cpe:/a:foo%5cbar:big%24money_2010%07:::~~special~ipod_touch~80gb~',
        'cpe:/a:foo:bar:12.%02.1234',
    ]
    for s in errors:
        with pytest.raises(CpeParseException):
            CPE.from_string(s).to_uri_string()
Esempio n. 5
0
def test_from_uri():
    cpe = CPE.from_string('cpe:/a:microsoft:internet_explorer')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other:EN-us'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.get_value_middle('language') == 'EN-us'

    cpe = CPE.from_string(
        'cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.is_value_any('language') == True
Esempio n. 6
0
def test_from_fs():
    cpe = CPE.from_string('cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*')
    # 'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.0.6001'
    assert cpe.get_value_middle('update') == 'beta'
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*')
    # 'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.'
    assert cpe.value_ends_with_any('version') == True
    assert cpe.get_value_middle('update') == 'sp'
    assert cpe.get_singles_after_value('update') == 1
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*')
    # 'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,edition=ANY,sw_edition="online",target_sw="win2003",target_hw="x64",other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'insight_diagnostics'
    assert cpe.get_value_middle('version') == '7.4.0.1570'
    assert cpe.is_value_na('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'online'
    assert cpe.get_value_middle('target_sw') == 'win2003'
    assert cpe.get_value_middle('target_hw') == 'x64'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*')
    # 'wfn:[part="a",vendor="foo\\bar",product="big\$money",version="2010",update=ANY,edition=ANY,sw_edition="special",target_sw="ipod_touch",target_hw="80gb",other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True
Esempio n. 7
0
def test_from_uri():
    cpe = CPE.from_string('cpe:/a:microsoft:internet_explorer')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other:EN-us')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.get_value_middle('language') == 'EN-us'

    cpe = CPE.from_string('cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('cpe:/a:foo%5cbar:big%24money_manager_2010:2010:u5:~legacy_edition~special~ipod_touch~80gb~other')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_manager_2010'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.get_value_middle('update') == 'u5'
    assert cpe.get_value_middle('edition') == 'legacy_edition'
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.get_value_middle('other') == 'other'
    assert cpe.is_value_any('language') == True
Esempio n. 8
0
def test_from_wfn_to_wfn():
    tests = [
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=NA]',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=NA,language=ANY]',
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",sw_edition="online",target_sw="windows_2003",target_hw="x64"]',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",update=NA,target_sw="linux"]',
        'wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch"]',
    ]
    for s in tests:
        assert CPE.from_string(s).equal_to(CPE(s)) == True
Esempio n. 9
0
def test_from_wfn_to_wfn():
    tests = [
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=NA]',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=NA,language=ANY]',
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",sw_edition="online",target_sw="windows_2003",target_hw="x64"]',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",update=NA,target_sw="linux"]',
        'wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch"]',
    ]
    for s in tests:
        assert CPE.from_string(s).equal_to(CPE(s)) == True
Esempio n. 10
0
def test_from_fs_to_wfn():
    tests = {
        'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*':
            'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
        'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*':
            'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
        'cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*':
            'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,edition=ANY,sw_edition="online",target_sw="win2003",target_hw="x64",other=ANY,language=ANY]',
        r'cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*':
            r'wfn:[part="a",vendor="foo\\bar",product="big\$money",version="2010",update=ANY,edition=ANY,sw_edition="special",target_sw="ipod_touch",target_hw="80gb",other=ANY,language=ANY]',
    }
    for s in tests.keys():
        cpe = CPE.from_string(s)
        assert cpe.to_wfn_string() == tests[s]
Esempio n. 11
0
def test_from_fs_to_wfn():
    tests = {
        'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*':
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
        'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*':
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
        'cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*':
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,edition=ANY,sw_edition="online",target_sw="win2003",target_hw="x64",other=ANY,language=ANY]',
        r'cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*':
        r'wfn:[part="a",vendor="foo\\bar",product="big\$money",version="2010",update=ANY,edition=ANY,sw_edition="special",target_sw="ipod_touch",target_hw="80gb",other=ANY,language=ANY]',
    }
    for s in tests.keys():
        cpe = CPE.from_string(s)
        assert cpe.to_wfn_string() == tests[s]
Esempio n. 12
0
def test_from_wfn_to_uri():
    tests = {
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY]':
        'cpe:/a:microsoft:internet_explorer:8.0.6001:beta',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?"]':
        'cpe:/a:microsoft:internet_explorer:8.%02:sp%01',
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,sw_edition="online",target_sw="win2003",target_hw="x64"]':
        'cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",target_sw="linux"]':
        'cpe:/a:hp:openview_network_manager:7.51::~~~linux~~',
        'wfn:[part="a",vendor="foo\\bar",product="big\$money_manager_2010",sw_edition="special",target_sw="ipod_touch",target_hw="80gb"]':
        'cpe:/a:foo%5cbar:big%24money_manager_2010:::~~special~ipod_touch~80gb~',
    }
    for s in tests.keys():
        assert CPE.from_string(s).to_uri_string() == tests[s]
Esempio n. 13
0
def test_from_wfn_to_uri():
    tests = {
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY]':
            'cpe:/a:microsoft:internet_explorer:8.0.6001:beta',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?"]':
            'cpe:/a:microsoft:internet_explorer:8.%02:sp%01',
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,sw_edition="online",target_sw="win2003",target_hw="x64"]':
            'cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",target_sw="linux"]':
            'cpe:/a:hp:openview_network_manager:7.51::~~~linux~~',
        'wfn:[part="a",vendor="foo\\bar",product="big\$money_manager_2010",sw_edition="special",target_sw="ipod_touch",target_hw="80gb"]':
            'cpe:/a:foo%5cbar:big%24money_manager_2010:::~~special~ipod_touch~80gb~',
    }
    for s in tests.keys():
        assert CPE.from_string(s).to_uri_string() == tests[s]
Esempio n. 14
0
def test_from_wfn_to_fs():
    tests = {
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY]':
            'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY]':
            'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.\*",update="sp?"]':
            'cpe:2.3:a:microsoft:internet_explorer:8.\*:sp?:*:*:*:*:*:*',
        'wfn:[part="a",vendor="hp",product="insight",version="7\.4\.0\.1570",update=NA,sw_edition="online",target_sw="win2003",target_hw="x64"]':
            'cpe:2.3:a:hp:insight:7.4.0.1570:-:*:*:online:win2003:x64:*',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",target_sw="linux"]':
            'cpe:2.3:a:hp:openview_network_manager:7.51:*:*:*:*:linux:*:*',
        r'wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch",target_hw="80gb"]':
            r'cpe:2.3:a:foo\\bar:big\$money_2010:*:*:*:*:special:ipod_touch:80gb:*',
    }
    for s in tests.keys():
        assert CPE.from_string(s).to_fs_string() == tests[s]
Esempio n. 15
0
def test_from_wfn_to_fs():
    tests = {
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY]':
        'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY]':
        'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*',
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.\*",update="sp?"]':
        'cpe:2.3:a:microsoft:internet_explorer:8.\*:sp?:*:*:*:*:*:*',
        'wfn:[part="a",vendor="hp",product="insight",version="7\.4\.0\.1570",update=NA,sw_edition="online",target_sw="win2003",target_hw="x64"]':
        'cpe:2.3:a:hp:insight:7.4.0.1570:-:*:*:online:win2003:x64:*',
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",target_sw="linux"]':
        'cpe:2.3:a:hp:openview_network_manager:7.51:*:*:*:*:linux:*:*',
        r'wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch",target_hw="80gb"]':
        r'cpe:2.3:a:foo\\bar:big\$money_2010:*:*:*:*:special:ipod_touch:80gb:*',
    }
    for s in tests.keys():
        assert CPE.from_string(s).to_fs_string() == tests[s]
Esempio n. 16
0
def test_from_wfn():
    cpe = CPE.from_string('wfn:[part="a",vendor="microsoft",product="internet_explorer"]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=NA]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.0.6001'
    assert cpe.get_value_middle('update') == 'beta'
    assert cpe.is_value_na('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=NA,language=ANY]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.'
    assert cpe.value_ends_with_any('version') == True
    assert cpe.get_value_middle('update') == 'sp'
    assert cpe.get_singles_after_value('update') == 1
    assert cpe.is_value_na('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",sw_edition="online",target_sw="windows_2003",target_hw="x64"]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'insight_diagnostics'
    assert cpe.get_value_middle('version') == '7.4.0.1570'
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'online'
    assert cpe.get_value_middle('target_sw') == 'windows_2003'
    assert cpe.get_value_middle('target_hw') == 'x64'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",update=NA,target_sw="linux"]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'openview_network_manager'
    assert cpe.get_value_middle('version') == '7.51'
    assert cpe.is_value_na('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.get_value_middle('target_sw') == 'linux'
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string('wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch"]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_2010'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True
Esempio n. 17
0
    def collect(self):
        return_code, out_lines, err_lines = self.host.exec_command(
            'systeminfo')
        systeminfo = out_lines
        #self.host.facts['_systeminfo_lines'] = systeminfo

        if 'systeminfo' in self.host.facts:
            return
        self.host.facts['systeminfo'] = {}

        multiline = None
        cur_network_card = None
        ip_addresses = False
        for line in systeminfo:
            if re.match(r'^\s*$', line) is not None:
                continue

            if multiline is not None:
                if multiline == 'Processor(s)':
                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['processor'].append(
                            m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Page File Location(s)':
                    m = re.match(r'^\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['page_file'].append(
                            m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Hotfix(s)':
                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['hotfix'].append(
                            m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Network Card(s)':
                    if ip_addresses:
                        m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][
                                cur_network_card]['IP address(es)'].append(
                                    m.group(1))
                            continue
                        else:
                            ip_addresses = False

                    if cur_network_card is not None:
                        m = re.match(r'^\s+(IP address\(es\))\s*$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][
                                cur_network_card][m.group(1)] = []
                            ip_addresses = True
                            continue

                        m = re.match(r'^\s+(.+):\s+(.+)$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][
                                cur_network_card][m.group(1)] = m.group(2)
                            continue
                        else:
                            cur_network_card = None

                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['network_card'][m.group(
                            1)] = {}
                        cur_network_card = m.group(1)
                        continue
                    else:
                        multiline = None
                else:
                    raise RuntimeError('Unknown multiline mode: ' + multiline)

            m = re.match(r'^([^:]+):\s+(.*)$', line)
            if m is None:
                raise RuntimeError('Unexpected line: ' + line)

            if line.startswith('Processor(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['processor'] = []
            elif line.startswith('Page File Location(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['page_file'] = []
                self.host.facts['systeminfo']['page_file'].append(m.group(2))
            elif line.startswith('Hotfix(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['hotfix'] = []
            elif line.startswith('Network Card(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['network_card'] = {}
            elif line.startswith('Virtual Memory:'):
                m = re.match(r'^Virtual Memory: ([^:]+):\s+(.*)$', line)
                if 'virtual_memory' not in self.host.facts['systeminfo']:
                    self.host.facts['systeminfo']['virtual_memory'] = {}

                if m.group(1) == 'Max Size':
                    self.host.facts['systeminfo']['virtual_memory'][
                        'max_size'] = m.group(2)
                elif m.group(1) == 'Available':
                    self.host.facts['systeminfo']['virtual_memory'][
                        'available'] = m.group(2)
                elif m.group(1) == 'In Use':
                    self.host.facts['systeminfo']['virtual_memory'][
                        'in_use'] = m.group(2)
                else:
                    logger.warn('Unknown Virtual Memory section: ' +
                                m.group(1))
            elif line.startswith('Hyper-V Requirements:'):
                #TODO multiline?
                self.host.facts['systeminfo']['hyperv'] = m.group(2)
            elif m.group(1) in SystemInfoCollector.SECTION_MAP:
                self.host.facts['systeminfo'][SystemInfoCollector.SECTION_MAP[
                    m.group(1)]] = m.group(2)
                if m.group(1) == 'OS Name':
                    if m.group(2) in SystemInfoCollector.OS_NAME_MAP:
                        cpe = CPE.from_string(
                            SystemInfoCollector.OS_NAME_MAP[m.group(2)])
                        if cpe not in self.host.facts['cpe']['os']:
                            self.host.facts['cpe']['os'].append(cpe)
                    else:
                        logger.warn('Unable to determine CPE from OS name: ' +
                                    m.group(2))
            else:
                logger.warn('Unknown section: ' + m.group(1))
Esempio n. 18
0
def test_from_wfn():
    cpe = CPE.from_string(
        'wfn:[part="a",vendor="microsoft",product="internet_explorer"]')
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=NA]'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.0.6001'
    assert cpe.get_value_middle('update') == 'beta'
    assert cpe.is_value_na('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=NA,language=ANY]'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.'
    assert cpe.value_ends_with_any('version') == True
    assert cpe.get_value_middle('update') == 'sp'
    assert cpe.get_singles_after_value('update') == 1
    assert cpe.is_value_na('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",sw_edition="online",target_sw="windows_2003",target_hw="x64"]'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'insight_diagnostics'
    assert cpe.get_value_middle('version') == '7.4.0.1570'
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'online'
    assert cpe.get_value_middle('target_sw') == 'windows_2003'
    assert cpe.get_value_middle('target_hw') == 'x64'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'wfn:[part="a",vendor="hp",product="openview_network_manager",version="7\.51",update=NA,target_sw="linux"]'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'openview_network_manager'
    assert cpe.get_value_middle('version') == '7.51'
    assert cpe.is_value_na('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.get_value_middle('target_sw') == 'linux'
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'wfn:[part="a",vendor="foo\\bar",product="big\$money_2010",sw_edition="special",target_sw="ipod_touch"]'
    )
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money_2010'
    assert cpe.is_value_any('version') == True
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True
Esempio n. 19
0
    def collect(self):
        return_code, out_lines, err_lines = self.host.exec_command('systeminfo')
        systeminfo = out_lines
        #self.host.facts['_systeminfo_lines'] = systeminfo

        if 'systeminfo' in self.host.facts:
            return
        self.host.facts['systeminfo'] = {}

        multiline = None
        cur_network_card = None
        ip_addresses = False
        for line in systeminfo:
            if re.match(r'^\s*$', line) is not None:
                continue

            if multiline is not None:
                if multiline == 'Processor(s)':
                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['processor'].append(m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Page File Location(s)':
                    m = re.match(r'^\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['page_file'].append(m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Hotfix(s)':
                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['hotfix'].append(m.group(1))
                        continue

                    multiline = None
                elif multiline == 'Network Card(s)':
                    if ip_addresses:
                        m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][cur_network_card]['IP address(es)'].append(m.group(1))
                            continue
                        else:
                            ip_addresses = False

                    if cur_network_card is not None:
                        m = re.match(r'^\s+(IP address\(es\))\s*$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][cur_network_card][m.group(1)] = []
                            ip_addresses = True
                            continue

                        m = re.match(r'^\s+(.+):\s+(.+)$', line)
                        if m:
                            self.host.facts['systeminfo']['network_card'][cur_network_card][m.group(1)] = m.group(2)
                            continue
                        else:
                            cur_network_card = None

                    m = re.match(r'^\s+\[[0-9]+\]:\s+(.*)$', line)
                    if m:
                        self.host.facts['systeminfo']['network_card'][m.group(1)] = {}
                        cur_network_card = m.group(1)
                        continue
                    else:
                        multiline = None
                else:
                    raise RuntimeError('Unknown multiline mode: ' + multiline)

            m = re.match(r'^([^:]+):\s+(.*)$', line)
            if m is None:
                raise RuntimeError('Unexpected line: ' + line)

            if line.startswith('Processor(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['processor'] = []
            elif line.startswith('Page File Location(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['page_file'] = []
                self.host.facts['systeminfo']['page_file'].append(m.group(2))
            elif line.startswith('Hotfix(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['hotfix'] = []
            elif line.startswith('Network Card(s):'):
                multiline = m.group(1)
                self.host.facts['systeminfo']['network_card'] = {}
            elif line.startswith('Virtual Memory:'):
                m = re.match(r'^Virtual Memory: ([^:]+):\s+(.*)$', line)
                if 'virtual_memory' not in self.host.facts['systeminfo']:
                    self.host.facts['systeminfo']['virtual_memory'] = {}

                if m.group(1) == 'Max Size':
                    self.host.facts['systeminfo']['virtual_memory']['max_size'] = m.group(2)
                elif m.group(1) == 'Available':
                    self.host.facts['systeminfo']['virtual_memory']['available'] = m.group(2)
                elif m.group(1) == 'In Use':
                    self.host.facts['systeminfo']['virtual_memory']['in_use'] = m.group(2)
                else:
                    logger.warn('Unknown Virtual Memory section: ' + m.group(1))
            elif line.startswith('Hyper-V Requirements:'):
                #TODO multiline?
                self.host.facts['systeminfo']['hyperv'] = m.group(2)
            elif m.group(1) in SystemInfoCollector.SECTION_MAP:
                self.host.facts['systeminfo'][SystemInfoCollector.SECTION_MAP[m.group(1)]] = m.group(2)
                if m.group(1) == 'OS Name':
                    if m.group(2) in SystemInfoCollector.OS_NAME_MAP:
                        cpe = CPE.from_string(SystemInfoCollector.OS_NAME_MAP[m.group(2)])
                        if cpe not in self.host.facts['cpe']['os']:
                            self.host.facts['cpe']['os'].append(cpe)
                    else:
                        logger.warn('Unable to determine CPE from OS name: ' + m.group(2))
            else:
                logger.warn('Unknown section: ' + m.group(1))
Esempio n. 20
0
def test_from_fs():
    cpe = CPE.from_string(
        'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*')
    # 'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.0\.6001",update="beta",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.0.6001'
    assert cpe.get_value_middle('update') == 'beta'
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*')
    # 'wfn:[part="a",vendor="microsoft",product="internet_explorer",version="8\.*",update="sp?",edition=ANY,sw_edition=ANY,target_sw=ANY,target_hw=ANY,other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'microsoft'
    assert cpe.get_value_middle('product') == 'internet_explorer'
    assert cpe.get_value_middle('version') == '8.'
    assert cpe.value_ends_with_any('version') == True
    assert cpe.get_value_middle('update') == 'sp'
    assert cpe.get_singles_after_value('update') == 1
    assert cpe.is_value_any('edition') == True
    assert cpe.is_value_any('sw_edition') == True
    assert cpe.is_value_any('target_sw') == True
    assert cpe.is_value_any('target_hw') == True
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*'
    )
    # 'wfn:[part="a",vendor="hp",product="insight_diagnostics",version="7\.4\.0\.1570",update=NA,edition=ANY,sw_edition="online",target_sw="win2003",target_hw="x64",other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'hp'
    assert cpe.get_value_middle('product') == 'insight_diagnostics'
    assert cpe.get_value_middle('version') == '7.4.0.1570'
    assert cpe.is_value_na('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'online'
    assert cpe.get_value_middle('target_sw') == 'win2003'
    assert cpe.get_value_middle('target_hw') == 'x64'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True

    cpe = CPE.from_string(
        'cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*')
    # 'wfn:[part="a",vendor="foo\\bar",product="big\$money",version="2010",update=ANY,edition=ANY,sw_edition="special",target_sw="ipod_touch",target_hw="80gb",other=ANY,language=ANY]',
    assert cpe.get_value_middle('part') == 'a'
    assert cpe.get_value_middle('vendor') == 'foo\\bar'
    assert cpe.get_value_middle('product') == 'big$money'
    assert cpe.get_value_middle('version') == '2010'
    assert cpe.is_value_any('update') == True
    assert cpe.is_value_any('edition') == True
    assert cpe.get_value_middle('sw_edition') == 'special'
    assert cpe.get_value_middle('target_sw') == 'ipod_touch'
    assert cpe.get_value_middle('target_hw') == '80gb'
    assert cpe.is_value_any('other') == True
    assert cpe.is_value_any('language') == True