Skip to content

Commit

Permalink
Merge pull request #1694 from akto-api-security/hotfix/fix_parallel_a…
Browse files Browse the repository at this point in the history
…pi_calls

Fix parallel api calls
  • Loading branch information
notshivansh authored Nov 5, 2024
2 parents 86e4d37 + aaba716 commit ce2c1a1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 98 deletions.
6 changes: 4 additions & 2 deletions apps/dashboard/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3746,8 +3746,10 @@
<result name="SUCCESS" type="json">
<param name="enumAsBean">true</param>
</result>
<result name="ERROR" type="httpheader">
<param name="status">401</param>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Dropdown from "../../../components/layouts/Dropdown";
import func from "@/util/func"
import { useNavigate } from "react-router-dom"
import PersistStore from "../../../../main/PersistStore";
import transform from "../../testing/transform";

function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction }) {

Expand Down Expand Up @@ -90,31 +91,9 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
setSlackIntegrated(apiTokenList && apiTokenList.length > 0)
})

let categories = []
let businessLogicSubcategories = []
const limit = 200
let skip = 0
for (let i = 0; i < 10; i++) {
const allSubCategoriesResponse = await testingApi.fetchAllSubCategories(true, "runTests", skip, limit)
if (!allSubCategoriesResponse) {
break
}
skip += limit

if (categories.length == 0 && allSubCategoriesResponse.categories) {
categories = allSubCategoriesResponse.categories
}

const subCategories = allSubCategoriesResponse.subCategories
if (subCategories && subCategories.length > 0) {
businessLogicSubcategories.push(...subCategories)
}

if (subCategories.length < limit) {
break
}
}

const metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
let categories = metaDataObj.categories
let businessLogicSubcategories = metaDataObj.subCategories
const testRolesResponse = await testingApi.fetchTestRoles()
var testRoles = testRolesResponse.testRoles.map(testRole => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import LearnPopoverComponent from "../../components/layouts/LearnPopoverComponen
import TitleWithInfo from "@/apps/dashboard/components/shared/TitleWithInfo"
import LocalStore from "../../../main/LocalStorageStore"
import func from "../../../../util/func"
import transform from "../testing/transform"

const TestEditor = () => {
const navigate = useNavigate()
Expand All @@ -39,55 +40,27 @@ const TestEditor = () => {
}

const fetchVulnerableRequests = async () => {
let vulnerableRequests = []

let skip = 0
const limit = 100
for (let i = 0; i < 10; i++) {
const allSubCategoriesResponse = await testEditorRequests.fetchVulnerableRequests(skip, limit)
skip += limit

if (!allSubCategoriesResponse) {
break
}

let arr1 = allSubCategoriesResponse.vulnerableRequests
if (arr1 && arr1.length > 0) {
vulnerableRequests.push(...arr1)
}

if (!arr1 || arr1.length < limit) {
break
}
let vulnerableRequests = [], promises = []
const limit = 50
for (let i = 0; i < 20; i++) {
promises.push(
testEditorRequests.fetchVulnerableRequests(i*limit, limit)
)
}

const allResults = await Promise.allSettled(promises);
for (const result of allResults) {
if (result.status === "fulfilled"){
if(result.value.vulnerableRequests && result.value.vulnerableRequests !== undefined && result.value.vulnerableRequests.length > 0){
vulnerableRequests.push(...result.value.vulnerableRequests)
}
}
}
return vulnerableRequests
}

const fetchSubcategories = async () => {
let subCategories = []

let skip = 0
const limit = 200
for (let i = 0; i < 10; i++) {
const allSubCategoriesResponse = await testEditorRequests.fetchAllSubCategories("testEditor", skip, limit)
skip += limit

if (!allSubCategoriesResponse) {
break
}

let arr1 = allSubCategoriesResponse.subCategories
if (arr1 && arr1.length > 0) {
subCategories.push(...arr1)
}

if (!arr1 || arr1.length < limit) {
break
}
}

return subCategories
const metaDataObj = await transform.getAllSubcategoriesData(false, "testEditor")
return metaDataObj.subCategories
}

const fetchAllTests = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,31 @@ const transform = {
}
return conditions;
},
async getAllSubcategoriesData(fetchActive,type){
let finalDataSubCategories = [], promises = [], categories = [];
const limit = 50;
for(var i = 0 ; i < 20; i++){
promises.push(
api.fetchAllSubCategories(fetchActive, type, i * limit, limit)
)
}
const allResults = await Promise.allSettled(promises);
for (const result of allResults) {
if (result.status === "fulfilled"){
if(result?.value?.subCategories && result?.value?.subCategories !== undefined && result?.value?.subCategories.length > 0){
finalDataSubCategories.push(...result.value.subCategories);
}

if(result?.value?.categories && result?.value?.categories !== undefined && result?.value?.categories.length > 0){
categories.push(...result.value.categories);
}
}
}
return {
categories: categories,
subCategories: finalDataSubCategories
}
},
async setTestMetadata() {
const resp = await api.fetchAllSubCategories(false, "Dashboard");
let subCategoryMap = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Category from './Category';
import ReportRecommendations from './ReportRecommendations';
import ReportTOC from './ReportTOC';
import BarGraph from '../../../components/charts/BarGraph';
import transform from '../transform';

function VulnerabilityReport() {
const pdfRef = useRef();
Expand Down Expand Up @@ -183,33 +184,8 @@ function VulnerabilityReport() {
}

const fetchSubcategoriesAndCategories = async () => {
let subCategories = []
let categories = []

let skip = 0
const limit = 200
for (let i = 0; i < 10; i++) {
const allSubCategoriesResponse = await api.fetchAllSubCategories(true, "runTests", skip, limit)
if (!allSubCategoriesResponse) {
break
}
skip += limit

let arr1 = allSubCategoriesResponse.subCategories
if (arr1 && arr1.length > 0) {
subCategories.push(...arr1)
}

if (categories.length == 0 && allSubCategoriesResponse.categories && allSubCategoriesResponse.categories.length > 0) {
categories = allSubCategoriesResponse.categories
}

if (arr1.length < limit) {
break
}
}

return [subCategories, categories]
const metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
return [metaDataObj.subCategories, metaDataObj.categories]
}

const fetchVulnerableData = async () => {
Expand Down

0 comments on commit ce2c1a1

Please sign in to comment.