def test_generateDownloadLink_invalidEvent(self, s3): client, bucket, bucket_name = s3 invalid_event = {"TEST": "TEST"} test_context = None results_handler = ResultsHandler( client, bucket_name, results_path=TEST_SCAN_RESULTS_BASE_PATH) response = results_handler.generateDownloadLink( invalid_event, test_context) assert response is False
def test_generateDownloadLink_fullResults(self, s3): client, bucket, bucket_name = s3 target = "infosec.mozilla.org" # Ensure we have all matching objects in the test S3 bucket client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_direnum.json'.format(target)) client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_websearch.json'.format(target)) client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_tcpscan.json'.format(target)) client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_httpobservatory.json'.format(target)) client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_tlsobservatory.json'.format(target)) client.put_object(ACL='authenticated-read', Bucket=bucket_name, Body=b'ABCD', Key='{}_sshobservatory.json'.format(target)) test_stepf_event = {"target": target} test_context = None results_handler = ResultsHandler( s3_client=client, bucket=bucket_name, results_path=TEST_SCAN_RESULTS_BASE_PATH) response = results_handler.generateDownloadLink( test_stepf_event, test_context) assert type(response) is dict assert response['status'] == 200 assert type(response['output']) is dict url = urlparse(response['url']) query = parse_qs(url.query) assert type(query) is dict assert url.scheme == "https" assert url.netloc == "{}.s3.amazonaws.com".format(bucket_name) assert url.path == "/results/{}.tgz".format(target) assert "AWSAccessKeyId" in query assert "Expires" in query assert "Signature" in query
def test_generateDownloadLink_noResults(self, s3): client, bucket, bucket_name = s3 target = "infosec.mozilla.org" # No objects in the S3 bucket, should return no results test_stepf_event = {"target": target} test_context = None results_handler = ResultsHandler( client, bucket_name, results_path=TEST_SCAN_RESULTS_BASE_PATH) response = results_handler.generateDownloadLink( test_stepf_event, test_context) assert type(response) is dict assert response['status'] == 404 assert response['message'] == 'No results found for target'
def check_results(event, context): results_handler = ResultsHandler(s3_client=S3_CLIENT, logger=logger) response = results_handler.generateDownloadLink(event, context) return response