-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from OWASP/dev
Dev RELEASE: v0.16.0
- Loading branch information
Showing
9 changed files
with
385 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,37 @@ | |
from .logger import logger | ||
|
||
|
||
def overwrite_user_params(list1: list[dict], list2: list[dict]) -> list[dict]: | ||
""" | ||
Update values in list1 based on the corresponding "name" values in list2. | ||
Args: | ||
list1 (list of dict): The list of dictionaries to be updated. | ||
list2 (list of dict): The list of dictionaries containing values to update from. | ||
Returns: | ||
list of dict: The updated list1 with values from list2. | ||
Example: | ||
```python | ||
list1 = [{'name': 'id', 'value': 67}, {'name': 'email', 'value': '[email protected]'}] | ||
list2 = [{'name': 'id', 'value': 10}, {'name': 'email', 'value': '[email protected]'}] | ||
updated_list = update_values(list1, list2) | ||
print(updated_list) | ||
# Output: [{'name': 'id', 'value': 10}, {'name': 'email', 'value': '[email protected]'}] | ||
``` | ||
""" | ||
# Create a dictionary for faster lookup | ||
lookup_dict = {item['name']: item['value'] for item in list2} | ||
|
||
# Update values in list1 using index lookup | ||
for item in list1: | ||
if item['name'] in lookup_dict: | ||
item['value'] = lookup_dict[item['name']] | ||
|
||
return list1 | ||
|
||
|
||
def validate_config_file_data(test_config_data: dict): | ||
if not isinstance(test_config_data, dict): | ||
logger.warning('Invalid data format') | ||
|
@@ -11,7 +42,9 @@ def validate_config_file_data(test_config_data: dict): | |
logger.warning('Error Occurred While reading file: %s', test_config_data) | ||
return False | ||
|
||
if not test_config_data.get('actors', ): | ||
if not test_config_data.get( | ||
'actors', | ||
): | ||
logger.warning('actors are required') | ||
return False | ||
|
||
|
@@ -36,15 +69,21 @@ def populate_user_data(actor_data: dict, actor_name: str, tests: list[dict]): | |
request_headers[header.get('name')] = header.get('value') | ||
|
||
for test in tests: | ||
# replace key and value instead of appending | ||
test['body_params'] += body_params | ||
test['query_params'] += query_params | ||
test['path_params'] += path_params | ||
test['body_params'] = overwrite_user_params( | ||
deepcopy(test['body_params']), body_params | ||
) | ||
test['query_params'] = overwrite_user_params( | ||
deepcopy(test['query_params']), query_params | ||
) | ||
test['path_params'] += overwrite_user_params( | ||
deepcopy(test['path_params']), path_params | ||
) | ||
# for post test processing tests such as broken authentication | ||
test['test_actor_name'] = actor_name | ||
if test.get('kwargs', {}).get('headers', {}).items(): | ||
test['kwargs']['headers'] = dict( | ||
test['kwargs']['headers'], **request_headers) | ||
test['kwargs']['headers'], **request_headers | ||
) | ||
else: | ||
test['kwargs']['headers'] = request_headers | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.