Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add various formats for data types #38

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions fuzz_lightyear/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional
from typing import Tuple

import hypothesis.provisional as pr
import hypothesis.strategies as st
from hypothesis.searchstrategy.strategies import SearchStrategy
from swagger_spec_validator.common import SwaggerValidationError # type: ignore
Expand Down Expand Up @@ -105,11 +106,25 @@ def _fuzz_string(
# https://swagger.io/docs/specification/data-models/data-types/#string
kwargs = {} # type: Dict[str, Any]

kwargs['min_size'] = parameter.get('minLength', 0)
kwargs['max_size'] = parameter.get('maxLength')

string_format = parameter.get('format')

if parameter.get('pattern'):
return st.from_regex(parameter['pattern'])
margaretgorguissian marked this conversation as resolved.
Show resolved Hide resolved
elif string_format == 'ipv4':
return pr.ip4_addr_strings()
elif string_format == 'ipv6':
return pr.ip6_addr_strings()
elif string_format == 'binary':
return st.binary(**kwargs)

if parameter.get('required', required):
kwargs['min_size'] = 1

if not get_settings().unicode_enabled:
kwargs['alphabet'] = string.printable

return st.text(**kwargs)


Expand All @@ -121,7 +136,7 @@ def _find_bounds(schema: Dict[str, Any]) -> Dict[str, Any]:
if 'minimum' in schema:
bounds['min_value'] = schema['minimum']
if schema.get('exclusiveMinimum'):
bounds['min_vallue'] += 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

bounds['min_value'] += 1.0

if 'maximum' in schema:
bounds['max_value'] = schema['maximum']
Expand Down