def process_test_data(raw_data: list, previous_results: dict) -> Dict[str, Dict[str, object]]:
leaks = []
result = {}
url = None
if 'url' in raw_data:
url = raw_data['url']['data'].decode()
for trial, pattern in TRIALS:
if url:
if callable(trial):
trial = trial(url)
if trial is None:
continue
if trial not in raw_data:
# Test raw data too old or particular request failed.
continue
response = json.loads(raw_data[trial]['data'].decode())
if response['status_code'] == 200:
# The pattern can have three different types.
# - If it is a simple string, we only check if it is contained in the response
if isinstance(pattern, str):
if pattern in response['text']:
leaks.append(trial)
# - If it is a RegEx object, we perform a pattern match
elif isinstance(pattern, re._pattern_type):
if re.match(response['text']):
leaks.append(trial)
# - If it is callable, we call it with the response text and check the return value
elif callable(pattern):
if pattern(response['text']):
leaks.append(trial)
result['leaks'] = leaks
return result
评论列表
文章目录