From 9b85431a90223a6c3cdbb3523fe660db58e03f5d Mon Sep 17 00:00:00 2001 From: Murray Stokely Date: Sun, 16 Jul 2023 19:41:07 -0700 Subject: [PATCH 1/2] Don't persist headers across requests --- intuitlib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intuitlib/utils.py b/intuitlib/utils.py index f3fb700..cfc58ad 100644 --- a/intuitlib/utils.py +++ b/intuitlib/utils.py @@ -85,7 +85,7 @@ def send_request(method, url, header, obj, body=None, session=None, oauth1_heade :return: requests object """ - headers = ACCEPT_HEADER + headers = ACCEPT_HEADER.copy() header.update(headers) if session is not None and isinstance(session, Session): From 08b19a14547411d5f89abfc54b7934f1d5541dd9 Mon Sep 17 00:00:00 2001 From: Murray Stokely Date: Sun, 21 Apr 2024 22:39:29 -0700 Subject: [PATCH 2/2] Add test that we're not polluting accept headers across requets. --- tests/test_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 5ebc106..99cda29 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -25,6 +25,7 @@ from urlparse import urlparse, parse_qs, urlsplit from intuitlib.enums import Scopes +from intuitlib.config import ACCEPT_HEADER from intuitlib.client import AuthClient from intuitlib.exceptions import AuthClientError from tests.helper import MockResponse @@ -91,12 +92,17 @@ def test_exceptions_all_bad_request(self, mock_post): @mock.patch('intuitlib.utils.requests.Session.request') def test_get_user_info_ok(self, mock_session): + + header_before_call = ACCEPT_HEADER.copy() + mock_resp = self.mock_request(status=200, content={ 'givenName': 'Test' }) mock_session.return_value = mock_resp response = self.auth_client.get_user_info(access_token='token') + # verify that we didn't pollute the default headers used for subsequent calls. + assert header_before_call == ACCEPT_HEADER.copy() assert response.json()['givenName'] == 'Test' @mock.patch('intuitlib.utils.requests.Session.request') @@ -108,4 +114,4 @@ def test_revoke_ok(self, mock_session): assert response if __name__ == '__main__': - pytest.main() \ No newline at end of file + pytest.main()