Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add totalIgnoredIssues tracking and update related logic in testing r… #2009

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ public enum QueryMode {

private Map<TestError, String> errorEnums = new HashMap<>();
List<TestingRunIssues> issueslist;
int totalIgnoredIssues;

public String fetchTestingRunResults() {
ObjectId testingRunResultSummaryId;
Expand All @@ -695,11 +696,43 @@ public String fetchTestingRunResults() {
if (queryMode != null) loggerMaker.infoAndAddToDb("fetchTestingRunResults called for queryMode="+queryMode);

int timeNow = Context.now();
Bson ignoredIssuesFilters = Filters.and(
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, "IGNORED"),
Filters.in(TestingRunIssues.LATEST_TESTING_RUN_SUMMARY_ID, testingRunResultSummaryId)
List<TestingRunResult> testingRunResultList = new ArrayList();
ObjectId objectId = new ObjectId(testingRunResultSummaryHexId);
Bson triFilters = Filters.and(
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, Arrays.asList("IGNORED"))
);
issueslist = TestingRunIssuesDao.instance.findAll(ignoredIssuesFilters, Projections.include("_id"));
issueslist = TestingRunIssuesDao.instance.findAll(triFilters, Projections.include("_id"));
List<Bson> testingRunResultsFilterList = new ArrayList<>();
boolean isStoredInVulnerableCollection = VulnerableTestingRunResultDao.instance.isStoredInVulnerableCollection(objectId, true);
for(TestingRunIssues issue: issueslist) {
Bson filter = Filters.empty();
if(isStoredInVulnerableCollection){
filter = Filters.and(
Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, new ObjectId(testingRunResultSummaryHexId)),
Filters.eq(TestingRunResult.API_INFO_KEY, issue.getId().getApiInfoKey()),
Filters.eq(TestingRunResult.TEST_SUB_TYPE, issue.getId().getTestSubCategory())
);

} else {
filter = Filters.and(
Filters.eq(TestingRunResult.TEST_RUN_RESULT_SUMMARY_ID, new ObjectId(testingRunResultSummaryHexId)),
Filters.eq(TestingRunResult.VULNERABLE, true),
Filters.eq(TestingRunResult.API_INFO_KEY, issue.getId().getApiInfoKey()),
Filters.eq(TestingRunResult.TEST_SUB_TYPE, issue.getId().getTestSubCategory())
);
}
testingRunResultsFilterList.add(filter);
}
List<Bson> filtersList = new ArrayList<>();
if(!testingRunResultsFilterList.isEmpty()) filtersList.add(Filters.or(testingRunResultsFilterList));
Bson sort = prepareTestingRunResultCustomSorting(sortKey, sortOrder);
if(isStoredInVulnerableCollection){
testingRunResultList = VulnerableTestingRunResultDao.instance.fetchLatestTestingRunResultWithCustomAggregations(Filters.and(filtersList), limit, skip, sort);
}else{
testingRunResultList = TestingRunResultDao.instance.fetchLatestTestingRunResultWithCustomAggregations(Filters.and(filtersList), limit, skip, sort);
}
totalIgnoredIssues = testingRunResultList.size();

loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched testing run issues of size: " + issueslist.size(), LogDb.DASHBOARD);

List<Bson> testingRunResultFilters = prepareTestRunResultsFilters(testingRunResultSummaryId, queryMode);
Expand All @@ -725,7 +758,7 @@ public String fetchTestingRunResults() {
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched testing run results of size: " + testingRunResults.size(), LogDb.DASHBOARD);

timeNow = Context.now();
removeTestingRunResultsByIssues(testingRunResults, issueslist, false);
removeCommonTestingRunResults(testingRunResults, testingRunResultList);
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Removed ignored issues from testing run results. Current size of testing run results: " + testingRunResults.size(), LogDb.DASHBOARD);
} catch (Exception e) {
loggerMaker.errorAndAddToDb(e, "error in fetchLatestTestingRunResult: " + e);
Expand All @@ -737,38 +770,20 @@ public String fetchTestingRunResults() {
return SUCCESS.toUpperCase();
}

public static void removeTestingRunResultsByIssues(List<TestingRunResult> testingRunResults,
List<TestingRunIssues> testingRunIssues,
boolean retainByIssues) {
long startTime = System.currentTimeMillis();

Set<String> issuesSet = new HashSet<>();
for (TestingRunIssues issue : testingRunIssues) {
String apiInfoKeyString = issue.getId().getApiInfoKey().toString();
String key = apiInfoKeyString + "|" + issue.getId().getTestSubCategory();
issuesSet.add(key);
}
loggerMaker.infoAndAddToDb("Total issues to be removed from TestingRunResults list: " + issuesSet.size(), LogDb.DASHBOARD);

Iterator<TestingRunResult> resultIterator = testingRunResults.iterator();
public static void removeCommonTestingRunResults(List<TestingRunResult> removeFromTestingRunResults,
List<TestingRunResult> removeTestingRunResults) {
Iterator<TestingRunResult> iterator = removeFromTestingRunResults.iterator();

while (resultIterator.hasNext()) {
TestingRunResult result = resultIterator.next();
String apiInfoKeyString = result.getApiInfoKey().toString();
String resultKey = apiInfoKeyString + "|" + result.getTestSubType();
while(iterator.hasNext()) {
TestingRunResult currentResult = iterator.next();

boolean matchFound = issuesSet.contains(resultKey);
boolean isCommon = removeTestingRunResults.stream()
.anyMatch(result -> result.getId().equals(currentResult.getId()));

if (retainByIssues && !matchFound) {
resultIterator.remove();
} else if (!retainByIssues && matchFound) {
resultIterator.remove();
if(isCommon) {
iterator.remove();
}
}

long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
loggerMaker.infoAndAddToDb("[" + Instant.now() + "] Removed elements from TestingRunResults list in " + duration + " ms", LogDb.DASHBOARD);
}

private Map<String, List<String>> reportFilterList;
Expand Down Expand Up @@ -1587,4 +1602,8 @@ public boolean getCleanUpTestingResources() {
public void setCleanUpTestingResources(boolean cleanUpTestingResources) {
this.cleanUpTestingResources = cleanUpTestingResources;
}

public int getTotalIgnoredIssues() {
return totalIgnoredIssues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,7 @@ public String fetchIssuesByStatusAndSummaryId() {
ObjectId objectId = new ObjectId(latestTestingRunSummaryId);

Bson triFilters = Filters.and(
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, issueStatusQuery),
Filters.in(TestingRunIssues.LATEST_TESTING_RUN_SUMMARY_ID, objectId)
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, issueStatusQuery)
);
issues = TestingRunIssuesDao.instance.findAll(triFilters, Projections.include("_id"));
List<Bson> testingRunResultsFilterList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function SingleTestRunPage() {
const [allResultsLength, setAllResultsLength] = useState(undefined)
const [currentSummary, setCurrentSummary] = useState('')
const [pageTotalCount, setPageTotalCount] = useState(0)
const [prevSelectedTab, setPrevSelectedTab] = useState('')

const tableTabMap = {
vulnerable: "VULNERABLE",
Expand Down Expand Up @@ -278,36 +279,40 @@ function SingleTestRunPage() {
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, issueslist, errorEnums }) => {
await api.fetchTestingRunResults(localSelectedTestRun.testingRunResultSummaryHexId, tableTabMap[selectedTab], sortKey, sortOrder, skip, limit, filters, queryValue).then(({ testingRunResults, issueslist, errorEnums, totalIgnoredIssues }) => {
issuesList = issueslist || []
totalIgnoredIssuesCount = totalIgnoredIssues
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))
}
})
if(!func.deepComparison(copyFilters, filters)){
setCopyFilters(filters)
api.fetchTestRunResultsCount(localSelectedTestRun.testingRunResultSummaryHexId).then((testCountMap) => {
testRunCountMap = testCountMap || []
testRunCountMap['VULNERABLE'] = Math.abs(testRunCountMap['VULNERABLE']-issuesList.length)
testRunCountMap['IGNORED_ISSUES'] = (issuesList.length || 0)
let countOthers = 0;
Object.keys(testCountMap).forEach((x) => {
if(x !== 'ALL'){
countOthers += testCountMap[x]
}
})
testRunCountMap['SECURED'] = testCountMap['ALL'] - countOthers
const orderedValues = tableTabsOrder.map(key => testCountMap[tableTabMap[key]] || 0)
setTestRunResultsCount(orderedValues)
setPageTotalCount(testRunCountMap[tableTabMap[selectedTab]])
})
}

if(!func.deepComparison(copyFilters, filters) || selectedTab !== prevSelectedTab){
setCopyFilters(filters)
setPrevSelectedTab(selectedTab)
api.fetchTestRunResultsCount(localSelectedTestRun.testingRunResultSummaryHexId).then((testCountMap) => {
testRunCountMap = testCountMap || []
testRunCountMap['VULNERABLE'] = Math.abs(testRunCountMap['VULNERABLE']-totalIgnoredIssuesCount)
testRunCountMap['IGNORED_ISSUES'] = (totalIgnoredIssuesCount || 0)
let countOthers = 0;
Object.keys(testCountMap).forEach((x) => {
if(x !== 'ALL'){
countOthers += testCountMap[x]
}
})
}

testRunCountMap['SECURED'] = testCountMap['ALL'] === 0 ? 0 : (testCountMap['ALL'] - countOthers)
const orderedValues = tableTabsOrder.map(key => testCountMap[tableTabMap[key]] || 0)
setTestRunResultsCount(orderedValues)
setPageTotalCount(selectedTab === 'ignored_issues' ? totalIgnoredIssuesCount : testRunCountMap[tableTabMap[selectedTab]])
})

}
}

fillTempData(testRunResultsRes, selectedTab)
return {value: transform.getPrettifiedTestRunResults(testRunResultsRes), total: selectedTab === 'ignored_issues' ? totalIgnoredIssuesCount : testRunCountMap[tableTabMap[selectedTab]]}
}
Expand Down
Loading