Skip to content

Commit

Permalink
Handled for issue status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Dec 30, 2024
1 parent c4a38fe commit 1795d1c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions libs/utils/src/main/java/com/akto/testing/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
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;
import com.akto.dto.RawApi;
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;
import com.akto.log.LoggerMaker;
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;
Expand Down Expand Up @@ -430,23 +436,28 @@ public static Map<String, Integer> 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<TestingRunResult> allVulResults = TestingRunResultDao.instance.findAll(filterQ, projection);

Map<TestingIssuesId, TestingRunResult> 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<Bson> 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<BasicDBObject> cursor = TestingRunResultDao.instance.getMCollection().aggregate(pipeline, BasicDBObject.class).cursor();
MongoCursor<BasicDBObject> 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);
Expand Down

0 comments on commit 1795d1c

Please sign in to comment.