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 deb67bd947..ff71d0f67c 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 @@ -513,8 +513,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) { @@ -576,6 +578,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; @@ -585,8 +616,7 @@ public enum QueryMode { private QueryMode queryMode; private Map errorEnums = new HashMap<>(); - - Map testCountMap; + List issueslist; public String fetchTestingRunResults() { ObjectId testingRunResultSummaryId; @@ -606,7 +636,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); @@ -634,23 +664,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); } @@ -1404,6 +1417,10 @@ public void setReportFilterList(Map> reportFilterList) { this.reportFilterList = reportFilterList; } + public List getIssueslist() { + return issueslist; + } + public boolean getCleanUpTestingResources() { return cleanUpTestingResources; } diff --git a/apps/dashboard/src/main/resources/struts.xml b/apps/dashboard/src/main/resources/struts.xml index 26c53faa7f..b210e8f748 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/components/tables/GithubServerTable.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/tables/GithubServerTable.js index 6498b96088..335f60064f 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/tables/GithubServerTable.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/tables/GithubServerTable.js @@ -130,6 +130,12 @@ function GithubServerTable(props) { } } + useEffect(() => { + if(Number.isInteger(props?.pageTotalCount)) { + setTotal(props?.pageTotalCount) + } + }, [props?.pageTotalCount, data]) + const handleSelectedTab = (x) => { const tableTabs = props.tableTabs ? props.tableTabs : props.tabs if(tableTabs){ 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..9a75c819a3 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 @@ -135,6 +135,7 @@ function SingleTestRunPage() { const [testingRunResultSummariesObj, setTestingRunResultSummariesObj] = useState({}) const [allResultsLength, setAllResultsLength] = useState(undefined) const [currentSummary, setCurrentSummary] = useState('') + const [pageTotalCount, setPageTotalCount] = useState(0) const tableTabMap = { vulnerable: "VULNERABLE", @@ -247,6 +248,7 @@ function SingleTestRunPage() { let testRunResultsRes = [] let testRunCountMap = [] let totalIgnoredIssuesCount = 0 + let issuesList = [] const { testingRun, workflowTest, testingRunType } = testingRunResultSummariesObj if(testingRun === undefined){ return {value: [], total: 0} @@ -270,17 +272,24 @@ function SingleTestRunPage() { }) testRunResultsRes = ignoredTestRunResults totalIgnoredIssuesCount = ignoredTestRunResults.length + setPageTotalCount(selectedTab === 'ignored_issues' ? totalIgnoredIssuesCount : testRunCountMap[tableTabMap[selectedTab]]) } 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)) } + }) + 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) + setPageTotalCount(testRunCountMap[tableTabMap[selectedTab]]) }) } } @@ -499,6 +508,7 @@ const promotedBulkActions = (selectedDataHexIds) => { "selected": 1 }} callFromOutside={updateTable} + pageTotalCount={pageTotalCount} /> ) 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 a3d530a321..2b86e5b4d8 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',