From 24e7e32d08273db683547757199946383c5651e6 Mon Sep 17 00:00:00 2001 From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:38:15 +0530 Subject: [PATCH] moved test results counting to other api --- .../akto/action/testing/StartTestAction.java | 61 ++++++++++++------- apps/dashboard/src/main/resources/struts.xml | 21 +++++++ .../SingleTestRunPage/SingleTestRunPage.js | 10 ++- .../src/apps/dashboard/pages/testing/api.js | 10 +++ 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java b/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java index 7ab4be3d8d..6f744db500 100644 --- a/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java @@ -511,8 +511,10 @@ private List prepareTestRunResultsFilters(ObjectId testingRunResultSummary List filterList = new ArrayList<>(); filterList.add(Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, testingRunResultSummaryId)); - Bson filtersForTestingRunResults = com.akto.action.testing.Utils.createFiltersForTestingReport(reportFilterList); - if(!filtersForTestingRunResults.equals(Filters.empty())) filterList.add(filtersForTestingRunResults); + if(reportFilterList != null) { + Bson filtersForTestingRunResults = com.akto.action.testing.Utils.createFiltersForTestingReport(reportFilterList); + if (!filtersForTestingRunResults.equals(Filters.empty())) filterList.add(filtersForTestingRunResults); + } if(queryMode == null) { if(fetchOnlyVulnerable) { @@ -574,6 +576,35 @@ public static Bson prepareTestingRunResultCustomSorting(String sortKey, int sort return sortStage; } + Map testCountMap; + public String fetchTestRunResultsCount() { + ObjectId testingRunResultSummaryId; + try { + testingRunResultSummaryId = new ObjectId(testingRunResultSummaryHexId); + } catch (Exception e) { + addActionError("Invalid test summary id"); + return ERROR.toUpperCase(); + } + + testCountMap = new HashMap<>(); + int timeNow = Context.now(); + for(QueryMode qm : QueryMode.values()) { + if(qm.equals(QueryMode.ALL) || qm.equals(QueryMode.SKIPPED_EXEC_NO_ACTION)) { + continue; + } + + timeNow = Context.now(); + int count = (int) TestingRunResultDao.instance.count(Filters.and( + prepareTestRunResultsFilters(testingRunResultSummaryId, qm) + )); + loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched total count of testingRunResults for: " + qm.name(), LogDb.DASHBOARD); + testCountMap.put(qm.toString(), count); + } + + testCountMap.put(QueryMode.VULNERABLE.name(), testCountMap.getOrDefault(QueryMode.VULNERABLE.name(), 0)); + return SUCCESS.toUpperCase(); + } + String testingRunResultSummaryHexId; List testingRunResults; private boolean fetchOnlyVulnerable; @@ -583,8 +614,7 @@ public enum QueryMode { private QueryMode queryMode; private Map errorEnums = new HashMap<>(); - - Map testCountMap; + List issueslist; public String fetchTestingRunResults() { ObjectId testingRunResultSummaryId; @@ -604,7 +634,7 @@ public String fetchTestingRunResults() { Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, "IGNORED"), Filters.in(TestingRunIssues.LATEST_TESTING_RUN_SUMMARY_ID, testingRunResultSummaryId) ); - List issueslist = TestingRunIssuesDao.instance.findAll(ignoredIssuesFilters, Projections.include("_id")); + issueslist = TestingRunIssuesDao.instance.findAll(ignoredIssuesFilters, Projections.include("_id")); loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched testing run issues of size: " + issueslist.size(), LogDb.DASHBOARD); List testingRunResultFilters = prepareTestRunResultsFilters(testingRunResultSummaryId, queryMode); @@ -632,23 +662,6 @@ public String fetchTestingRunResults() { timeNow = Context.now(); removeTestingRunResultsByIssues(testingRunResults, issueslist, false); loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Removed ignored issues from testing run results. Current size of testing run results: " + testingRunResults.size(), LogDb.DASHBOARD); - - testCountMap = new HashMap<>(); - for(QueryMode qm : QueryMode.values()) { - if(qm.equals(QueryMode.ALL) || qm.equals(QueryMode.SKIPPED_EXEC_NO_ACTION)) { - continue; - } - - timeNow = Context.now(); - int count = (int) TestingRunResultDao.instance.count(Filters.and( - prepareTestRunResultsFilters(testingRunResultSummaryId, qm) - )); - loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched total count of testingRunResults for: " + qm.name(), LogDb.DASHBOARD); - testCountMap.put(qm.toString(), count); - } - - testCountMap.put(QueryMode.VULNERABLE.name(), Math.abs(testCountMap.getOrDefault(QueryMode.VULNERABLE.name(), 0)- issueslist.size())); - testCountMap.put("IGNORED_ISSUES", issueslist.size()); } catch (Exception e) { loggerMaker.errorAndAddToDb(e, "error in fetchLatestTestingRunResult: " + e); } @@ -1401,4 +1414,8 @@ public Map getTestCountMap() { public void setReportFilterList(Map> reportFilterList) { this.reportFilterList = reportFilterList; } + + public List getIssueslist() { + return issueslist; + } } diff --git a/apps/dashboard/src/main/resources/struts.xml b/apps/dashboard/src/main/resources/struts.xml index e9536f35af..c490b0c263 100644 --- a/apps/dashboard/src/main/resources/struts.xml +++ b/apps/dashboard/src/main/resources/struts.xml @@ -3751,6 +3751,27 @@ + + + + + TEST_RESULTS + READ + + + + 403 + false + ^actionErrors.* + + + + 422 + false + ^actionErrors.* + + + diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage/SingleTestRunPage.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage/SingleTestRunPage.js index 52392bad1d..200198dacd 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage/SingleTestRunPage.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage/SingleTestRunPage.js @@ -247,6 +247,7 @@ function SingleTestRunPage() { let testRunResultsRes = [] let testRunCountMap = [] let totalIgnoredIssuesCount = 0 + let issuesList = [] const { testingRun, workflowTest, testingRunType } = testingRunResultSummariesObj if(testingRun === undefined){ return {value: [], total: 0} @@ -271,14 +272,19 @@ function SingleTestRunPage() { testRunResultsRes = ignoredTestRunResults totalIgnoredIssuesCount = ignoredTestRunResults.length } else { - await api.fetchTestingRunResults(localSelectedTestRun.testingRunResultSummaryHexId, tableTabMap[selectedTab], sortKey, sortOrder, skip, limit, filters, queryValue).then(({ testingRunResults, testCountMap, errorEnums }) => { - testRunCountMap = testCountMap + await api.fetchTestingRunResults(localSelectedTestRun.testingRunResultSummaryHexId, tableTabMap[selectedTab], sortKey, sortOrder, skip, limit, filters, queryValue).then(({ testingRunResults, issueslist, errorEnums }) => { + issuesList = issueslist || [] testRunResultsRes = transform.prepareTestRunResults(hexId, testingRunResults, subCategoryMap, subCategoryFromSourceConfigMap) if(selectedTab === 'domain_unreachable' || selectedTab === 'skipped' || selectedTab === 'need_configurations') { errorEnums['UNKNOWN_ERROR_OCCURRED'] = "OOPS! Unknown error occurred." setErrorsObject(errorEnums) setMissingConfigs(transform.getMissingConfigs(testRunResultsRes)) } + }) + await api.fetchTestRunResultsCount(localSelectedTestRun.testingRunResultSummaryHexId).then(({testCountMap}) => { + testRunCountMap = testCountMap || [] + testRunCountMap['VULNERABLE'] = Math.abs(testRunCountMap['VULNERABLE']-issuesList.length) + testRunCountMap['IGNORED_ISSUES'] = (issuesList.length || 0) const orderedValues = tableTabsOrder.map(key => testCountMap[tableTabMap[key]] || 0) setTestRunResultsCount(orderedValues) }) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js index be973bfa69..3bfbbc6fd2 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js @@ -34,6 +34,16 @@ export default { }) return resp }, + async fetchTestRunResultsCount(testingRunResultSummaryHexId) { + const resp = await request({ + url: '/api/fetchTestRunResultsCount', + method: 'post', + data: { + testingRunResultSummaryHexId + } + }) + return resp + }, async fetchAllSubCategories(fetchOnlyActive, mode, skip, limit) { const resp = await request({ url: 'api/fetchAllSubCategories',