Skip to content

Commit

Permalink
Merge pull request #2044 from akto-api-security/hotfix/test_suite_bugs
Browse files Browse the repository at this point in the history
fix test suite state bugs
  • Loading branch information
notshivansh authored Feb 3, 2025
2 parents 5c1a685 + befef03 commit 9202c30
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1181,12 +1182,32 @@ public String modifyTestingRunConfig(){
if (existingTestingRun != null) {
List<Bson> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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])
Expand Down Expand Up @@ -664,7 +641,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
<Modal.Section>
<>
<RunTestConfiguration
showEditableSettings={setActiveFromTesting}
timeFieldsDisabled={showEditableSettings || activeFromTesting}
testRun={testRun}
setTestRun={setTestRun}
runTypeOptions={runTypeOptions}
Expand Down Expand Up @@ -836,7 +813,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
</div>
</div>
<RunTestConfiguration
showEditableSettings={setActiveFromTesting}
timeFieldsDisabled={showEditableSettings || activeFromTesting}
testRun={testRun}
setTestRun={setTestRun}
runTypeOptions={runTypeOptions}
Expand Down Expand Up @@ -864,7 +841,7 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
checkRemoveAll={checkRemoveAll} handleModifyConfig={handleModifyConfig} /> :
<>
<RunTestConfiguration
showEditableSettings={setActiveFromTesting}
timeFieldsDisabled={showEditableSettings || activeFromTesting}
testRun={testRun}
setTestRun={setTestRun}
runTypeOptions={runTypeOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VerticalStack, HorizontalGrid, Checkbox, TextField, Text } from '@shopi
import Dropdown from "../../../components/layouts/Dropdown";
import func from "@/util/func"

const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes, testRunTimeOptions, testRolesArr, maxConcurrentRequestsOptions, slackIntegrated, generateLabelForSlackIntegration,getLabel,showEditableSettings }) => {
const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes, testRunTimeOptions, testRolesArr, maxConcurrentRequestsOptions, slackIntegrated, generateLabelForSlackIntegration,getLabel, timeFieldsDisabled }) => {
return (
<VerticalStack gap={"4"}>
<HorizontalGrid gap={"4"} columns={"3"}>
Expand All @@ -26,10 +26,10 @@ const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes
continuousTesting,
runTypeLabel: runType.label
}));
}} disabled={showEditableSettings} />
}} />
<Dropdown
label="Select Time:"
disabled={testRun.continuousTesting === true || showEditableSettings}
disabled={testRun.continuousTesting === true || timeFieldsDisabled}
menuItems={hourlyTimes}
initial={testRun.hourlyLabel}
selected={(hour) => {
Expand Down Expand Up @@ -114,7 +114,9 @@ const RunTestConfiguration = ({ testRun, setTestRun, runTypeOptions, hourlyTimes
<Checkbox
label="Use different target for testing"
checked={testRun.hasOverriddenTestAppUrl}
onChange={() => setTestRun(prev => ({ ...prev, hasOverriddenTestAppUrl: !prev.hasOverriddenTestAppUrl }))}
onChange={() => {
setTestRun(prev => ({ ...prev, hasOverriddenTestAppUrl: !prev.hasOverriddenTestAppUrl, overriddenTestAppUrl: "" }))
}}
/>
{testRun.hasOverriddenTestAppUrl &&
<div style={{ width: '400px' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 9202c30

Please sign in to comment.