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

Update generator to consider 201 as success response code #83

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions fuzz_lightyear/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def generate_sequences(
# (rather than starting operation), so that it's clearer for
# output.
client = get_abstraction().client
request_graph = _generate_request_graph()
request_graph = generate_request_graph()
for tag_group in get_fuzzable_tags(client):
last_results = [] # type: List
for _ in range(n):
Expand Down Expand Up @@ -124,7 +124,7 @@ def _add_request_to_sequence(


@lru_cache(maxsize=1)
def _generate_request_graph() -> Dict[str, set]:
def generate_request_graph() -> Dict[str, set]:
"""
Generates a directed graph, represented as an adjacency list.

Expand All @@ -140,6 +140,8 @@ def _generate_request_graph() -> Dict[str, set]:
for operation_id in dir(getattr(client, tag_group)):
operation = getattr(getattr(client, tag_group), operation_id).operation
responses = operation.op_spec.get('responses', {}).get('200', {})
if not responses:

Choose a reason for hiding this comment

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

Im just suggesting this cause 200 and 201 are not happening the same time!

Suggested change
if not responses:
responses = operation.op_spec.get('responses', {})
responses = responses.get('200', {}) or responses.get('201', {})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good. I'll include it with future changes 👍🏼

responses = operation.op_spec.get('responses', {}).get('201', {})
if responses:
response_params = list(
responses.get('schema', {}).get('properties', {}).keys(),
Expand Down
4 changes: 2 additions & 2 deletions testing/vulnerable_app/views/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get(self):
@ns.route('/side-effect/create')
class CreateWithSideEffect(Resource):
@api.doc(security='apikey')
@api.response(200, 'Success', model=widget_model)
@api.response(201, 'Success', model=widget_model)
@requires_user
def post(self, user):

Expand All @@ -81,7 +81,7 @@ def post(self, user):

return {
'id': widget_id,
}
}, 201


@ns.route('/side-effect/get/<int:id>')
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

import fuzz_lightyear
from fuzz_lightyear.generator import generate_request_graph
from fuzz_lightyear.generator import generate_sequences


Expand Down Expand Up @@ -166,6 +167,17 @@ def test_length_three(mock_client):
)


def test_request_graph(mock_client):
requested_graph = generate_request_graph()
node = 'get_bravo_two'
expected_edges = [
'get_get_with_side_effect_unsafe', 'post_create_with_side_effect',
'get_get_with_side_effect_safe',
]
for e in expected_edges:
assert e in requested_graph[node]


def is_in_result(expected_sequence, result):
for sequence in result:
formatted_sequence = []
Expand Down