コード例 #1
0
def test_vuln_report():
    r = ImageVulnerabilityListing()
    r.image_id = 'image'
    r.user_id = 'user'
    r.cpe_report = [CpeVulnerability()]
    v = r.cpe_report[0]
    v.name = 'lib1'
    v.cpe = 'cpe:*:*'
    v.cpe23 = 'cpe2:*:*'
    v.version = '1.1'
    v.feed_name = 'nvdv2'
    v.feed_namespace = 'nvdv2:cpes'
    v.severity = 'High'
    v.vulnerability_id = 'CVE'
    v.vendor_data = [CvssCombined()]
    v.vendor_data[0].id = 'CVE-VENDOR'
    v.vendor_data[0].cvss_v2 = CvssScore()
    v.vendor_data[0].cvss_v2.base_score = 1.0
    v.vendor_data[0].cvss_v2.exploitability_score = 2.0
    v.vendor_data[0].cvss_v2.impact_score = 3.0
    v.vendor_data[0].cvss_v3 = CvssScore()
    v.vendor_data[0].cvss_v3.base_score = 1.0
    v.vendor_data[0].cvss_v3.exploitability_score = 2.0
    v.vendor_data[0].cvss_v3.impact_score = 3.0
    v.nvd_data = [CvssCombined()]
    v.nvd_data[0].id = 'CVE-NVD'
    v.nvd_data[0].cvss_v2 = CvssScore()
    v.nvd_data[0].cvss_v2.base_score = 1.1
    v.nvd_data[0].cvss_v2.exploitability_score = 2.2
    v.nvd_data[0].cvss_v2.impact_score = 3.3
    v.nvd_data[0].cvss_v3 = CvssScore()
    v.nvd_data[0].cvss_v3.base_score = 1.1
    v.nvd_data[0].cvss_v3.exploitability_score = 2.2
    v.nvd_data[0].cvss_v3.impact_score = 3.3
    r.legacy_report = LegacyVulnerabilityReport()
    r.legacy_report.multi = LegacyMultiReport()
    r.legacy_report.multi.result = LegacyTableReport()
    r.legacy_report.multi.result.colcount = 4
    r.legacy_report.multi.result.rowcount = 1
    r.legacy_report.multi.result.header = ['id', 'name', 'version', 'url']
    r.legacy_report.multi.result.rows = [[
        'CVE-NVD', 'lib1', '1.1', 'http://someurl'
    ]]
    r.legacy_report.multi.url_column_index = 3
    r.legacy_report.multi.warns = []

    assert r.to_json() == {
        'user_id':
        'user',
        'image_id':
        'image',
        'cpe_report': [{
            'cpe':
            'cpe:*:*',
            'cpe23':
            'cpe2:*:*',
            'pkg_path':
            None,
            'pkg_type':
            None,
            'feed_name':
            'nvdv2',
            'feed_namespace':
            'nvdv2:cpes',
            'version':
            '1.1',
            'name':
            'lib1',
            'link':
            None,
            'nvd_data': [{
                'id': 'CVE-NVD',
                'cvss_v2': {
                    'base_score': 1.1,
                    'exploitability_score': 2.2,
                    'impact_score': 3.3,
                },
                'cvss_v3': {
                    'base_score': 1.1,
                    'exploitability_score': 2.2,
                    'impact_score': 3.3
                }
            }],
            'vendor_data': [{
                'id': 'CVE-VENDOR',
                'cvss_v2': {
                    'base_score': 1.0,
                    'exploitability_score': 2.0,
                    'impact_score': 3.0,
                },
                'cvss_v3': {
                    'base_score': 1.0,
                    'exploitability_score': 2.0,
                    'impact_score': 3.0
                }
            }],
            'severity':
            'High',
            'vulnerability_id':
            'CVE',
        }],
        'legacy_report': {
            'multi': {
                'result': {
                    'colcount': 4,
                    'header': ['id', 'name', 'version', 'url'],
                    'rowcount': 1,
                    'rows': [['CVE-NVD', 'lib1', '1.1', 'http://someurl']]
                },
                'url_column_index': 3,
                'warns': []
            }
        }
    }
