From 1795d1c0dc3c4e82f298c85da7510f1dcf20c63c Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 30 Dec 2024 23:52:39 +0530 Subject: [PATCH] Handled for issue status --- .../src/main/java/com/akto/testing/Utils.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libs/utils/src/main/java/com/akto/testing/Utils.java b/libs/utils/src/main/java/com/akto/testing/Utils.java index 3999cce874..77913061df 100644 --- a/libs/utils/src/main/java/com/akto/testing/Utils.java +++ b/libs/utils/src/main/java/com/akto/testing/Utils.java @@ -14,6 +14,7 @@ import org.bson.conversions.Bson; import org.bson.types.ObjectId; import com.akto.dao.testing.TestingRunResultDao; +import com.akto.dao.testing_run_findings.TestingRunIssuesDao; import com.akto.dto.ApiInfo.ApiInfoKey; import com.akto.dto.CollectionConditions.ConditionsType; import com.akto.dto.OriginalHttpRequest; @@ -21,6 +22,8 @@ import com.akto.dto.test_editor.DataOperandsFilterResponse; import com.akto.dto.test_editor.FilterNode; import com.akto.dto.test_editor.Util; +import com.akto.dto.test_run_findings.TestingIssuesId; +import com.akto.dto.test_run_findings.TestingRunIssues; import com.akto.dto.testing.TestingRunResult; import com.akto.dto.testing.WorkflowUpdatedSampleData; import com.akto.dto.type.RequestTemplate; @@ -28,7 +31,10 @@ import com.akto.log.LoggerMaker.LogDb; import com.akto.test_editor.filter.Filter; import com.akto.test_editor.filter.data_operands_impl.ValidationResult; +import com.akto.testing_utils.TestingUtils; +import com.akto.util.Constants; import com.akto.util.JSONUtils; +import com.akto.util.enums.GlobalEnums; import com.akto.util.enums.GlobalEnums.Severity; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; @@ -430,23 +436,28 @@ public static Map finalCountIssuesMap(ObjectId testingRunResult countIssuesMap.put(Severity.MEDIUM.toString(), 0); countIssuesMap.put(Severity.LOW.toString(), 0); - Bson projection = Projections.computed("confidence", Projections.computed("$first", "$testResults.confidence")); + Bson projection = Projections.include(TestingRunResult.API_INFO_KEY, TestingRunResult.TEST_SUB_TYPE); Bson filterQ = Filters.and( Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, testingRunResultSummaryId), Filters.eq(TestingRunResult.VULNERABLE, true) ); - BasicDBObject groupId = new BasicDBObject("_id", "$confidence"); + List allVulResults = TestingRunResultDao.instance.findAll(filterQ, projection); + + Map testingIssuesIdsMap = TestingUtils. + listOfIssuesIdsFromTestingRunResults(allVulResults, true, false); + + Bson inQuery = Filters.and(Filters.in(Constants.ID, testingIssuesIdsMap.keySet().toArray()), Filters.eq(TestingRunIssues.TEST_RUN_ISSUES_STATUS, GlobalEnums.TestRunIssueStatus.OPEN)); List pipeline = new ArrayList<>(); + pipeline.add(Aggregates.match(inQuery)); + pipeline.add(Aggregates.group( + "$" + TestingRunIssues.KEY_SEVERITY, Accumulators.sum("count",1) + )); - pipeline.add(Aggregates.match(filterQ)); - pipeline.add(Aggregates.project(projection)); - pipeline.add(Aggregates.group(groupId, Accumulators.sum("count", 1))); - MongoCursor cursor = TestingRunResultDao.instance.getMCollection().aggregate(pipeline, BasicDBObject.class).cursor(); + MongoCursor cursor = TestingRunIssuesDao.instance.getMCollection().aggregate(pipeline, BasicDBObject.class).cursor(); while(cursor.hasNext()){ BasicDBObject dbObject = cursor.next(); - BasicDBObject objectId = (BasicDBObject) dbObject.get("_id"); - String id = objectId.getString("_id"); + String id = dbObject.getString("_id"); int val = dbObject.getInt("count"); countIssuesMap.put(id, val);