diff --git a/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java b/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java index 614b0ece58..4653acee42 100644 --- a/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/testing/StartTestAction.java @@ -493,11 +493,12 @@ public String fetchTestingRunResultSummaries() { ); this.testingRunType = TestingRunType.ONE_TIME; - if(cicdCount > 0){ + if (cicdCount > 0) { this.testingRunType = TestingRunType.CI_CD; - } - else if(this.testingRun.getPeriodInSeconds() > 0){ + } else if (this.testingRun.getPeriodInSeconds() > 0) { this.testingRunType = TestingRunType.RECURRING; + } else if (this.testingRun.getPeriodInSeconds() == -1) { + this.testingRunType = TestingRunType.CONTINUOUS_TESTING; } if (this.testingRun != null && this.testingRun.getTestIdConfig() == 1) { @@ -1181,12 +1182,32 @@ public String modifyTestingRunConfig(){ if (existingTestingRun != null) { List updates = new ArrayList<>(); - if (editableTestingRunConfig.getTestRunTime() != 0 && editableTestingRunConfig.getTestRunTime() != existingTestingRun.getTestRunTime()) { + if (editableTestingRunConfig.getTestRunTime() > 0 + && editableTestingRunConfig.getTestRunTime() <= 6 * 60 * 60 + && editableTestingRunConfig.getTestRunTime() != existingTestingRun.getTestRunTime()) { updates.add(Updates.set(TestingRun.TEST_RUNTIME, editableTestingRunConfig.getTestRunTime())); } - - if (editableTestingRunConfig.getMaxConcurrentRequests() != 0 && editableTestingRunConfig.getMaxConcurrentRequests() != existingTestingRun.getMaxConcurrentRequests()) { - updates.add(Updates.set(TestingRun.MAX_CONCURRENT_REQUEST, editableTestingRunConfig.getMaxConcurrentRequests())); + + if (editableTestingRunConfig.getMaxConcurrentRequests() > 0 + && editableTestingRunConfig.getMaxConcurrentRequests() <= 100 && editableTestingRunConfig + .getMaxConcurrentRequests() != existingTestingRun.getMaxConcurrentRequests()) { + updates.add(Updates.set(TestingRun.MAX_CONCURRENT_REQUEST, + editableTestingRunConfig.getMaxConcurrentRequests())); + } + + if (existingTestingRun.getSendSlackAlert() != editableTestingRunConfig.getSendSlackAlert()) { + updates.add( + Updates.set(TestingRun.SEND_SLACK_ALERT, editableTestingRunConfig.getSendSlackAlert())); + } + + int periodInSeconds = 0; + if (editableTestingRunConfig.getContinuousTesting()) { + periodInSeconds = -1; + } else if (editableTestingRunConfig.getRecurringDaily()) { + periodInSeconds = 86400; + } + if (existingTestingRun.getPeriodInSeconds() != periodInSeconds) { + updates.add(Updates.set(TestingRun.PERIOD_IN_SECONDS, periodInSeconds)); } if (!updates.isEmpty()) { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx index 73e9fd597e..2218dd696b 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx @@ -193,32 +193,6 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu })); }); - // Efficient deep equality check - function areObjectArraysEqual(obj1, obj2) { - const keys1 = Object.keys(obj1); - const keys2 = Object.keys(obj2); - - if (keys1.length !== keys2.length) return false; - - const setKeys1 = new Set(keys1); - const setKeys2 = new Set(keys2); - if (setKeys1.size !== setKeys2.size || [...setKeys1].some(key => !setKeys2.has(key))) { - return false; - } - - for (let key of keys1) { - const arr1 = obj1[key].map(obj => JSON.stringify(obj)).sort(); - const arr2 = obj2[key].map(obj => JSON.stringify(obj)).sort(); - - if (arr1.length !== arr2.length || arr1.some((item, index) => item !== arr2[index])) { - return false; - } - } - - return true; - } - - if (!areObjectArraysEqual(updatedTests, testRun.tests)) { handleAddSettings(parentAdvanceSettingsConfig); const getRunTypeLabel = (runType) => { if (!runType) return "Now"; @@ -230,15 +204,18 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu ...testRun, tests: updatedTests, overriddenTestAppUrl: testIdConfig.testingRunConfig.overriddenTestAppUrl, + hasOverriddenTestAppUrl: testIdConfig?.testingRunConfig?.overriddenTestAppUrl?.length > 0, maxConcurrentRequests: testIdConfig.maxConcurrentRequests, testRunTime: testIdConfig.testRunTime, testRoleId: testIdConfig.testingRunConfig.testRoleId, testRunTimeLabel: (testIdConfig.testRunTime === -1) ? "30 minutes" : getLabel(testRunTimeOptions, testIdConfig.testRunTime.toString())?.label, testRoleLabel: getLabel(testRolesArr, testIdConfig.testingRunConfig.testRoleId).label, runTypeLabel: getRunTypeLabel(testRunType), - testName: testIdConfig.name + testName: testIdConfig.name, + sendSlackAlert: testIdConfig?.sendSlackAlert, + recurringDaily: testIdConfig?.periodInSeconds === 86400, + continuousTesting: testIdConfig?.periodInSeconds === -1 })); - } } setShouldRuntestConfig(false); }, [shouldRuntestConfig]) @@ -664,7 +641,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu <> : <> { +const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes, testRunTimeOptions, testRolesArr, maxConcurrentRequestsOptions, slackIntegrated, generateLabelForSlackIntegration,getLabel, timeFieldsDisabled }) => { return ( @@ -26,10 +26,10 @@ const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes continuousTesting, runTypeLabel: runType.label })); - }} disabled={showEditableSettings} /> + }} /> { @@ -114,7 +114,9 @@ const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes setTestRun(prev => ({ ...prev, hasOverriddenTestAppUrl: !prev.hasOverriddenTestAppUrl }))} + onChange={() => { + setTestRun(prev => ({ ...prev, hasOverriddenTestAppUrl: !prev.hasOverriddenTestAppUrl, overriddenTestAppUrl: "" })) + }} /> {testRun.hasOverriddenTestAppUrl &&
diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js index 34d9b69b43..f89ffdd48e 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/api.js @@ -475,8 +475,8 @@ export default { data: { latestTestingRunSummaryId, issueStatusQuery, sortKey, sortOrder, skip, limit, filters } }) }, - modifyTestingRunConfig(testingRunConfigId, editableConfigObject) { - const requestData = { testingRunConfigId, editableTestingRunConfig: editableConfigObject } + modifyTestingRunConfig(testingRunConfigId, editableTestingRunConfig) { + const requestData = { testingRunConfigId, editableTestingRunConfig } return request({ url: '/api/modifyTestingRunConfig', method: 'post', diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js index 2d3a898b9d..1990d50bb4 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js @@ -1133,10 +1133,13 @@ getMissingConfigs(testResults){ configsAdvancedSettings:settings, testRoleId: testRun.testRoleId, testSubCategoryList: selectedTests, - overriddenTestAppUrl: testRun.overriddenTestAppUrl, + overriddenTestAppUrl: testRun.hasOverriddenTestAppUrl ? testRun.overriddenTestAppUrl : "", maxConcurrentRequests: testRun.maxConcurrentRequests, testingRunHexId: hexId, testRunTime: testRun.testRunTime, + sendSlackAlert: testRun.sendSlackAlert, + recurringDaily: testRun.recurringDaily, + continuousTesting: testRun.continuousTesting, } } } diff --git a/libs/dao/src/main/java/com/akto/dto/testing/config/EditableTestingRunConfig.java b/libs/dao/src/main/java/com/akto/dto/testing/config/EditableTestingRunConfig.java index 8bcba2ef5f..5f5c366dac 100644 --- a/libs/dao/src/main/java/com/akto/dto/testing/config/EditableTestingRunConfig.java +++ b/libs/dao/src/main/java/com/akto/dto/testing/config/EditableTestingRunConfig.java @@ -5,6 +5,9 @@ public class EditableTestingRunConfig extends TestingRunConfig { private int maxConcurrentRequests; private String testingRunHexId; private int testRunTime; + private boolean sendSlackAlert; + private boolean recurringDaily; + private boolean continuousTesting; public EditableTestingRunConfig() { @@ -33,5 +36,29 @@ public String getTestingRunHexId() { public void setTestingRunHexId(String testingRunHexId) { this.testingRunHexId = testingRunHexId; } + + public boolean getSendSlackAlert() { + return sendSlackAlert; + } + + public void setSendSlackAlert(boolean sendSlackAlert) { + this.sendSlackAlert = sendSlackAlert; + } + + public boolean getRecurringDaily() { + return recurringDaily; + } + + public void setRecurringDaily(boolean recurringDaily) { + this.recurringDaily = recurringDaily; + } + + public boolean getContinuousTesting() { + return continuousTesting; + } + + public void setContinuousTesting(boolean continuousTesting) { + this.continuousTesting = continuousTesting; + } }