Example #1
0
def processReport(report: ReportWrapper, startTime: datetime) -> Optional[VulnTestInfo]:
    """ Attempt to verify a given report """
    if report.needsBotReply():
        if startTime > report.getReportedTime():
            return None
        if config.DEBUG:
            print("Processing %s" % report.getReportTitle())
        for module in modules:
            if module.match(report.getReportBody(), report.getReportWeakness()):  # type: ignore
                if config.DEBUG:
                    print(module.__file__.split('/')[-1] + " matched id=%s!" % report.getReportID())
                vti = module.process(report)  # type: ignore
                if config.DEBUGVERBOSE:
                    print(vti)
                if vti:
                    postComment(report.getReportID(), vti, addStopMessage=True)
                    if vti.reproduced and config.metadataLogging:
                        metadataVTI = generateMetadataVTI(report, vti)
                        postComment(report.getReportID(), metadataVTI, internal=True)
                return vti
        if config.DEBUG:
            print("No matches")
    return None
Example #2
0
def test_verifyProcess(monkeypatch):
    from AutoTriageBot import verify
    time = datetime.datetime.now()
    monkeypatch.setattr(verify, 'postComment', Counter())
    report = ReportWrapper()
    monkeypatch.setattr(report, 'needsBotReply', lambda: False)
    assert verify.postComment.count == 0
    assert verify.processReport(report, time) is None
    assert verify.postComment.count == 0
    monkeypatch.setattr(report, 'needsBotReply', lambda: True)
    monkeypatch.setattr(report, 'getReportedTime',
                        lambda: datetime.datetime.now())
    monkeypatch.setattr(
        verify.config, 'genesis',
        datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc))
    monkeypatch.setattr(verify.config, 'DEBUG', False)
    monkeypatch.setattr(report, 'getReportBody', lambda: "XSS report")
    monkeypatch.setattr(report, 'getReportTitle', lambda: "XSS report")
    monkeypatch.setattr(report, 'getReportWeakness', lambda: "XSS")
    monkeypatch.setattr(report, 'getReportID', lambda: '-1')
    vti = VulnTestInfo(reproduced=False, message="VTI", info={}, type='type')
    for module in verify.modules:
        monkeypatch.setattr(module, 'process', lambda r: vti)
        monkeypatch.setattr(module, 'match', lambda u, v: True)
    monkeypatch.setattr(report, 'needsBotReply', lambda: True)
    assert report.needsBotReply()
    assert verify.postComment.count == 0
    assert verify.processReport(report, time) == vti
    assert verify.postComment.count == 1
    assert verify.postComment.lastCall == (('-1', vti), {
        'addStopMessage': True
    })
    for module in verify.modules:
        monkeypatch.setattr(module, 'match', lambda b, w: False)
    assert verify.postComment.count == 1
    assert verify.processReport(report, time) is None
    assert verify.postComment.count == 1