UNPKG

auditjs

Version:

Audit dependencies to identify known vulnerabilities and maintenance problems

81 lines 3.5 kB
"use strict"; /* * Copyright 2019-Present Sonatype Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.XmlFormatter = void 0; const builder = __importStar(require("xmlbuilder")); const Formatter_1 = require("./Formatter"); class XmlFormatter { printAuditResults(list) { const testsuite = builder.create('testsuite'); testsuite.att('tests', list.length); testsuite.att('timestamp', new Date().toISOString()); testsuite.att('failures', (0, Formatter_1.getNumberOfVulnerablePackagesFromResults)(list)); for (let i = 0; i < list.length; i++) { const testcase = testsuite.ele('testcase', { classname: list[i].coordinates, name: list[i].coordinates }); const vulns = list[i].vulnerabilities; if (vulns) { if (vulns.length > 0) { const failure = testcase.ele('failure'); let failureText = ''; for (let j = 0; j < vulns.length; j++) { failureText += this.getVulnerabilityForXmlBlock(vulns[j]) + '\n'; } failure.text(failureText); failure.att('type', 'Vulnerability detected'); } } } const xml = testsuite.end({ pretty: true }); console.log(xml); } getVulnerabilityForXmlBlock(vuln) { let vulnBlock = ''; vulnBlock += `Vulnerability Title: ${vuln.title}\n`; vulnBlock += `ID: ${vuln.id}\n`; vulnBlock += `Description: ${vuln.description}\n`; vulnBlock += `CVSS Score: ${vuln.cvssScore}\n`; vulnBlock += `CVSS Vector: ${vuln.cvssVector}\n`; vulnBlock += `CVE: ${vuln.cve}\n`; vulnBlock += `Reference: ${vuln.reference}\n`; return vulnBlock; } } exports.XmlFormatter = XmlFormatter; //# sourceMappingURL=XmlFormatter.js.map