kasunkv / owasp-zap-vsts-task

Visual Studio Team Services build/release task for running OWASP ZAP automated security tests
MIT License
30 stars 11 forks source link

Fails to create HTML report if only one site is present in a scan #17

Closed IrmantasVaracinskas closed 6 years ago

IrmantasVaracinskas commented 6 years ago

Hello,

I've been having some problems generating HTML report. Replicated error in tests by removing whole "http://k2vowasptestsite2.azurewebsites.net" node from "valid.xml" file. Error looks something like this: TypeError: Cannot read property 'host' of undefined at spec\OwaspZapScan\classes\Helper.js:9:1537 at node_modules\xmljson\lib\to_json.js:33:10 at Parser. (node_modules\xml2js\lib\xml2js.js:255:20) at SAXParser.saxParser.onclosetag (node_modules\xml2js\lib\xml2js.js:225:24) at emit (node_modules\sax\lib\sax.js:615:33) at emitNode (node_modules\sax\lib\sax.js:620:3) at closeTag (node_modules\sax\lib\sax.js:861:5) at SAXParser.write (node_modules\sax\lib\sax.js:1293:29) at Parser.exports.Parser.Parser.parseString (node_modules\xml2js\lib\xml2js.js:273:29) at Parser.parseString (node_modules\xml2js\lib\xml2js.js:6:61) at exports.parseString (node_modules\xml2js\lib\xml2js.js:296:19) at Object.module.exports [as to_json] (node_modules\xmljson\lib\to_json.js:17:9) at Helper.ProcessAlerts (spec\OwaspZapScan\classes\Helper.js:9:1008) at Context. (spec\tests\helper.spec.js:25:29)

Managed to make it work with few changes to source code but it's not very pretty Problem is in: const sites: Site[] = reportJson.OWASPZAPReport.site; It works if I replace it with const sitesAny: any = reportJson.OWASPZAPReport.site; const sites: Site[] = Object.keys(sitesAny)[0] === '0' ? sitesAny : [sitesAny as Site];

Not sure if this would introduce new defects.

Regards, Irmantas Varacinskas

kasunkv commented 6 years ago

@IrmantasVaracinskas Good catch. :) Thank you for the feedback. The fix is now released with the v2.0.7