From 323d4623a16f93e0c1bcedc0302041ceef332d29 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 13:45:40 -0800 Subject: [PATCH 01/13] this is hacky but it hides the secret --- .../streams/http/requests_native_auth/abstract_oauth.py | 7 ++++++- .../python/airbyte_cdk/utils/airbyte_secrets_utils.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 0dd450413dd48..04749f2048303 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -3,6 +3,7 @@ # import logging +import secrets from abc import abstractmethod from json import JSONDecodeError from typing import Any, List, Mapping, MutableMapping, Optional, Tuple, Union @@ -16,6 +17,7 @@ from airbyte_cdk.utils import AirbyteTracedException from requests.auth import AuthBase +from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets from ..exceptions import DefaultBackoffException logger = logging.getLogger("airbyte") @@ -115,9 +117,12 @@ def _wrap_refresh_token_exception(self, exception: requests.exceptions.RequestEx def _get_refresh_access_token_response(self) -> Any: try: response = requests.request(method="POST", url=self.get_token_refresh_endpoint(), data=self.build_refresh_request_body()) + response_json = response.json() + access_key = response_json[self.get_access_token_name()] + add_to_secrets([access_key]) self._log_response(response) response.raise_for_status() - return response.json() + return response_json except requests.exceptions.RequestException as e: if e.response is not None: if e.response.status_code == 429 or e.response.status_code >= 500: diff --git a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py index eb04a6cf891f4..3ebabefdaca18 100644 --- a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py +++ b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py @@ -61,6 +61,11 @@ def update_secrets(secrets: List[str]): global __SECRETS_FROM_CONFIG __SECRETS_FROM_CONFIG = secrets +def add_to_secrets(secrets: List[str]): + """Add to the list of secrets to be replaced""" + global __SECRETS_FROM_CONFIG + __SECRETS_FROM_CONFIG.extend(secrets) + def filter_secrets(string: str) -> str: """Filter secrets from a string by replacing them with ****""" From 66b2a99a93962afd69dbf3193f21204cfd0fdcc0 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 14:22:30 -0800 Subject: [PATCH 02/13] update --- .../http/requests_native_auth/abstract_oauth.py | 6 ++++-- .../streams/http/requests_native_auth/oauth.py | 2 ++ .../airbyte_cdk/utils/airbyte_secrets_utils.py | 4 ++-- .../python/unit_tests/utils/test_secret_utils.py | 13 ++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 04749f2048303..3c0fec8f60f8f 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -117,11 +117,13 @@ def _wrap_refresh_token_exception(self, exception: requests.exceptions.RequestEx def _get_refresh_access_token_response(self) -> Any: try: response = requests.request(method="POST", url=self.get_token_refresh_endpoint(), data=self.build_refresh_request_body()) + response.raise_for_status() + response_json = response.json() + # Add the access token to the list of secrets so it is replaced before logging the response access_key = response_json[self.get_access_token_name()] - add_to_secrets([access_key]) + add_to_secrets(access_key) self._log_response(response) - response.raise_for_status() return response_json except requests.exceptions.RequestException as e: if e.response is not None: diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py index 48a855fa515f8..b51baf86daacd 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py @@ -9,6 +9,7 @@ from airbyte_cdk.config_observation import create_connector_config_control_message, emit_configuration_as_airbyte_control_message from airbyte_cdk.sources.message import MessageRepository, NoopMessageRepository from airbyte_cdk.sources.streams.http.requests_native_auth.abstract_oauth import AbstractOauth2Authenticator +from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets class Oauth2Authenticator(AbstractOauth2Authenticator): @@ -246,6 +247,7 @@ def get_access_token(self) -> str: def refresh_access_token(self) -> Tuple[str, str, str]: response_json = self._get_refresh_access_token_response() + add_to_secrets([response_json[self.get_refresh_token_name()]]) return ( response_json[self.get_access_token_name()], response_json[self.get_expires_in_name()], diff --git a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py index 3ebabefdaca18..b9d34313e221a 100644 --- a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py +++ b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py @@ -61,10 +61,10 @@ def update_secrets(secrets: List[str]): global __SECRETS_FROM_CONFIG __SECRETS_FROM_CONFIG = secrets -def add_to_secrets(secrets: List[str]): +def add_to_secrets(secret: str): """Add to the list of secrets to be replaced""" global __SECRETS_FROM_CONFIG - __SECRETS_FROM_CONFIG.extend(secrets) + __SECRETS_FROM_CONFIG.append(secret) def filter_secrets(string: str) -> str: diff --git a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py index 08cc81778da0c..5fb73640d1207 100644 --- a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py +++ b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py @@ -3,7 +3,7 @@ # import pytest -from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets, get_secret_paths, get_secrets, update_secrets +from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets, get_secret_paths, get_secrets, update_secrets, add_to_secrets SECRET_STRING_KEY = "secret_key1" SECRET_STRING_VALUE = "secret_value" @@ -121,3 +121,14 @@ def test_secret_filtering(): update_secrets([SECRET_STRING_VALUE, SECRET_STRING_2_VALUE]) filtered = filter_secrets(sensitive_str) assert filtered == f"**** {NOT_SECRET_VALUE} **** ****" + +def test_secrets_added_are_filtered(): + ADDED_SECRET = "only_a_secret_if_added" + sensitive_str = f"{ADDED_SECRET} {NOT_SECRET_VALUE}" + + filtered = filter_secrets(sensitive_str) + assert filtered == sensitive_str + + add_to_secrets(ADDED_SECRET) + filtered = filter_secrets(sensitive_str) + assert filtered == f"**** {NOT_SECRET_VALUE}" From 8476404937fc5511cfa5fd14d28356ab5399447e Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 14:44:05 -0800 Subject: [PATCH 03/13] fix --- .../requests_native_auth/abstract_oauth.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 3c0fec8f60f8f..510b00eeaa208 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -117,14 +117,16 @@ def _wrap_refresh_token_exception(self, exception: requests.exceptions.RequestEx def _get_refresh_access_token_response(self) -> Any: try: response = requests.request(method="POST", url=self.get_token_refresh_endpoint(), data=self.build_refresh_request_body()) - response.raise_for_status() - - response_json = response.json() - # Add the access token to the list of secrets so it is replaced before logging the response - access_key = response_json[self.get_access_token_name()] - add_to_secrets(access_key) - self._log_response(response) - return response_json + if response.ok: + response_json = response.json() + # Add the access token to the list of secrets so it is replaced before logging the response + access_key = response_json[self.get_access_token_name()] + add_to_secrets(access_key) + self._log_response(response) + return response_json + else: + self._log_response(response) + response.raise_for_status() except requests.exceptions.RequestException as e: if e.response is not None: if e.response.status_code == 429 or e.response.status_code >= 500: From 1d07398575629b4f351576ffbcddc08770b91613 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 14:45:03 -0800 Subject: [PATCH 04/13] update --- .../sources/streams/http/requests_native_auth/oauth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py index b51baf86daacd..e21212aea2583 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py @@ -247,7 +247,6 @@ def get_access_token(self) -> str: def refresh_access_token(self) -> Tuple[str, str, str]: response_json = self._get_refresh_access_token_response() - add_to_secrets([response_json[self.get_refresh_token_name()]]) return ( response_json[self.get_access_token_name()], response_json[self.get_expires_in_name()], From a9d134b2ca107761330d165040fb12001336195c Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 14:45:43 -0800 Subject: [PATCH 05/13] reset to master --- .../sources/streams/http/requests_native_auth/oauth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py index e21212aea2583..48a855fa515f8 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py @@ -9,7 +9,6 @@ from airbyte_cdk.config_observation import create_connector_config_control_message, emit_configuration_as_airbyte_control_message from airbyte_cdk.sources.message import MessageRepository, NoopMessageRepository from airbyte_cdk.sources.streams.http.requests_native_auth.abstract_oauth import AbstractOauth2Authenticator -from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets class Oauth2Authenticator(AbstractOauth2Authenticator): From 61eca252bf3d119a13f207a0b5c5435ac1183a25 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 17:04:51 -0800 Subject: [PATCH 06/13] fix format --- .../streams/http/requests_native_auth/abstract_oauth.py | 2 +- .../python/airbyte_cdk/utils/airbyte_secrets_utils.py | 7 ++++--- airbyte-cdk/python/unit_tests/utils/test_secret_utils.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 510b00eeaa208..66df79366c6da 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -15,9 +15,9 @@ from airbyte_cdk.sources.http_logger import format_http_message from airbyte_cdk.sources.message import MessageRepository, NoopMessageRepository from airbyte_cdk.utils import AirbyteTracedException +from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets from requests.auth import AuthBase -from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets from ..exceptions import DefaultBackoffException logger = logging.getLogger("airbyte") diff --git a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py index b9d34313e221a..e690a556606b4 100644 --- a/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py +++ b/airbyte-cdk/python/airbyte_cdk/utils/airbyte_secrets_utils.py @@ -10,7 +10,7 @@ def get_secret_paths(spec: Mapping[str, Any]) -> List[List[str]]: paths = [] - def traverse_schema(schema_item: Any, path: List[str]): + def traverse_schema(schema_item: Any, path: List[str]) -> None: """ schema_item can be any property or value in the originally input jsonschema, depending on how far down the recursion stack we go path is the path to that schema item in the original input @@ -56,12 +56,13 @@ def get_secrets(connection_specification: Mapping[str, Any], config: Mapping[str __SECRETS_FROM_CONFIG: List[str] = [] -def update_secrets(secrets: List[str]): +def update_secrets(secrets: List[str]) -> None: """Update the list of secrets to be replaced""" global __SECRETS_FROM_CONFIG __SECRETS_FROM_CONFIG = secrets -def add_to_secrets(secret: str): + +def add_to_secrets(secret: str) -> None: """Add to the list of secrets to be replaced""" global __SECRETS_FROM_CONFIG __SECRETS_FROM_CONFIG.append(secret) diff --git a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py index 5fb73640d1207..13dd542653448 100644 --- a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py +++ b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py @@ -3,7 +3,7 @@ # import pytest -from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets, get_secret_paths, get_secrets, update_secrets, add_to_secrets +from airbyte_cdk.utils.airbyte_secrets_utils import add_to_secrets, filter_secrets, get_secret_paths, get_secrets, update_secrets SECRET_STRING_KEY = "secret_key1" SECRET_STRING_VALUE = "secret_value" From 868e23d680eab26c7c6302ef5586bcbe40f1f6f2 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Tue, 6 Feb 2024 17:58:01 -0800 Subject: [PATCH 07/13] flake --- .../sources/streams/http/requests_native_auth/abstract_oauth.py | 1 - airbyte-cdk/python/unit_tests/utils/test_secret_utils.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 66df79366c6da..7a4af43b18be8 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -3,7 +3,6 @@ # import logging -import secrets from abc import abstractmethod from json import JSONDecodeError from typing import Any, List, Mapping, MutableMapping, Optional, Tuple, Union diff --git a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py index 13dd542653448..39c6ff735da04 100644 --- a/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py +++ b/airbyte-cdk/python/unit_tests/utils/test_secret_utils.py @@ -122,6 +122,7 @@ def test_secret_filtering(): filtered = filter_secrets(sensitive_str) assert filtered == f"**** {NOT_SECRET_VALUE} **** ****" + def test_secrets_added_are_filtered(): ADDED_SECRET = "only_a_secret_if_added" sensitive_str = f"{ADDED_SECRET} {NOT_SECRET_VALUE}" From b44f39e48749d70e829ca4074b3b12fb3a5e20a1 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Wed, 7 Feb 2024 09:16:42 -0800 Subject: [PATCH 08/13] Update abstract_oauth.py --- .../sources/streams/http/requests_native_auth/abstract_oauth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index 7a4af43b18be8..d3bdf6f424f3e 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -124,6 +124,7 @@ def _get_refresh_access_token_response(self) -> Any: self._log_response(response) return response_json else: + # log the response even if the request failed for troubleshooting purposes self._log_response(response) response.raise_for_status() except requests.exceptions.RequestException as e: From e8eacc23d0c38fc83685770386c8e525b39e22cc Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Wed, 7 Feb 2024 09:19:40 -0800 Subject: [PATCH 09/13] Update abstract_oauth.py --- .../sources/streams/http/requests_native_auth/abstract_oauth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index d3bdf6f424f3e..d9c6df0476c2c 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -119,6 +119,7 @@ def _get_refresh_access_token_response(self) -> Any: if response.ok: response_json = response.json() # Add the access token to the list of secrets so it is replaced before logging the response + # An argument could be made to remove the prevous access key from the list of secrets, but unmasking values seems like a security incident waiting to happen... access_key = response_json[self.get_access_token_name()] add_to_secrets(access_key) self._log_response(response) From bda2e1c06b6e30933fde875ef641e3b0fb583cb2 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Wed, 7 Feb 2024 09:41:52 -0800 Subject: [PATCH 10/13] update unit test --- .../python/unit_tests/sources/declarative/auth/test_oauth.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py index bd019d374987c..b0004bae7719f 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py @@ -12,6 +12,8 @@ from airbyte_cdk.sources.declarative.auth import DeclarativeOauth2Authenticator from requests import Response +from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets + LOGGER = logging.getLogger(__name__) resp = Response() @@ -165,6 +167,9 @@ def test_refresh_access_token(self, mocker): assert ("access_token", 1000) == token + filtered = filter_secrets("access_token") + assert filtered == "****" + @pytest.mark.parametrize( "timestamp, expected_date", [ From d44850a39e2ed1058786c5550e480ea2c2127c8f Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Fri, 9 Feb 2024 18:01:54 -0800 Subject: [PATCH 11/13] raise exception if access_token is missing --- .../requests_native_auth/abstract_oauth.py | 4 +++- .../sources/declarative/auth/test_oauth.py | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py index d9c6df0476c2c..63915f71d6514 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py @@ -120,7 +120,9 @@ def _get_refresh_access_token_response(self) -> Any: response_json = response.json() # Add the access token to the list of secrets so it is replaced before logging the response # An argument could be made to remove the prevous access key from the list of secrets, but unmasking values seems like a security incident waiting to happen... - access_key = response_json[self.get_access_token_name()] + access_key = response_json.get(self.get_access_token_name()) + if not access_key: + raise Exception("Token refresh API response was missing access token {self.get_access_token_name()}") add_to_secrets(access_key) self._log_response(response) return response_json diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py index b0004bae7719f..93208432e2b34 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py @@ -170,6 +170,30 @@ def test_refresh_access_token(self, mocker): filtered = filter_secrets("access_token") assert filtered == "****" + + def test_refresh_access_token_missing_access_token(self, mocker): + oauth = DeclarativeOauth2Authenticator( + token_refresh_endpoint="{{ config['refresh_endpoint'] }}", + client_id="{{ config['client_id'] }}", + client_secret="{{ config['client_secret'] }}", + refresh_token="{{ config['refresh_token'] }}", + config=config, + scopes=["scope1", "scope2"], + token_expiry_date="{{ config['token_expiry_date'] }}", + refresh_request_body={ + "custom_field": "{{ config['custom_field'] }}", + "another_field": "{{ config['another_field'] }}", + "scopes": ["no_override"], + }, + parameters={}, + ) + + resp.status_code = 200 + mocker.patch.object(resp, "json", return_value={"expires_in": 1000}) + mocker.patch.object(requests, "request", side_effect=mock_request, autospec=True) + with pytest.raises(Exception): + token = oauth.refresh_access_token() + @pytest.mark.parametrize( "timestamp, expected_date", [ From caa5f4fb5cf215516face14df0093b0e8924e2ba Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Fri, 9 Feb 2024 18:49:01 -0800 Subject: [PATCH 12/13] flake8 --- .../python/unit_tests/sources/declarative/auth/test_oauth.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py index 93208432e2b34..48670a70f0c55 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py @@ -170,7 +170,6 @@ def test_refresh_access_token(self, mocker): filtered = filter_secrets("access_token") assert filtered == "****" - def test_refresh_access_token_missing_access_token(self, mocker): oauth = DeclarativeOauth2Authenticator( token_refresh_endpoint="{{ config['refresh_endpoint'] }}", @@ -192,7 +191,7 @@ def test_refresh_access_token_missing_access_token(self, mocker): mocker.patch.object(resp, "json", return_value={"expires_in": 1000}) mocker.patch.object(requests, "request", side_effect=mock_request, autospec=True) with pytest.raises(Exception): - token = oauth.refresh_access_token() + oauth.refresh_access_token() @pytest.mark.parametrize( "timestamp, expected_date", From a06030e27e8aa605b3b0169f6412d1ca03be3040 Mon Sep 17 00:00:00 2001 From: Alexandre Girard Date: Wed, 14 Feb 2024 16:18:49 -0800 Subject: [PATCH 13/13] format --- .../python/unit_tests/sources/declarative/auth/test_oauth.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py index 48670a70f0c55..78dd0b591ec3c 100644 --- a/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py +++ b/airbyte-cdk/python/unit_tests/sources/declarative/auth/test_oauth.py @@ -10,9 +10,8 @@ import pytest import requests from airbyte_cdk.sources.declarative.auth import DeclarativeOauth2Authenticator -from requests import Response - from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets +from requests import Response LOGGER = logging.getLogger(__name__)