diff --git a/sherlock_project/sherlock.py b/sherlock_project/sherlock.py index e037d39458..c1c1b26ec1 100644 --- a/sherlock_project/sherlock.py +++ b/sherlock_project/sherlock.py @@ -227,6 +227,7 @@ def sherlock( # Results from analysis of all sites results_total = {} + request_futures = {} # First create futures for all requests. This allows for the requests to run in parallel for social_network, net_info in site_data.items(): @@ -333,7 +334,7 @@ def sherlock( ) # Store future in data for access later - net_info["request_future"] = future + request_futures[social_network] = future # Add this site's results into final dictionary with all the other results. results_total[social_network] = results_site @@ -356,7 +357,7 @@ def sherlock( error_type: list[str] = [error_type] # Retrieve future and ensure it has finished - future = net_info["request_future"] + future = request_futures[social_network] r, error_text, exception_text = get_response( request_future=future, error_type=error_type, social_network=social_network ) diff --git a/tests/test_ux.py b/tests/test_ux.py index 1feaf88a19..44cab0c487 100644 --- a/tests/test_ux.py +++ b/tests/test_ux.py @@ -1,5 +1,6 @@ import pytest from sherlock_project import sherlock +from sherlock_project.notify import QueryNotify from sherlock_interactives import Interactives from sherlock_interactives import InteractivesSubprocessError @@ -33,6 +34,50 @@ def test_wildcard_username_expansion(): assert sherlock.multiple_usernames('test{?}test') == ["test_test" , "test-test" , "test.test"] +def test_sherlock_does_not_mutate_input_site_data(monkeypatch): + class FakeResponse: + status_code = 404 + text = "" + encoding = "UTF-8" + elapsed = None + + class FakeFuture: + def result(self): + return FakeResponse() + + class FakeFuturesSession: + def __init__(self, *args, **kwargs): + pass + + def head(self, **kwargs): + return FakeFuture() + + get = head + post = head + put = head + + monkeypatch.setattr(sherlock.requests, "session", lambda: object()) + monkeypatch.setattr(sherlock, "SherlockFuturesSession", FakeFuturesSession) + site_data = { + "Example": { + "urlMain": "https://example.com", + "url": "https://example.com/{}", + "errorType": "status_code", + "errorCode": 404, + } + } + original_site_data = {name: dict(info) for name, info in site_data.items()} + + sherlock.sherlock( + username="alice", + site_data=site_data, + query_notify=QueryNotify(), + timeout=1, + ) + + assert site_data == original_site_data + + @pytest.mark.parametrize('cliargs', [ '', '--site urghrtuight --egiotr',