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.
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:
Then from other machine run the cats tool with HappyPathFuzzer
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
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:
The countryCode field has three characters, which is not as per the regex
How to Reproduce Steps to reproduce the behaviour:
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