3
3
import com .akto .action .UserAction ;
4
4
import com .akto .billing .UsageMetricUtils ;
5
5
import com .akto .dao .context .Context ;
6
+ import com .akto .dao .monitoring .ModuleInfoDao ;
6
7
import com .akto .dao .test_editor .YamlTemplateDao ;
7
- import com .akto .dao .testing .DeleteTestRunsDao ;
8
- import com .akto .dao .testing .TestRolesDao ;
9
- import com .akto .dao .testing .TestingRunConfigDao ;
10
- import com .akto .dao .testing .TestingRunDao ;
11
- import com .akto .dao .testing .TestingRunResultDao ;
12
- import com .akto .dao .testing .TestingRunResultSummariesDao ;
13
- import com .akto .dao .testing .VulnerableTestingRunResultDao ;
14
- import com .akto .dao .testing .WorkflowTestsDao ;
8
+ import com .akto .dao .testing .*;
15
9
import com .akto .dao .testing .sources .TestSourceConfigsDao ;
16
10
import com .akto .dao .testing_run_findings .TestingRunIssuesDao ;
17
- import com .akto .dao .testing .*;
18
- import com .akto .dao .testing .config .TestSuiteDao ;
19
- import com .akto .dto .ApiCollection ;
20
- import com .akto .dto .billing .FeatureAccess ;
21
- import com .akto .dto .testing .config .EditableTestingRunConfig ;
22
- import com .akto .dto .testing .config .TestSuites ;
23
11
import com .akto .dto .ApiInfo ;
24
12
import com .akto .dto .ApiToken .Utility ;
25
13
import com .akto .dto .CollectionConditions .TestConfigsAdvancedSettings ;
26
14
import com .akto .dto .User ;
15
+ import com .akto .dto .billing .FeatureAccess ;
16
+ import com .akto .dto .monitoring .ModuleInfo ;
27
17
import com .akto .dto .test_editor .Info ;
28
18
import com .akto .dto .test_run_findings .TestingIssuesId ;
29
19
import com .akto .dto .test_run_findings .TestingRunIssues ;
30
- import com .akto .dto .testing .AuthMechanism ;
31
- import com .akto .dto .testing .AutoTicketingDetails ;
32
- import com .akto .dto .testing .CollectionWiseTestingEndpoints ;
33
- import com .akto .dto .testing .CustomTestingEndpoints ;
34
- import com .akto .dto .testing .DeleteTestRuns ;
35
- import com .akto .dto .testing .GenericTestResult ;
36
- import com .akto .dto .testing .MultiExecTestResult ;
37
- import com .akto .dto .testing .TestResult ;
20
+ import com .akto .dto .testing .*;
38
21
import com .akto .dto .testing .TestResult .TestError ;
39
- import com .akto .dto .testing .TestingEndpoints ;
40
- import com .akto .dto .testing .TestingRun ;
41
22
import com .akto .dto .testing .TestingRun .State ;
42
23
import com .akto .dto .testing .TestingRun .TestingRunType ;
43
- import com .akto .dto .testing .TestingRunConfig ;
44
- import com .akto .dto .testing .TestingRunResult ;
45
- import com .akto .dto .testing .TestingRunResultSummary ;
46
- import com .akto .dto .testing .WorkflowTest ;
47
- import com .akto .dto .testing .WorkflowTestingEndpoints ;
48
24
import com .akto .dto .testing .config .EditableTestingRunConfig ;
49
25
import com .akto .dto .testing .info .CurrentTestsStatus ;
50
26
import com .akto .dto .testing .info .CurrentTestsStatus .StatusForIndividualTest ;
51
27
import com .akto .dto .testing .sources .TestSourceConfig ;
52
- import com .akto .dto .usage .MetricTypes ;
53
28
import com .akto .log .LoggerMaker ;
54
29
import com .akto .log .LoggerMaker .LogDb ;
55
- import com .akto .testing .TestCompletion ;
56
30
import com .akto .usage .UsageMetricCalculator ;
57
- import com .akto .usage .UsageMetricHandler ;
58
31
import com .akto .util .Constants ;
59
- import com .akto .util .UsageUtils ;
60
32
import com .akto .util .enums .GlobalEnums ;
61
33
import com .akto .util .enums .GlobalEnums .Severity ;
62
34
import com .akto .util .enums .GlobalEnums .TestErrorSource ;
63
35
import com .akto .utils .DeleteTestRunUtils ;
64
36
import com .akto .utils .Utils ;
65
37
import com .google .gson .Gson ;
66
- import com .mongodb .client .model .Aggregates ;
67
- import com .mongodb .client .model .Filters ;
68
- import com .mongodb .client .model .Projections ;
69
- import com .mongodb .client .model .Sorts ;
70
- import com .mongodb .client .model .Updates ;
38
+ import com .mongodb .client .model .*;
71
39
import com .mongodb .client .result .InsertOneResult ;
72
40
import com .opensymphony .xwork2 .Action ;
73
- import java .time .Instant ;
74
- import java .util .ArrayList ;
75
- import java .util .Arrays ;
76
- import java .util .HashMap ;
77
- import java .util .HashSet ;
78
- import java .util .Iterator ;
79
- import java .util .List ;
80
- import java .util .Map ;
81
- import java .util .Set ;
82
- import java .util .UUID ;
83
- import java .util .concurrent .Callable ;
84
- import java .util .concurrent .ExecutorService ;
85
- import java .util .concurrent .Executors ;
86
- import java .util .concurrent .Future ;
87
- import java .util .concurrent .ScheduledExecutorService ;
88
- import java .util .concurrent .TimeUnit ;
89
- import java .util .regex .Pattern ;
90
- import java .util .stream .Collectors ;
91
41
import org .apache .commons .lang3 .StringUtils ;
92
42
import org .bson .conversions .Bson ;
93
43
import org .bson .types .ObjectId ;
94
44
45
+ import java .time .Instant ;
46
+ import java .util .*;
47
+ import java .util .concurrent .*;
48
+ import java .util .regex .Pattern ;
49
+ import java .util .stream .Collectors ;
50
+
95
51
public class StartTestAction extends UserAction {
96
52
97
53
private TestingEndpoints .Type type ;
@@ -161,7 +117,7 @@ private static List<ObjectId> getTestsWithSeverity(List<String> severities) {
161
117
private boolean sendSlackAlert = false ;
162
118
private boolean sendMsTeamsAlert = false ;
163
119
164
- private TestingRun createTestingRun (int scheduleTimestamp , int periodInSeconds ) {
120
+ private TestingRun createTestingRun (int scheduleTimestamp , int periodInSeconds , String miniTestingServiceName ) {
165
121
User user = getSUser ();
166
122
167
123
if (!StringUtils .isEmpty (this .overriddenTestAppUrl )) {
@@ -221,9 +177,10 @@ private TestingRun createTestingRun(int scheduleTimestamp, int periodInSeconds)
221
177
222
178
return new TestingRun (scheduleTimestamp , user .getLogin (),
223
179
testingEndpoints , testIdConfig , State .SCHEDULED , periodInSeconds , testName , this .testRunTime ,
224
- this .maxConcurrentRequests , this .sendSlackAlert , this .sendMsTeamsAlert );
180
+ this .maxConcurrentRequests , this .sendSlackAlert , this .sendMsTeamsAlert , miniTestingServiceName );
225
181
}
226
182
183
+ String selectedMiniTestingServiceName ;
227
184
private List <String > selectedTests ;
228
185
private List <TestConfigsAdvancedSettings > testConfigsAdvancedSettings ;
229
186
@@ -268,7 +225,7 @@ public String startTest() {
268
225
}
269
226
if (localTestingRun == null ) {
270
227
try {
271
- localTestingRun = createTestingRun (scheduleTimestamp , getPeriodInSeconds (recurringDaily , recurringWeekly , recurringMonthly ));
228
+ localTestingRun = createTestingRun (scheduleTimestamp , getPeriodInSeconds (recurringDaily , recurringWeekly , recurringMonthly ), selectedMiniTestingServiceName );
272
229
// pass boolean from ui, which will tell if testing is coniinuous on new endpoints
273
230
if (this .continuousTesting ) {
274
231
localTestingRun .setPeriodInSeconds (-1 );
@@ -331,7 +288,7 @@ public String startTest() {
331
288
Updates .set (TestingRun .STATE , TestingRun .State .COMPLETED ),
332
289
Updates .set (TestingRun .END_TIMESTAMP , Context .now ())));
333
290
}
334
-
291
+
335
292
}
336
293
337
294
if (this .overriddenTestAppUrl != null || this .selectedTests != null ) {
@@ -342,7 +299,7 @@ public String startTest() {
342
299
testingRunConfig .setTestSuiteIds (testSuiteIdsObj );
343
300
this .testIdConfig = testingRunConfig .getId ();
344
301
TestingRunConfigDao .instance .insertOne (testingRunConfig );
345
- }
302
+ }
346
303
347
304
}
348
305
@@ -760,7 +717,7 @@ public String fetchTestRunResultsCount() {
760
717
return ERROR .toUpperCase ();
761
718
}
762
719
763
-
720
+
764
721
int accountId = Context .accountId .get ();
765
722
766
723
testCountMap = new HashMap <>();
@@ -787,9 +744,9 @@ public String fetchTestRunResultsCount() {
787
744
} catch (Exception e ) {
788
745
e .printStackTrace ();
789
746
}
790
-
747
+
791
748
}
792
-
749
+
793
750
} catch (Exception e ) {
794
751
e .printStackTrace ();
795
752
return ERROR .toUpperCase ();
@@ -938,9 +895,9 @@ public String fetchVulnerableTestRunResults() {
938
895
}else {
939
896
testingRunResultList = TestingRunResultDao .instance .findAll (filters , skip , 50 , null );
940
897
}
941
-
942
898
943
-
899
+
900
+
944
901
// Map<String, String> sampleDataVsCurlMap = new HashMap<>();
945
902
// for (TestingRunResult runResult: testingRunResultList) {
946
903
// WorkflowTest workflowTest = runResult.getWorkflowTest();
@@ -1306,11 +1263,11 @@ public String modifyTestingRunConfig(){
1306
1263
if (editableTestingRunConfig .getTestSubCategoryList () != null && !editableTestingRunConfig .getTestSubCategoryList ().equals (existingTestingRunConfig .getTestSubCategoryList ())) {
1307
1264
updates .add (Updates .set (TestingRunConfig .TEST_SUBCATEGORY_LIST , editableTestingRunConfig .getTestSubCategoryList ()));
1308
1265
}
1309
-
1266
+
1310
1267
if (editableTestingRunConfig .getTestRoleId () != null && !editableTestingRunConfig .getTestRoleId ().equals (existingTestingRunConfig .getTestRoleId ())) {
1311
1268
updates .add (Updates .set (TestingRunConfig .TEST_ROLE_ID , editableTestingRunConfig .getTestRoleId ()));
1312
1269
}
1313
-
1270
+
1314
1271
if (editableTestingRunConfig .getOverriddenTestAppUrl () != null && !editableTestingRunConfig .getOverriddenTestAppUrl ().equals (existingTestingRunConfig .getOverriddenTestAppUrl ())) {
1315
1272
updates .add (Updates .set (TestingRunConfig .OVERRIDDEN_TEST_APP_URL , editableTestingRunConfig .getOverriddenTestAppUrl ()));
1316
1273
}
@@ -1320,17 +1277,17 @@ public String modifyTestingRunConfig(){
1320
1277
updates .add (Updates .set (TestingRunConfig .AUTO_TICKETING_DETAILS ,
1321
1278
editableTestingRunConfig .getAutoTicketingDetails ()));
1322
1279
}
1323
-
1280
+
1324
1281
if (!updates .isEmpty ()) {
1325
1282
TestingRunConfigDao .instance .updateOne (
1326
1283
Filters .eq (Constants .ID , this .testingRunConfigId ),
1327
- Updates .combine (updates )
1284
+ Updates .combine (updates )
1328
1285
);
1329
1286
}
1330
1287
}
1331
1288
1332
1289
if (editableTestingRunConfig .getTestingRunHexId () != null ) {
1333
-
1290
+
1334
1291
TestingRun existingTestingRun = TestingRunDao .instance .findOne (Filters .eq (Constants .ID , new ObjectId (editableTestingRunConfig .getTestingRunHexId ())));
1335
1292
1336
1293
if (existingTestingRun != null ) {
@@ -1375,15 +1332,15 @@ public String modifyTestingRunConfig(){
1375
1332
)
1376
1333
);
1377
1334
}
1378
-
1335
+
1379
1336
if (!updates .isEmpty ()) {
1380
1337
TestingRunDao .instance .updateOne (
1381
1338
Filters .eq (Constants .ID ,new ObjectId (editableTestingRunConfig .getTestingRunHexId ())),
1382
- Updates .combine (updates )
1339
+ Updates .combine (updates )
1383
1340
);
1384
1341
}
1385
1342
}
1386
-
1343
+
1387
1344
}
1388
1345
1389
1346
@@ -1468,7 +1425,7 @@ public void run() {
1468
1425
Updates .set (TestingRunResult .IS_IGNORED_RESULT , true )
1469
1426
);
1470
1427
}
1471
-
1428
+
1472
1429
} catch (Exception e ) {
1473
1430
e .printStackTrace ();
1474
1431
}
@@ -1511,6 +1468,22 @@ private boolean validateAutoTicketingDetails(AutoTicketingDetails autoTicketingD
1511
1468
return true ;
1512
1469
}
1513
1470
1471
+ private Set <String > miniTestingServiceNames ;
1472
+ public String fetchMiniTestingServiceNames () {
1473
+ List <ModuleInfo > moduleInfos = ModuleInfoDao .instance .findAll (Filters .and (
1474
+ Filters .eq (ModuleInfo .MODULE_TYPE , ModuleInfo .ModuleType .MINI_TESTING ),
1475
+ Filters .gt (ModuleInfo .LAST_HEARTBEAT_RECEIVED , Context .now () - 20 * 60 )));
1476
+ if (this .miniTestingServiceNames == null ) {
1477
+ this .miniTestingServiceNames = new HashSet <>();
1478
+ }
1479
+ for (ModuleInfo moduleInfo : moduleInfos ) {
1480
+ if (moduleInfo .getName () != null ) {
1481
+ this .miniTestingServiceNames .add (moduleInfo .getName ());
1482
+ }
1483
+ }
1484
+ return SUCCESS .toUpperCase ();
1485
+ }
1486
+
1514
1487
1515
1488
public void setType (TestingEndpoints .Type type ) {
1516
1489
this .type = type ;
@@ -1893,7 +1866,7 @@ public void setSendMsTeamsAlert(boolean sendMsTeamsAlert) {
1893
1866
public void setRecurringWeekly (boolean recurringWeekly ) {
1894
1867
this .recurringWeekly = recurringWeekly ;
1895
1868
}
1896
-
1869
+
1897
1870
public void setRecurringMonthly (boolean recurringMonthly ) {
1898
1871
this .recurringMonthly = recurringMonthly ;
1899
1872
}
@@ -1905,4 +1878,16 @@ public void setTestSuiteIds(List<String> testSuiteIds) {
1905
1878
public void setAutoTicketingDetails (AutoTicketingDetails autoTicketingDetails ) {
1906
1879
this .autoTicketingDetails = autoTicketingDetails ;
1907
1880
}
1881
+
1882
+ public Set <String > getMiniTestingServiceNames () {
1883
+ return miniTestingServiceNames ;
1884
+ }
1885
+
1886
+ public void setMiniTestingServiceNames (Set <String > miniTestingServiceNames ) {
1887
+ this .miniTestingServiceNames = miniTestingServiceNames ;
1888
+ }
1889
+
1890
+ public void setSelectedMiniTestingServiceName (String selectedMiniTestingServiceName ) {
1891
+ this .selectedMiniTestingServiceName = selectedMiniTestingServiceName ;
1892
+ }
1908
1893
}
0 commit comments