Report { public Report(GoalContext _ctx, Application _app, Set<Application> _modules) { this.goalContext = _ctx; this.app = _app; if (_modules == null) { this.modules = new HashSet<Application>(); this.modules.add(this.app); } else this.modules = _modules; Report.log.info( "Report to be done for " + this.app + ", [" + this.modules.size() + "] modules in total: " + this.modules); } Report(GoalContext _ctx, Application _app, Set<Application> _modules); String getExceptionThreshold(); void setExceptionThreshold(String _threshold); boolean isCreateAffectedLibraries(); void setCreateAffectedLibraries(boolean createAffectedLibraries); void setExemptions(ExemptionSet _exemptions); void fetchAppVulnerabilities(); void processVulnerabilities(); boolean isThrowBuildException(); Map<String, String> getConfiguration(); Map<String, Long> getStats(); String getExceptionMessage(); String getResultAsString(); void writeResult(@NotNull Path _dir); Path writeResult(@NotNull Path _dir, String _template, String _report); Path writeResultAsHtml(@NotNull Path _dir); Path writeResultAsXml(@NotNull Path _dir); Path writeResultAsJson(@NotNull Path _dir); static final String THRESHOLD_NONE; static final String THRESHOLD_DEP_ON; static final String THRESHOLD_POT_EXE; static final String THRESHOLD_ACT_EXE; }
@Test public void testReport() { try { this.configureBackendServiceUrl(server); this.setupMockServices(this.testApp); vulasConfiguration.setProperty( ExemptionBug.CFG_PREFIX + ".CVE-2014-0050.reason", "The vulnerable library with digest 6F1EBC is no problem because ..."); vulasConfiguration.setProperty( ExemptionBug.CFG_PREFIX + ".CVE-2014-0050.libraries", "6F1EBC6CE20AD8B3D4825CEB2E625E5C432A0E10"); vulasConfiguration.setProperty( ExemptionBug.CFG_PREFIX + ".CVE-2013-2186.reason", "Vulnerability CVE-2013-2186 is no problem because ..."); vulasConfiguration.setProperty(ExemptionBug.CFG_PREFIX + ".CVE-2013-2186.libraries", "*"); vulasConfiguration.setProperty( ExemptionBug.CFG_PREFIX + ".CVE-2019-1234.reason", "Vulnerability CVE-2019-1234 is no problem because ..."); vulasConfiguration.setProperty(ExemptionScope.CFG, "teST, provIDED"); vulasConfiguration.setProperty(ExemptionUnassessed.CFG, "knOWN"); final Configuration cfg = vulasConfiguration.getConfiguration(); final GoalContext goal_context = new GoalContext(); goal_context.setVulasConfiguration(vulasConfiguration); goal_context.setTenant(this.testTenant); goal_context.setSpace(this.testSpace); goal_context.setApplication(this.testApp); final Report report = new Report(goal_context, this.testApp, null); report.setExceptionThreshold( cfg.getString(CoreConfiguration.REP_EXC_THRESHOLD, Report.THRESHOLD_ACT_EXE)); report.setExemptions(ExemptionSet.createFromConfiguration(cfg)); report.fetchAppVulnerabilities(); report.processVulnerabilities(); final Path report_dir = Paths.get("./target/vulas/report"); if (!report_dir.toFile().exists()) report_dir.toFile().mkdirs(); report.writeResult(report_dir); assertTrue(FileUtil.isAccessibleFile(report_dir.resolve(Report.REPORT_FILE_HTML))); assertTrue(FileUtil.isAccessibleFile(report_dir.resolve(Report.REPORT_FILE_XML))); assertTrue(FileUtil.isAccessibleFile(report_dir.resolve(Report.REPORT_FILE_JSON))); final Tidy tidy = new Tidy(); tidy.parse( new ByteArrayInputStream( FileUtil.readInputStream( new FileInputStream( new File("./target/vulas/report/" + Report.REPORT_FILE_HTML)))), new FileOutputStream(new File("./target/jtidy-html.txt"))); assertEquals(0, tidy.getParseErrors()); assertEquals(3, tidy.getParseWarnings()); String path = "/backend" + PathBuilder.appVulnDeps(this.testApp, true, false, true); path = path.substring(0, path.indexOf('?')); verifyHttp(server) .times( 1, method(Method.GET), uri(path), parameter("includeHistorical", "true"), parameter("includeAffected", "false"), parameter("includeAffectedUnconfirmed", "true")); verifyHttp(server) .times( 1, method(Method.GET), uri(path), parameter("includeHistorical", "false"), parameter("includeAffected", "true"), parameter("includeAffectedUnconfirmed", "true")); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }