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

java.lang.IllegalArgumentException When header.yaml file is given as input #110

Closed ganeshnikam18 closed 3 months ago

ganeshnikam18 commented 4 months ago

Describe the bug If we give header.yaml file as a input on the cats command line then we get below exception:

vm:~/cats$ java -jar ./target/cats-runner.jar --fuzzers=StringFieldsRightBoundaryFuzzer --server=http://api-server.com --contract=./swagger.yml --headers=./header.yml

[**][*] ▶ Starting cats-11.0.1-SNAPSHOT, build time 2024-02-28T18:40:31Z UTC, platform Linux-6.5.0-21-generic-amd64 [**][*] ⚙ Headers file: /cats/header.yml [**][***] ‼ Something went wrong while running CATS: java.lang.IllegalArgumentException: Cannot deserialize value of type java.util.LinkedHashMap<java.lang.Object,java.lang.Object> from Array value (token JsonToken.START_ARRAY) at [Source: UNKNOWN; byte offset: #UNKNOWN]

This exception will come for any FileArguments like: --header, --refData --urlParam

Steps To Reproduce Steps to reproduce the behaviour:

  1. Run cats command for any specification with --headers file. Content of headers.yaml file could be as below:

all:

  • X-API-Key:abc123
    1. The program will crash with Exception

Expected behaviour The headers.yaml file should be read properly and those headers should be sent in the request.

en-milie commented 4 months ago

Hi @ganeshnikam18. Headers file syntax implies that headers are sub-elements of paths and all, not array values like in your example. This is why it crashes. It's probably a good idea to change a bit the message to suggest that it's an issue with the syntax.

ganeshnikam18 commented 4 months ago

@en-milie Ok. Got it. The content of the header.yaml file should be as below:

all: X-API-Key : abc123

It will then be converted to Object, Instead of ArrayList.

Sorry for the incorrect bug

en-milie commented 4 months ago

It should be as follows:

all:
  X-API-Key: abc123

Notice the indentation of the X-API-Key. It needs 2 spaces in order to be a sub-element of all.

ganeshnikam18 commented 4 months ago

Yes. Thanks for the clarification

en-milie commented 3 months ago

Closing this.