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

Ip Address value is not generated properly #106

Closed ganeshnikam18 closed 3 months ago

ganeshnikam18 commented 4 months ago

CATS version: 10.3.0

What is the issue? If any requestBody schema has "ipaddress" field, the cats is generating very long string for this field. Ideally it should generate random IPv4 address

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

When we execute HappyPath fuzzer for this file, CATS generates below fuzzed body:

"payload": "{"ipaddress":"718951363927897923360586256180007154435308929228851126446436180141171429804609172230175966541623515461280772929060207152401.963566832870923380059481281857380419995538769907442566957194029356142283127464923521227008552846241712373738766797097576278838561608772.689087567263479742349714296829196377275980732993337744196137894166195402548357612062278404841149224582026639901937149506405666469933302.6711145576437248243454401062813189308873159340","countryCode":"WLF","name":"BoheTys","id":9,"tag":"UVB9A"}"

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 Valid IPv4 address value should be generated for this field

What is the root cause?

public Object generate(Schema<?> schema) {

return "%s.%s.%s.%s".formatted(RandomStringUtils.randomNumeric(1, 255), RandomStringUtils.randomNumeric(1, 255), RandomStringUtils.randomNumeric(1, 255), RandomStringUtils.randomNumeric(1, 255)); }

This function is not generating proper IP address. It generated 255 char length for each X in X.X.X.X format. Ideally it should generate integer value from 0-255 for every X.

What is the fix for this issue? I have added below fix for this issue. if you find it appropriate then please add it. ip-address-fix.patch

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.