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

CountryCode regex pattern is not honoured #104

Closed ganeshnikam18 closed 3 months ago

ganeshnikam18 commented 4 months ago

CATS version: 10.3.0

What is the issue ? When any specification file has countryCode field along with regex pattern, then CATS not honouring that regex. petstore-country-code.json

In this spec file, one field defined as below: "Pet": { "type": "object", "required": [ "id", "name" ], "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" }, "tag": { "type": "string" }, "countryCode": { "type": "string", "pattern": "^[A-Z]{2}$" } } },

The countryCode field as regex where 2 capital letter characters are allowed. When we execute HappyPath fuzzer for this file, CATS generates below fuzzed body:

"payload": "{\"countryCode\":\"FJI\",\"name\":\"pcj74\",\"id\":1,\"tag\":\"425J\"}"

The countryCode field has three characters, which is not as per the regex

How to Reproduce Steps to reproduce the behaviour:

  1. For the server side, I am running Spotlight Prism Mock Server:
  2. Run the mock version with this spec file
  3. Then from other machine run the cats tool with HappyPathFuzzer
  4. Check the payload in the generated test cases.

Expected behaviour CATS should honour the regex pattern and generate correct countryCode. Above 3 character country code will be rejected by Server.

What is the root cause? In CountryCodeGenerator.java, we are checking only for schema.minLength == 2. If its not specified countryCode is generated using the default format: Locale.IsoCountryCode.PART1_ALPHA3. We should also check for pattern.

What is the fix ? I have added below fix for this issue. If you find it appropriate, then please add it: t.patch

en-milie commented 4 months ago

Thank you for also fixing it.

en-milie commented 4 months ago

Available in: https://github.com/Endava/cats/releases/tag/cats-11.1.0

en-milie commented 3 months ago

Closing this.