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

Feature/logs in fetching test run result #1871

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -511,8 +511,10 @@ private List<Bson> prepareTestRunResultsFilters(ObjectId testingRunResultSummary
List<Bson> 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) {
Expand Down Expand Up @@ -574,6 +576,35 @@ public static Bson prepareTestingRunResultCustomSorting(String sortKey, int sort
return sortStage;
}

Map<String, Integer> 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<TestingRunResult> testingRunResults;
private boolean fetchOnlyVulnerable;
Expand All @@ -583,8 +614,7 @@ public enum QueryMode {
private QueryMode queryMode;

private Map<TestError, String> errorEnums = new HashMap<>();

Map<String, Integer> testCountMap;
List<TestingRunIssues> issueslist;

public String fetchTestingRunResults() {
ObjectId testingRunResultSummaryId;
Expand All @@ -604,7 +634,7 @@ public String fetchTestingRunResults() {
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, "IGNORED"),
Filters.in(TestingRunIssues.LATEST_TESTING_RUN_SUMMARY_ID, testingRunResultSummaryId)
);
List<TestingRunIssues> 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<Bson> testingRunResultFilters = prepareTestRunResultsFilters(testingRunResultSummaryId, queryMode);
Expand Down Expand Up @@ -632,23 +662,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);
}
Expand Down Expand Up @@ -1401,4 +1414,8 @@ public Map<String, Integer> getTestCountMap() {
public void setReportFilterList(Map<String, List<String>> reportFilterList) {
this.reportFilterList = reportFilterList;
}

public List<TestingRunIssues> getIssueslist() {
return issueslist;
}
}
21 changes: 21 additions & 0 deletions apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3751,6 +3751,27 @@
</result>
</action>

<action name="api/fetchTestRunResultsCount" class="com.akto.action.testing.StartTestAction" method="fetchTestRunResultsCount">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="roleAccessInterceptor">
<param name="featureLabel">TEST_RESULTS</param>
<param name="accessType">READ</param>
</interceptor-ref>

<result name="FORBIDDEN" type="json">
<param name="statusCode">403</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/fetchVulnerableTestRunResults" class="com.akto.action.testing.StartTestAction" method="fetchVulnerableTestRunResults">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}
Expand All @@ -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]])
})
}
}
Expand Down Expand Up @@ -499,6 +508,7 @@ const promotedBulkActions = (selectedDataHexIds) => {
"selected": 1
}}
callFromOutside={updateTable}
pageTotalCount={pageTotalCount}
/>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading