Skip to content

Commit

Permalink
Merge pull request #1882 from akto-api-security/feature/clean_up_reso…
Browse files Browse the repository at this point in the history
…urces

Feature/clean up resources
  • Loading branch information
notshivansh authored Jan 1, 2025
2 parents 1b70865 + 84a6cd8 commit 91e5a33
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class StartTestAction extends UserAction {
private Map<String,Integer> issuesSummaryInfoMap = new HashMap<>();

private String testRoleId;
private boolean cleanUpTestingResources;

private static final Gson gson = new Gson();

private static List<ObjectId> getTestingRunListFromSummary(Bson filters){
Expand Down Expand Up @@ -147,7 +149,7 @@ private TestingRun createTestingRun(int scheduleTimestamp, int periodInSeconds)
}
if (this.selectedTests != null) {
int id = UUID.randomUUID().hashCode() & 0xfffffff;
TestingRunConfig testingRunConfig = new TestingRunConfig(id, null, this.selectedTests, authMechanism.getId(), this.overriddenTestAppUrl, this.testRoleId);
TestingRunConfig testingRunConfig = new TestingRunConfig(id, null, this.selectedTests, authMechanism.getId(), this.overriddenTestAppUrl, this.testRoleId, this.cleanUpTestingResources);
// add advanced setting here
if(this.testConfigsAdvancedSettings != null && !this.testConfigsAdvancedSettings.isEmpty()){
testingRunConfig.setConfigsAdvancedSettings(this.testConfigsAdvancedSettings);
Expand Down Expand Up @@ -1401,4 +1403,12 @@ public Map<String, Integer> getTestCountMap() {
public void setReportFilterList(Map<String, List<String>> reportFilterList) {
this.reportFilterList = reportFilterList;
}

public boolean getCleanUpTestingResources() {
return cleanUpTestingResources;
}

public void setCleanUpTestingResources(boolean cleanUpTestingResources) {
this.cleanUpTestingResources = cleanUpTestingResources;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,20 @@ export default {
data: {}
})
},
scheduleTestForCollection(apiCollectionId, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings) {
scheduleTestForCollection(apiCollectionId, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings, cleanUpTestingResources) {
return request({
url: '/api/startTest',
method: 'post',
data: { apiCollectionId, type: "COLLECTION_WISE", startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings}
data: { apiCollectionId, type: "COLLECTION_WISE", startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings, cleanUpTestingResources}
}).then((resp) => {
return resp
})
},
scheduleTestForCustomEndpoints(apiInfoKeyList, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, source, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings) {
scheduleTestForCustomEndpoints(apiInfoKeyList, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, source, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings, cleanUpTestingResources) {
return request({
url: '/api/startTest',
method: 'post',
data: {apiInfoKeyList, type: "CUSTOM", startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, source, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings}
data: {apiInfoKeyList, type: "CUSTOM", startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, source, testRoleId, continuousTesting, sendSlackAlert, testConfigsAdvancedSettings, cleanUpTestingResources}
}).then((resp) => {
return resp
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
authMechanismPresent: false,
testRoleLabel: "No test role selected",
testRoleId: "",
sendSlackAlert: false
sendSlackAlert: false,
cleanUpTestingResources: false
}

const navigate = useNavigate()
Expand Down Expand Up @@ -413,7 +414,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
}

async function handleRun() {
const { startTimestamp, recurringDaily, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert } = testRun
const { startTimestamp, recurringDaily, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, cleanUpTestingResources } = testRun
const collectionId = parseInt(apiCollectionId)

const tests = testRun.tests
Expand Down Expand Up @@ -454,9 +455,9 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
}

if (filtered || selectedResourcesForPrimaryAction.length > 0) {
await observeApi.scheduleTestForCustomEndpoints(apiInfoKeyList, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, "TESTING_UI", testRoleId, continuousTesting, sendSlackAlert, finalAdvancedConditions)
await observeApi.scheduleTestForCustomEndpoints(apiInfoKeyList, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, "TESTING_UI", testRoleId, continuousTesting, sendSlackAlert, finalAdvancedConditions, cleanUpTestingResources)
} else {
await observeApi.scheduleTestForCollection(collectionId, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, finalAdvancedConditions)
await observeApi.scheduleTestForCollection(collectionId, startTimestamp, recurringDaily, selectedTests, testName, testRunTime, maxConcurrentRequests, overriddenTestAppUrl, testRoleId, continuousTesting, sendSlackAlert, finalAdvancedConditions, cleanUpTestingResources)
}

setActive(false)
Expand Down Expand Up @@ -767,6 +768,13 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
}
</HorizontalGrid>

{window.ACTIVE_ACCOUNT === 1723492815 &&
<Checkbox
label={"Clean up resources after test run. This will try to delete all resources created during test run."}
checked={testRun.cleanUpTestingResources}
onChange={() => setTestRun(prev => ({ ...prev, cleanUpTestingResources: !prev.cleanUpTestingResources }))}
/>
}

</VerticalStack>
</VerticalStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private static boolean removeCustomAuth(RawApi rawApi, List<CustomAuthType> cust
return removed;
}

private ExecutorSingleOperationResp modifyAuthTokenInRawApi(TestRoles testRole, RawApi rawApi) {
public static ExecutorSingleOperationResp modifyAuthTokenInRawApi(TestRoles testRole, RawApi rawApi) {
Map<String, List<String>> rawHeaders = rawApi.fetchReqHeaders();
for(AuthWithCond authWithCond: testRole.getAuthWithCondList()) {

Expand Down
Loading

0 comments on commit 91e5a33

Please sign in to comment.