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/add test suites #2027

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1166e0e
still has bug
amitpanwar789 Jan 17, 2025
09e6eae
working but have bugs
amitpanwar789 Jan 19, 2025
b2ce1bc
test suite added
amitpanwar789 Jan 19, 2025
c65d38a
missed console.log removed
amitpanwar789 Jan 19, 2025
0447af8
type error in getCollectionId
amitpanwar789 Jan 19, 2025
fa1afac
dummyData recovered
amitpanwar789 Jan 19, 2025
400b0d7
dummy Data file removed
amitpanwar789 Jan 20, 2025
5dfe09e
Merge branch 'feature/add_test_suites' into feature/test_suite
amitpanwar789 Jan 20, 2025
680c4c4
ui of testcard fixed
amitpanwar789 Jan 20, 2025
aff833f
not done completely, need api to modify test_run object in editableCo…
amitpanwar789 Jan 23, 2025
80f1abd
test suite completed
amitpanwar789 Jan 28, 2025
fbf1a18
Merge pull request #1996 from amitpanwar789/feature/test_suite
Ark2307 Jan 28, 2025
ab9c27d
unnecessary fetchSubAllCategory reduced, all values are fetched corre…
amitpanwar789 Jan 28, 2025
1e459ef
select testModal selection minor bug fixed
amitpanwar789 Jan 29, 2025
53dadd1
testRunType reflect
amitpanwar789 Jan 29, 2025
2341564
getRunTypeLabelFixed
amitpanwar789 Jan 29, 2025
9e0be9c
Merge pull request #2029 from amitpanwar789/feature/test_suite
Ark2307 Jan 30, 2025
f1ea56e
Merge branch 'master' into feature/add_test_suites
Ark2307 Jan 30, 2025
6f7f1ac
Adding no upsert check
Ark2307 Jan 30, 2025
9bfcaf4
test selected text changed in test modal
amitpanwar789 Jan 30, 2025
bd8a766
Merge pull request #2033 from amitpanwar789/feature/test_suite
Ark2307 Jan 30, 2025
28c2011
unit test added for testModifyTestingRunConfig
amitpanwar789 Jan 30, 2025
14d2818
actionError are added
amitpanwar789 Jan 30, 2025
bf2568b
Merge branch 'feature/add_test_suites' into feature/test_suite
amitpanwar789 Jan 30, 2025
0636fa3
null check added for all values being modified
amitpanwar789 Jan 30, 2025
95bfa97
Merge pull request #2035 from amitpanwar789/feature/test_suite
notshivansh Jan 30, 2025
5480ddc
fix broken unit test
notshivansh Jan 30, 2025
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 @@ -6,6 +6,7 @@
import com.akto.dao.testing.sources.TestSourceConfigsDao;
import com.akto.dao.testing_run_findings.TestingRunIssuesDao;
import com.akto.dao.testing.*;
import com.akto.dto.testing.config.EditableTestingRunConfig;
import com.akto.dto.ApiInfo;
import com.akto.dto.User;
import com.akto.dto.ApiToken.Utility;
Expand Down Expand Up @@ -234,12 +235,13 @@ public String startTest() {
}

}

if (this.overriddenTestAppUrl != null || this.selectedTests != null) {
int id = UUID.randomUUID().hashCode() & 0xfffffff ;
int id = UUID.randomUUID().hashCode() & 0xfffffff;
TestingRunConfig testingRunConfig = new TestingRunConfig(id, null, this.selectedTests, null, this.overriddenTestAppUrl, this.testRoleId);
this.testIdConfig = testingRunConfig.getId();
TestingRunConfigDao.instance.insertOne(testingRunConfig);
}
}

}

Expand Down Expand Up @@ -506,7 +508,7 @@ else if(this.testingRun.getPeriodInSeconds() > 0){
}

TestingRunConfig runConfig = TestingRunConfigDao.instance.findOne(
Filters.eq("_id", this.testingRun.getTestIdConfig()), Projections.exclude("collectionWiseApiInfoKey", "testSubCategoryList")
Filters.eq("_id", this.testingRun.getTestIdConfig()), Projections.exclude("collectionWiseApiInfoKey")
);

this.testingRun.setTestingRunConfig(runConfig);
Expand Down Expand Up @@ -1125,11 +1127,70 @@ public String getCurrentTestStateStatus(){
return Action.SUCCESS.toUpperCase();
}

private EditableTestingRunConfig editableTestingRunConfig;