コード例 #2
0
def test_vuln_report():
    r = ImageVulnerabilityListing()
    r.image_id = "image"
    r.user_id = "user"
    r.cpe_report = [CpeVulnerability()]
    v = r.cpe_report[0]
    v.name = "lib1"
    v.cpe = "cpe:*:*"
    v.cpe23 = "cpe2:*:*"
    v.version = "1.1"
    v.feed_name = "nvdv2"
    v.feed_namespace = "nvdv2:cpes"
    v.severity = "High"
    v.vulnerability_id = "CVE"
    v.vendor_data = [CvssCombined()]
    v.vendor_data[0].id = "CVE-VENDOR"
    v.vendor_data[0].cvss_v2 = CvssScore()
    v.vendor_data[0].cvss_v2.base_score = 1.0
    v.vendor_data[0].cvss_v2.exploitability_score = 2.0
    v.vendor_data[0].cvss_v2.impact_score = 3.0
    v.vendor_data[0].cvss_v3 = CvssScore()
    v.vendor_data[0].cvss_v3.base_score = 1.0
    v.vendor_data[0].cvss_v3.exploitability_score = 2.0
    v.vendor_data[0].cvss_v3.impact_score = 3.0
    v.nvd_data = [CvssCombined()]
    v.nvd_data[0].id = "CVE-NVD"
    v.nvd_data[0].cvss_v2 = CvssScore()
    v.nvd_data[0].cvss_v2.base_score = 1.1
    v.nvd_data[0].cvss_v2.exploitability_score = 2.2
    v.nvd_data[0].cvss_v2.impact_score = 3.3
    v.nvd_data[0].cvss_v3 = CvssScore()
    v.nvd_data[0].cvss_v3.base_score = 1.1
    v.nvd_data[0].cvss_v3.exploitability_score = 2.2
    v.nvd_data[0].cvss_v3.impact_score = 3.3
    r.legacy_report = LegacyVulnerabilityReport()
    r.legacy_report.multi = LegacyMultiReport()
    r.legacy_report.multi.result = LegacyTableReport()
    r.legacy_report.multi.result.colcount = 4
    r.legacy_report.multi.result.rowcount = 1
    r.legacy_report.multi.result.header = ["id", "name", "version", "url"]
    r.legacy_report.multi.result.rows = [[
        "CVE-NVD", "lib1", "1.1", "http://someurl"
    ]]
    r.legacy_report.multi.url_column_index = 3
    r.legacy_report.multi.warns = []

    assert r.to_json() == {
        "user_id":
        "user",
        "image_id":
        "image",
        "cpe_report": [{
            "cpe":
            "cpe:*:*",
            "cpe23":
            "cpe2:*:*",
            "pkg_path":
            None,
            "pkg_type":
            None,
            "feed_name":
            "nvdv2",
            "feed_namespace":
            "nvdv2:cpes",
            "version":
            "1.1",
            "name":
            "lib1",
            "link":
            None,
            "nvd_data": [{
                "id": "CVE-NVD",
                "cvss_v2": {
                    "base_score": 1.1,
                    "exploitability_score": 2.2,
                    "impact_score": 3.3,
                },
                "cvss_v3": {
                    "base_score": 1.1,
                    "exploitability_score": 2.2,
                    "impact_score": 3.3,
                },
            }],
            "vendor_data": [{
                "id": "CVE-VENDOR",
                "cvss_v2": {
                    "base_score": 1.0,
                    "exploitability_score": 2.0,
                    "impact_score": 3.0,
                },
                "cvss_v3": {
                    "base_score": 1.0,
                    "exploitability_score": 2.0,
                    "impact_score": 3.0,
                },
            }],
            "severity":
            "High",
            "vulnerability_id":
            "CVE",
        }],
        "legacy_report": {
            "multi": {
                "result": {
                    "colcount": 4,
                    "header": ["id", "name", "version", "url"],
                    "rowcount": 1,
                    "rows": [["CVE-NVD", "lib1", "1.1", "http://someurl"]],
                },
                "url_column_index": 3,
                "warns": [],
            }
        },
    }