import * as Task from 'vsts-task-lib' ; import { ReportType } from './../enums/Enums' ; import { Report } from './../classes/Report' ; import { Helper } from './../classes/Helper' ; import { AlertResult } from './../interfaces/types/AlertResult' ; import { TaskInput } from './TaskInput' ; export class Verify { private _reports : Report ; private _helper : Helper ; private _taskInputs : TaskInput ; constructor ( helper , report , taskInputs ) { this . _taskInputs = taskInputs ; this . _helper = helper ; this . _reports = report ; } async Assert ( ) { const xmlReport = await this . _reports . GetScanResults ( ReportType . XML ) ; const alertResult = this . _helper . ProcessAlerts ( xmlReport , this . _taskInputs . TargetUrl ) ; if ( process . env . NODE_ENV !== 'test' ) { Task . debug ( `
                Scan Result: 
                High Risk Alerts: ${ alertResult . HighAlerts }
                Medium Risk Alerts: ${ alertResult . MediumAlerts }
                Low Risk Alerts: ${ alertResult . LowAlerts }
                Informational Risk Alerts: ${ alertResult . InformationalAlerts }` ) ; } this . _reports . PrintResult ( alertResult . HighAlerts , alertResult . MediumAlerts , alertResult . LowAlerts , alertResult . InformationalAlerts ) ; if ( this . _taskInputs . EnableVerifications ) { if ( this . _taskInputs . MaxHighRiskAlerts < alertResult . HighAlerts ) { if ( process . env . NODE_ENV !== 'test' ) { Task . setResult ( Task . TaskResult . Failed , `High Risk Alert Threshold Exceeded. Threshold: ${ this . _taskInputs . MaxHighRiskAlerts }, Actual: ${ alertResult . HighAlerts }` ) ; } } if ( this . _taskInputs . MaxMediumRiskAlerts < alertResult . MediumAlerts ) { if ( process . env . NODE_ENV !== 'test' ) { Task . setResult ( Task . TaskResult . Failed , `Medium Risk Alert Threshold Exceeded. Threshold: ${ this . _taskInputs . MaxMediumRiskAlerts }, Actual: ${ alertResult . MediumAlerts }` ) ; } } if ( this . _taskInputs . MaxLowRiskAlerts < alertResult . LowAlerts ) { if ( process . env . NODE_ENV !== 'test' ) { Task . setResult ( Task . TaskResult . Failed , `Low Alert Risk Threshold Exceeded. Threshold: ${ this . _taskInputs . MaxLowRiskAlerts }, Actual: ${ alertResult . LowAlerts }` ) ; } } } } }