public String modifyTestingRunConfig(){
TestingRunConfigDao.instance.updateOne(
Filters.eq(Constants.ID, this.testingRunConfigId),
Updates.set("configsAdvancedSettings", this.testConfigsAdvancedSettings)
);
if (editableTestingRunConfig == null) {
addActionError("Invalid editableTestingRunConfig");
return Action.ERROR.toUpperCase();
}
try {
if (this.testingRunConfigId == 0) {
addActionError("Invalid testing run config id");
return Action.ERROR.toUpperCase();
} else {

TestingRunConfig existingTestingRunConfig = TestingRunConfigDao.instance.findOne(Filters.eq(Constants.ID, this.testingRunConfigId));
if (existingTestingRunConfig == null) {
addActionError("Testing run config object not found for ID: " + this.testingRunConfigId);
return Action.ERROR.toUpperCase();
}

if (editableTestingRunConfig.getConfigsAdvancedSettings() != null) {
existingTestingRunConfig.setConfigsAdvancedSettings(editableTestingRunConfig.getConfigsAdvancedSettings());
}

if (editableTestingRunConfig.getTestSubCategoryList() != null) {
existingTestingRunConfig.setTestSubCategoryList(editableTestingRunConfig.getTestSubCategoryList());
}

if (editableTestingRunConfig.getTestRoleId() != null) {
existingTestingRunConfig.setTestRoleId(editableTestingRunConfig.getTestRoleId());
}

if (editableTestingRunConfig.getOverriddenTestAppUrl() != null) {
existingTestingRunConfig.setOverriddenTestAppUrl(editableTestingRunConfig.getOverriddenTestAppUrl());
}

TestingRunConfigDao.instance.replaceOne(Filters.eq(Constants.ID, this.testingRunConfigId), existingTestingRunConfig);
}

if (editableTestingRunConfig.getTestingRunHexId() != null) {

TestingRun existingTestingRun = TestingRunDao.instance.findOne(Filters.eq(Constants.ID, new ObjectId(editableTestingRunConfig.getTestingRunHexId())));

if (existingTestingRun != null) {
if (editableTestingRunConfig.getTestRunTime() != 0) {
existingTestingRun.setTestRunTime(editableTestingRunConfig.getTestRunTime());
}

if (editableTestingRunConfig.getMaxConcurrentRequests() != 0) {
existingTestingRun.setMaxConcurrentRequests(editableTestingRunConfig.getMaxConcurrentRequests());
}

TestingRunDao.instance.replaceOne(
Filters.eq(Constants.ID, new ObjectId(editableTestingRunConfig.getTestingRunHexId())),
existingTestingRun
);
}

}


} catch (Exception e) {
addActionError("Unable to modify testing run config and testing run");
return Action.ERROR.toUpperCase();
}
return SUCCESS.toUpperCase();
}

Expand Down Expand Up @@ -1568,6 +1629,10 @@ public void setTestingRunConfigId(int testingRunConfigId) {
this.testingRunConfigId = testingRunConfigId;
}

public void setEditableTestingRunConfig(EditableTestingRunConfig editableTestingRunConfig) {
this.editableTestingRunConfig = editableTestingRunConfig;
}

public Map<String, Integer> getTestCountMap() {
return testCountMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import com.akto.dao.UsersDao;
import com.akto.dao.billing.OrganizationsDao;
import com.akto.dao.context.Context;
import com.akto.dao.testing.TestingRunConfigDao;
import com.akto.dao.testing.TestingRunDao;
import com.akto.dao.testing.TestingRunResultSummariesDao;
import com.akto.dto.testing.config.EditableTestingRunConfig;
import com.akto.dto.AccountSettings;
import com.akto.dto.ApiInfo;
import com.akto.dto.ApiToken;
Expand Down Expand Up @@ -266,4 +268,52 @@ public void testStartCICDTest() throws IOException, ServletException {

}

@Test
public void testModifyTestingRunConfig() {

int testingRunConfigId = UUID.randomUUID().hashCode() & 0xfffffff;
ObjectId testingRunHexId = new ObjectId();

List<String> list1 = Arrays.asList("pkucgztk", "oionxmec", "tmptskkz", "rorcqyqf");
List<String> list2 = Arrays.asList("sqhrduyv", "awpqhaxz", "tdzydooe", "hxwvtoem");
TestingRunConfig testingRunConfig = new TestingRunConfig();
testingRunConfig.setTestRoleId("initialRole");
testingRunConfig.setOverriddenTestAppUrl("https://initial.url");
testingRunConfig.setTestSubCategoryList(list1);

TestingRunConfigDao.instance.insertOne(testingRunConfig);

TestingRun testingRun = new TestingRun();
testingRun.setTestIdConfig(testingRunConfigId);
testingRun.setTestRunTime(1800);
testingRun.setMaxConcurrentRequests(5);
testingRun.setId(testingRunHexId);

TestingRunDao.instance.insertOne(testingRun);

EditableTestingRunConfig editableTestingRunConfig = new EditableTestingRunConfig();
editableTestingRunConfig.setTestRunTime(3600);
editableTestingRunConfig.setTestRoleId("newRole");
editableTestingRunConfig.setOverriddenTestAppUrl("https://test.url");
editableTestingRunConfig.setMaxConcurrentRequests(10);
editableTestingRunConfig.setTestSubCategoryList(list2);

StartTestAction startTestAction = new StartTestAction();
startTestAction.setTestingRunConfigId(testingRunConfigId);
startTestAction.setEditableTestingRunConfig(editableTestingRunConfig);

String result = startTestAction.modifyTestingRunConfig();

assertEquals(Action.SUCCESS.toUpperCase(), result);

TestingRunConfig updatedConfig = TestingRunConfigDao.instance.findOne(Filters.eq(Constants.ID, testingRunConfigId));
assertEquals("newRole", updatedConfig.getTestRoleId());
assertEquals("https://test.url", updatedConfig.getOverriddenTestAppUrl());
assertEquals(list2, updatedConfig.getTestSubCategoryList());

TestingRun updatedTestingRun = TestingRunDao.instance.findOne(Filters.eq(Constants.ID, testingRunHexId));
assertEquals(3600, updatedTestingRun.getTestRunTime());
assertEquals(10, updatedTestingRun.getMaxConcurrentRequests());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ function ApiDetails(props) {
endpoints={[apiDetail]}
filtered={true}
useLocalSubCategoryData={useLocalSubCategoryData}
preActivator={false}
/>
<Box>
<Tooltip content="Open URL in test editor" dismissOnMouseOut>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ function ApiEndpoints(props) {
closeRunTest={() => setRunTests(false)}
disabled={showEmptyScreen}
selectedResourcesForPrimaryAction={selectedResourcesForPrimaryAction}
preActivator={false}
/>
</HorizontalStack>
)
Expand Down
Loading
Loading