2424import com .endava .cats .openapi .handler .index .SpecPositionIndex ;
2525import com .endava .cats .report .ExecutionStatisticsListener ;
2626import com .endava .cats .report .TestCaseListener ;
27+ import com .endava .cats .util .AnsiUtils ;
2728import com .endava .cats .util .CatsRandom ;
2829import com .endava .cats .util .CatsUtil ;
2930import com .endava .cats .util .ConsoleUtils ;
3839import jakarta .inject .Inject ;
3940import lombok .Getter ;
4041import org .eclipse .microprofile .config .inject .ConfigProperty ;
41- import org .fusesource .jansi .Ansi ;
4242import picocli .AutoComplete ;
4343import picocli .CommandLine ;
4444
5858import java .util .concurrent .TimeUnit ;
5959import java .util .stream .Collectors ;
6060
61- import static org .fusesource .jansi .Ansi .ansi ;
62-
6361/**
6462 * Main application command.
6563 */
@@ -139,11 +137,11 @@ public class CatsCommand implements Runnable, CommandLine.IExitCodeGenerator, Au
139137
140138 @ Inject
141139 @ CommandLine .ArgGroup (heading = "%n@|bold,underline Authentication Options:|@%n" , exclusive = false )
142- AuthArguments authArgs ;
140+ AuthArguments authArguments ;
143141
144142 @ Inject
145143 @ CommandLine .ArgGroup (heading = "%n@|bold,underline Check Options:|@%n" , exclusive = false )
146- CheckArguments checkArgs ;
144+ CheckArguments checkArguments ;
147145
148146 @ Inject
149147 @ CommandLine .ArgGroup (heading = "%n@|bold,underline Files Options:|@%n" , exclusive = false )
@@ -231,26 +229,9 @@ void printVersion(Future<VersionChecker.CheckResult> newVersion) throws Executio
231229 VersionChecker .CheckResult checkResult = newVersion .get ();
232230 logger .debug ("Current version {}. Latest version {}" , appVersion , checkResult .getVersion ());
233231 if (checkResult .isNewVersion ()) {
234- String message = ansi ()
235- .bold ()
236- .fgBrightBlue ()
237- .a ("A new version is available: {}. Download url: {}" )
238- .reset ()
239- .toString ();
240- String currentVersionFormatted = ansi ()
241- .bold ()
242- .fgBrightBlue ()
243- .a (checkResult .getVersion ())
244- .reset ()
245- .bold ()
246- .fgBrightBlue ()
247- .toString ();
248- String downloadUrlFormatted = ansi ()
249- .bold ()
250- .fgGreen ()
251- .a (checkResult .getDownloadUrl ())
252- .reset ()
253- .toString ();
232+ String message = AnsiUtils .boldBrightBlue ("A new version is available: {}. Download url: {}" );
233+ String currentVersionFormatted = AnsiUtils .boldBrightBlue (checkResult .getVersion ());
234+ String downloadUrlFormatted = AnsiUtils .boldGreen (checkResult .getDownloadUrl ());
254235 logger .star (message , currentVersionFormatted , downloadUrlFormatted );
255236 }
256237 }
@@ -295,21 +276,11 @@ Future<VersionChecker.CheckResult> checkForNewVersion() {
295276
296277 private void printSuggestions () {
297278 if (executionStatisticsListener .areManyAuthErrors ()) {
298- String message = ansi ()
299- .bold ()
300- .fgBrightYellow ()
301- .a ("There were {} tests failing with authorisation errors. Either supply authentication details or check if the supplied credentials are correct!" )
302- .reset ()
303- .toString ();
279+ String message = AnsiUtils .boldYellow ("There were {} tests failing with authorisation errors. Either supply authentication details or check if the supplied credentials are correct!" );
304280 logger .star (message , executionStatisticsListener .getAuthErrors ());
305281 }
306282 if (executionStatisticsListener .areManyIoErrors ()) {
307- String message = ansi ()
308- .bold ()
309- .fgBrightYellow ()
310- .a ("There were {} tests failing with i/o errors. Make sure that you have access to the service or that the --server url is correct!" )
311- .reset ()
312- .toString ();
283+ String message = AnsiUtils .boldYellow ("There were {} tests failing with i/o errors. Make sure that you have access to the service or that the --server url is correct!" );
313284 logger .star (message , executionStatisticsListener .getIoErrors ());
314285 }
315286 }
@@ -363,7 +334,7 @@ private void executeCustomFuzzer() throws IOException {
363334 }
364335
365336 OpenAPI createOpenAPI () throws IOException {
366- String finishMessage = ansi (). fgGreen (). a ( "Finished parsing the contract in {} ms" ). reset (). toString ( );
337+ String finishMessage = AnsiUtils . green ( "Finished parsing the contract in {} ms" );
367338 long t0 = System .currentTimeMillis ();
368339 OpenAPI openAPI = OpenApiUtils .readOpenApi (apiArguments .getContract ());
369340 logger .debug (finishMessage , (System .currentTimeMillis () - t0 ));
@@ -381,41 +352,41 @@ void prepareRun() throws IOException {
381352 }
382353
383354 private void printConfiguration (OpenAPI openAPI ) {
384- logger .config (ansi () .bold (). a ( "OpenAPI specs: {}" ). reset (). toString (), ansi (). fg ( Ansi . Color . BLUE ). a ( apiArguments .getContract ()). reset ( ));
385- logger .config (ansi () .bold (). a ( "API base url: {}" ). reset (). toString (), ansi (). fg ( Ansi . Color . BLUE ). a ( apiArguments .getServer ()). reset ( ));
386- logger .config (ansi () .bold (). a ( "Reporting path: {}" ). reset (). toString (), ansi (). fg ( Ansi . Color . BLUE ). a ( reportingArguments .getOutputReportFolder ()). reset ( ));
387- logger .config (ansi () .bold (). a ( "{} configured fuzzers out of {} total fuzzers" ). bold (). reset (). toString ( ),
388- ansi (). fg ( Ansi . Color . BLUE ). a ( filterArguments .getFirstPhaseFuzzersForPath ().size ()). reset (). bold ( ),
389- ansi (). fg ( Ansi . Color . BLUE ). a ( filterArguments .getAllRegisteredFuzzers ().size ()). reset (). bold ( ));
390- logger .config (ansi () .bold (). a ( "{} configured paths out of {} total OpenAPI paths" ). bold (). reset (). toString ( ),
391- ansi (). fg ( Ansi . Color . BLUE ). a ( filterArguments .getPathsToRun (openAPI ).size ()). bold (). reset (). bold ( ),
392- ansi (). fg ( Ansi . Color . BLUE ). a ( openAPI .getPaths ().size ()). reset (). bold ( ));
393- logger .config (ansi () .bold (). a ( "HTTP methods in scope: {}" ). reset (). toString (), ansi (). fg ( Ansi . Color . BLUE ). a ( filterArguments .getHttpMethods ()). reset ( ));
394- logger .config (ansi () .bold (). bold (). a ( "Example flags: useRequestBodyExamples {}, useSchemaExamples {}, usePropertyExamples {}, useResponseBodyExamples {}, useDefaults {}" ). reset (). toString ( ),
395- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .isUseRequestBodyExamples ()). reset (). bold ( ),
396- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .isUseSchemaExamples ()). reset (). bold ( ),
397- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .isUsePropertyExamples ()). reset (). bold ( ),
398- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .isUseResponseBodyExamples ()). reset (). bold ( ),
399- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .isUseDefaults ()). reset (). bold ( ));
400- logger .config (ansi () .bold (). a ( "selfReferenceDepth {}, largeStringsSize {}, randomHeadersNumber {}, limitFuzzedFields {}, limitXxxOfCombinations {}" ). reset (). toString ( ),
401- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getSelfReferenceDepth ()). reset (). bold ( ),
402- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getLargeStringsSize ()). reset (). bold ( ),
403- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getRandomHeadersNumber ()). reset (). bold ( ),
404- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getLimitNumberOfFields ()). reset (). bold ( ),
405- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getLimitXxxOfCombinations ()). reset (). bold ( ));
406- logger .config (ansi () .bold (). a ( "How the service handles whitespaces and random unicodes: edgeSpacesStrategy {}, sanitizationStrategy {}" ). reset (). toString ( ),
407- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getEdgeSpacesStrategy ()). reset (). bold ( ),
408- ansi (). fg ( Ansi . Color . BLUE ). a ( processingArguments .getSanitizationStrategy ()). reset (). bold ( ));
409- logger .config (ansi () .bold (). a ( "Seed value: {}" ). reset (). toString ( ),
410- ansi (). fg ( Ansi . Color . BLUE ). a ( CatsRandom .getStoredSeed ()). reset (). bold ( ));
355+ logger .config (AnsiUtils .bold ("OpenAPI specs: {}" ), AnsiUtils . blue ( apiArguments .getContract ()));
356+ logger .config (AnsiUtils .bold ("API base url: {}" ), AnsiUtils . blue ( apiArguments .getServer ()));
357+ logger .config (AnsiUtils .bold ("Reporting path: {}" ), AnsiUtils . blue ( reportingArguments .getOutputReportFolder ()));
358+ logger .config (AnsiUtils .bold ("{} configured fuzzers out of {} total fuzzers" ),
359+ AnsiUtils . boldBlue ( filterArguments .getFirstPhaseFuzzersForPath ().size ()),
360+ AnsiUtils . boldBlue ( filterArguments .getAllRegisteredFuzzers ().size ()));
361+ logger .config (AnsiUtils .bold ("{} configured paths out of {} total OpenAPI paths" ),
362+ AnsiUtils . boldBlue ( filterArguments .getPathsToRun (openAPI ).size ()),
363+ AnsiUtils . boldBlue ( openAPI .getPaths ().size ()));
364+ logger .config (AnsiUtils .bold ("HTTP methods in scope: {}" ), AnsiUtils . blue ( filterArguments .getHttpMethods ()));
365+ logger .config (AnsiUtils .bold ("Example flags: useRequestBodyExamples {}, useSchemaExamples {}, usePropertyExamples {}, useResponseBodyExamples {}, useDefaults {}" ),
366+ AnsiUtils . boldBlue ( processingArguments .isUseRequestBodyExamples ()),
367+ AnsiUtils . boldBlue ( processingArguments .isUseSchemaExamples ()),
368+ AnsiUtils . boldBlue ( processingArguments .isUsePropertyExamples ()),
369+ AnsiUtils . boldBlue ( processingArguments .isUseResponseBodyExamples ()),
370+ AnsiUtils . boldBlue ( processingArguments .isUseDefaults ()));
371+ logger .config (AnsiUtils .bold ("selfReferenceDepth {}, largeStringsSize {}, randomHeadersNumber {}, limitFuzzedFields {}, limitXxxOfCombinations {}" ),
372+ AnsiUtils . boldBlue ( processingArguments .getSelfReferenceDepth ()),
373+ AnsiUtils . boldBlue ( processingArguments .getLargeStringsSize ()),
374+ AnsiUtils . boldBlue ( processingArguments .getRandomHeadersNumber ()),
375+ AnsiUtils . boldBlue ( processingArguments .getLimitNumberOfFields ()),
376+ AnsiUtils . boldBlue ( processingArguments .getLimitXxxOfCombinations ()));
377+ logger .config (AnsiUtils .bold ("How the service handles whitespaces and random unicodes: edgeSpacesStrategy {}, sanitizationStrategy {}" ),
378+ AnsiUtils . boldBlue ( processingArguments .getEdgeSpacesStrategy ()),
379+ AnsiUtils . boldBlue ( processingArguments .getSanitizationStrategy ()));
380+ logger .config (AnsiUtils .bold ("Seed value: {}" ),
381+ AnsiUtils . boldBlue ( CatsRandom .getStoredSeed ()));
411382
412383 int nofOfOperations = OpenApiUtils .getNumberOfOperations (openAPI );
413- logger .config (ansi () .bold (). a ( "Total number of OpenAPI operations: {}" ). reset (). toString (), ansi (). fg ( Ansi . Color . BLUE ). a (nofOfOperations ));
384+ logger .config (AnsiUtils .bold ("Total number of OpenAPI operations: {}" ), AnsiUtils . blue (nofOfOperations ));
414385 }
415386
416387 private void fuzzPath (Map .Entry <String , PathItem > pathItemEntry , OpenAPI openAPI ) {
417388 /* WE NEED TO ITERATE THROUGH EACH HTTP OPERATION CORRESPONDING TO THE CURRENT PATH ENTRY*/
418- String ansiString = ansi () .bold (). a ( "Start fuzzing path {}" ). reset (). toString ( );
389+ String ansiString = AnsiUtils .bold ("Start fuzzing path {}" );
419390 logger .start (ansiString , pathItemEntry .getKey ());
420391 List <FuzzingData > fuzzingDataList = fuzzingDataFactory .fromPathItem (pathItemEntry .getKey (), pathItemEntry .getValue (), openAPI );
421392
@@ -453,7 +424,7 @@ private void runFuzzers(List<FuzzingData> fuzzingDataListWithHttpMethodsFiltered
453424 private void runSingleFuzzer (Fuzzer fuzzer , FuzzingData data ) {
454425 if (data .shouldSkipFuzzerForPath (fuzzer .toString ())) {
455426 logger .skip ("Skipping Fuzzer {} for path {} due to OpenAPI extension configuration" ,
456- ansi (). fgYellow (). a ( fuzzer .toString ()). reset ( ), data .getPath ());
427+ AnsiUtils . yellow ( fuzzer .toString ()), data .getPath ());
457428 return ;
458429 }
459430
@@ -473,12 +444,12 @@ private void runSingleFuzzer(Fuzzer fuzzer, FuzzingData data) {
473444 }
474445
475446 private void logFuzzerEnd (Fuzzer fuzzer , FuzzingData data ) {
476- logger .complete ("Finishing Fuzzer {}, http method {}, path {}" , ansi (). fgGreen (). a ( fuzzer .toString ()). reset ( ), data .getMethod (), data .getPath ());
447+ logger .complete ("Finishing Fuzzer {}, http method {}, path {}" , AnsiUtils . green ( fuzzer .toString ()), data .getMethod (), data .getPath ());
477448 logger .info ("{}" , SEPARATOR );
478449 }
479450
480451 private void logFuzzerStart (Fuzzer fuzzer , FuzzingData data ) {
481- logger .start ("Starting Fuzzer {}, http method {}, path {}" , ansi (). fgGreen (). a ( fuzzer .toString ()). reset ( ), data .getMethod (), data .getPath ());
452+ logger .start ("Starting Fuzzer {}, http method {}, path {}" , AnsiUtils . green ( fuzzer .toString ()), data .getMethod (), data .getPath ());
482453 logger .debug ("Fuzzing payload: {}" , data .getPayload ());
483454 }
484455
0 commit comments