From ee30e058adb941546a8b8b2f5cd66dd1071174fc Mon Sep 17 00:00:00 2001 From: Matt Nowzari Date: Wed, 5 Feb 2025 08:23:26 -0500 Subject: [PATCH] SharePoint Online Connector: Added credentials.close() call to _fetch_token() method (#3177) (cherry picked from commit 56b6971dc17ae0f9b9d015561978df9fbf748536) --- connectors/sources/sharepoint_online.py | 2 ++ tests/sources/test_sharepoint_online.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/connectors/sources/sharepoint_online.py b/connectors/sources/sharepoint_online.py index f0e9f3f8d..5786bcb4f 100644 --- a/connectors/sources/sharepoint_online.py +++ b/connectors/sources/sharepoint_online.py @@ -357,6 +357,8 @@ async def _fetch_token(self): token = await credentials.get_token(self._scope) + await credentials.close() + return token.token, datetime.utcfromtimestamp(token.expires_on) diff --git a/tests/sources/test_sharepoint_online.py b/tests/sources/test_sharepoint_online.py index 7b8045e0b..dea56c28f 100644 --- a/tests/sources/test_sharepoint_online.py +++ b/tests/sources/test_sharepoint_online.py @@ -534,6 +534,7 @@ async def test_fetch_token(self, token, mock_responses): certificate_credential_mock = AsyncMock() certificate_credential_mock.get_token = AsyncMock(return_value=entra_token) + certificate_credential_mock.close = AsyncMock() with patch( "connectors.sources.sharepoint_online.CertificateCredential", @@ -541,6 +542,8 @@ async def test_fetch_token(self, token, mock_responses): ): actual_token, actual_expires_at = await token._fetch_token() + certificate_credential_mock.close.assert_called_once() + assert actual_token == bearer assert actual_expires_at == datetime.utcfromtimestamp(expires_at)