Skip to content

Commit

Permalink
Fixing queries in testing containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Jan 13, 2025
1 parent 0ec5dbf commit 9f450fb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public String fetchTestingRunResult() {
Filters.eq(TestingRunResult.TEST_SUB_TYPE, testSubType),
Filters.eq(TestingRunResult.API_INFO_KEY, issue.getId().getApiInfoKey())
);
testingRunResult = VulnerableTestingRunResultDao.instance.findOne(filterForRunResult);
testingRunResult = VulnerableTestingRunResultDao.instance.findOne(filterForRunResult, null);
if(testingRunResult == null){
testingRunResult = TestingRunResultDao.instance.findOne(filterForRunResult);
}
Expand Down
6 changes: 4 additions & 2 deletions apps/testing/src/main/java/com/akto/testing/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.akto.dao.testing.TestingRunDao;
import com.akto.dao.testing.TestingRunResultDao;
import com.akto.dao.testing.TestingRunResultSummariesDao;
import com.akto.dao.testing.VulnerableTestingRunResultDao;
import com.akto.dao.testing_run_findings.TestingRunIssuesDao;
import com.akto.dto.billing.FeatureAccess;
import com.akto.dto.billing.SyncLimit;
Expand Down Expand Up @@ -437,7 +438,7 @@ public void run() {
Filters.eq(TestingRunResultSummary.TESTING_RUN_ID, testingRun.getId()),
Filters.eq(TestingRunResultSummary.STATE, State.FAILED)
);
List<TestingRunResult> testingRunResults = TestingRunResultDao.instance.fetchLatestTestingRunResult(Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, testingRunResultSummary.getId()), 1);
List<TestingRunResult> testingRunResults = Utils.fetchLatestTestingRunResult(Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, testingRunResultSummary.getId()));
if (testingRunResults != null && !testingRunResults.isEmpty()) {
TestingRunResult testingRunResult = testingRunResults.get(0);
if (Context.now() - testingRunResult.getEndTimestamp() < LAST_TEST_RUN_EXECUTION_DELTA) {
Expand Down Expand Up @@ -745,10 +746,11 @@ private static void raiseMixpanelEvent(ObjectId summaryId, TestingRun testingRun
if(newIssuesModelList.size() <= 5) {
Bson filterForRunResult = Filters.and(
Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, testingRunIssues.getLatestTestingRunSummaryId()),
Filters.eq(TestingRunResult.VULNERABLE, true),
Filters.eq(TestingRunResult.TEST_SUB_TYPE, testingRunIssues.getId().getTestSubCategory()),
Filters.eq(TestingRunResult.API_INFO_KEY, testingRunIssues.getId().getApiInfoKey())
);
TestingRunResult testingRunResult = TestingRunResultDao.instance.findOne(filterForRunResult, Projections.include("_id"));
TestingRunResult testingRunResult = VulnerableTestingRunResultDao.instance.findOne(filterForRunResult, Projections.include("_id"));
testRunResultId = testingRunResult.getHexId();
} else testRunResultId = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public List<TestingRunResult> fetchLatestTestingRunResult(Bson filters, int limi
pipeline.add(Aggregates.skip(skip));
pipeline.add(Aggregates.limit(limit));
pipeline.addAll(customAggregation);
MongoCursor<BasicDBObject> cursor = instance.getMCollection()
MongoCursor<BasicDBObject> cursor = this.getMCollection()
.aggregate(pipeline, BasicDBObject.class).cursor();
List<TestingRunResult> testingRunResults = new ArrayList<>();
while (cursor.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public List<TestingRunResult> fetchLatestTestingRunResultWithCustomAggregations(
}

@Override
public TestingRunResult findOne(Bson q) {
TestingRunResult tr = super.findOne(q);
public TestingRunResult findOne(Bson q, Bson projection) {
TestingRunResult tr = super.findOne(q, projection);
if(tr == null){
tr = instance.findOne(q);
tr = instance.findOne(q, projection);
}
return tr;
}
Expand Down
22 changes: 22 additions & 0 deletions libs/utils/src/main/java/com/akto/testing/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.akto.util.enums.GlobalEnums.Severity;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Accumulators;
import com.mongodb.client.model.Aggregates;
Expand Down Expand Up @@ -475,5 +476,26 @@ public static Map<String, Integer> finalCountIssuesMap(ObjectId testingRunResult

return countIssuesMap;
}

public static List<TestingRunResult> fetchLatestTestingRunResult(Bson filter){
List<TestingRunResult> resultsFromNonVulCollection = TestingRunResultDao.instance.fetchLatestTestingRunResult(filter, 1);
List<TestingRunResult> resultsFromVulCollection = VulnerableTestingRunResultDao.instance.fetchLatestTestingRunResult(filter, 1);

if(resultsFromVulCollection != null && !resultsFromVulCollection.isEmpty()){
if(resultsFromNonVulCollection != null && !resultsFromNonVulCollection.isEmpty()){
TestingRunResult tr1 = resultsFromVulCollection.get(0);
TestingRunResult tr2 = resultsFromNonVulCollection.get(0);
if(tr1.getEndTimestamp() >= tr2.getEndTimestamp()){
return resultsFromVulCollection;
}else{
return resultsFromVulCollection;
}
}else{
return resultsFromVulCollection;
}
}

return resultsFromNonVulCollection;
}

}

0 comments on commit 9f450fb

Please sign in to comment.