Endava / cats

CATS is a REST API Fuzzer and negative testing tool for OpenAPI endpoints. CATS automatically generates, runs and reports tests with minimum configuration and no coding effort. Tests are self-healing and do not require maintenance.
Apache License 2.0
1.11k stars 76 forks source link

CATS runner crashing with java.lang.NullPointerException #92

Closed ganeshnikam18 closed 5 months ago

ganeshnikam18 commented 5 months ago

Describe the bug I have locally built the cats-runner.jar using the mvwn command. Trying to run the tool on one of the custom perstore.json file. In this run cats-runner.jar is crashing with " java.lang.NullPointerException". Here are the complete details:

CATS version: 10.3.0 Petstore Speci File: petstore.json

For the server side, I am running Spotlight Prism Mock Server:

The stacktrace of the crash: [******][*******] ◯ key application/json contentType application\/.*\+?json;?.* java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because the return value of "io.swagger.v3.oas.models.media.MediaType.getSchema()" is null at com.endava.cats.factory.FuzzingDataFactory.getCurrentRequestSchemaName(FuzzingDataFactory.java:356) at com.endava.cats.factory.FuzzingDataFactory.getFuzzDataForHttpMethod(FuzzingDataFactory.java:204) at com.endava.cats.factory.FuzzingDataFactory.getFuzzDataForPost(FuzzingDataFactory.java:157) at com.endava.cats.factory.FuzzingDataFactory.fromPathItem(FuzzingDataFactory.java:88) at com.endava.cats.factory.FuzzingDataFactory_ClientProxy.fromPathItem(Unknown Source) at com.endava.cats.command.CatsCommand.fuzzPath(CatsCommand.java:321) at com.endava.cats.command.CatsCommand.startFuzzing(CatsCommand.java:261) at com.endava.cats.command.CatsCommand.doLogic(CatsCommand.java:204) at com.endava.cats.command.CatsCommand.run(CatsCommand.java:156) at picocli.CommandLine.executeUserObject(CommandLine.java:2026) at picocli.CommandLine.access$1500(CommandLine.java:148) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461) at picocli.CommandLine$RunLast.handle(CommandLine.java:2453) at picocli.CommandLine$RunLast.handle(CommandLine.java:2415) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273) at picocli.CommandLine$RunLast.execute(CommandLine.java:2417) at picocli.CommandLine.execute(CommandLine.java:2170) at com.endava.cats.CatsMain.run(CatsMain.java:39) at com.endava.cats.CatsMain_ClientProxy.run(Unknown Source) at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:132) at io.quarkus.runtime.Quarkus.run(Quarkus.java:71) at io.quarkus.runtime.Quarkus.run(Quarkus.java:44) at io.quarkus.runner.GeneratedMain.main(Unknown Source) ganesh@ganesh-vm:~/cats-original/cats-cats-10.3.0$

To Reproduce Steps to reproduce the behaviour:

  1. Run the prism mock server container with the above petstore contract file docker run --init --rm -v $(pwd):/tmp -p 4010:4010 stoplight/prism:4 mock -h 0.0.0.0 "/tmp/petstore.json
  2. From the other host where cats tool is built and binary is available run the below command: java -jar target/cats-runner.jar --server=http://<mock-server-ip>:4010 --contract=petstore.json --fuzzers=HappyPathFuzzer --log=com.endava.cats:debug --verbosity=DETAILED
  3. It will crash with above stack trace

Expected behaviour The cats tool should not crash

Below mentioned request body in the contract causing this crash "post": { "summary": "Create a pet", "operationId": "createPets", "tags": [ "pets" ], "requestBody": { "content": { "application/json": {} }, "required": true },

Ideally requestBody should not be empty (without specifying schema). But some spec file do get published like this. What is the fix ? We have to add the NULL check for schema presence. Check below image for patch. Screenshot 2024-01-09 153154-11

en-milie commented 5 months ago

Hi @ganeshnikam18. Thank you for reporting this issue. Let me check what's happening.

en-milie commented 5 months ago

@ganeshnikam18 Thank you for the detailed report, very well written. And also for the fix. It will be available in the next release.

en-milie commented 5 months ago

This should be fix in latest release: https://github.com/Endava/cats/releases/tag/cats-10.4.0

en-milie commented 5 months ago

I'll close this as fixed.