Esempio n. 1
0
def test_bandit_report_add_hit_to_no_existed_file():
    report = BanditReport()
    with pytest.raises(KeyError):
        report.add_hit({
            "issue_confidence": 'LOW',
            "issue_severity": 'MEDIUM',
            "filename": 'filename'
        })
Esempio n. 2
0
def test_bandit_report_metric_with_two_files_and_hits():
    report = BanditReport()
    report.add_file('filename1', 100, 10)
    report.add_hit({
        "issue_confidence": 'LOW',
        "issue_severity": 'MEDIUM',
        "filename": 'filename1'
    })
    new_metric1 = BASE_DICT.copy()
    new_metric1['loc'] = 100
    new_metric1['nosec'] = 10
    new_metric1["SEVERITY.MEDIUM"] = 1
    new_metric1["CONFIDENCE.LOW"] = 1

    report.add_file('filename2', 50, 5)
    report.add_hit({
        "issue_confidence": 'HIGH',
        "issue_severity": 'MEDIUM',
        "filename": 'filename2'
    })
    new_metric2 = BASE_DICT.copy()
    new_metric2['loc'] = 50
    new_metric2['nosec'] = 5
    new_metric2["SEVERITY.MEDIUM"] = 1
    new_metric2["CONFIDENCE.HIGH"] = 1

    total = BASE_DICT.copy()
    total['loc'] = 150
    total['nosec'] = 15
    total["SEVERITY.MEDIUM"] = 2
    total["CONFIDENCE.LOW"] = 1
    total["CONFIDENCE.HIGH"] = 1

    expected = {
        "_totals": total,
        'filename1': new_metric1,
        'filename2': new_metric2,
    }
    assert report.metrics == expected
Esempio n. 3
0
def test_bandit_report_same_hit():
    report = BanditReport()
    report.add_file('filename', 100, 10)
    report.add_hit({
        "issue_confidence": 'LOW',
        "issue_severity": 'MEDIUM',
        "filename": 'filename'
    })
    report.add_hit({
        "issue_confidence": 'LOW',
        "issue_severity": 'MEDIUM',
        "filename": 'filename'
    })
    new_metric = BASE_DICT.copy()
    new_metric['loc'] = 100
    new_metric['nosec'] = 10
    new_metric["SEVERITY.MEDIUM"] = 1
    new_metric["CONFIDENCE.LOW"] = 1

    expected = {
        "_totals": new_metric,
        'filename': new_metric,
    }
    assert report.metrics == expected