From a950083eb4a9ba5228b80b6d31e39c56c7e8ad07 Mon Sep 17 00:00:00 2001 From: Mrfence97 Date: Tue, 3 Dec 2024 11:26:39 +0000 Subject: [PATCH 1/2] fix: Regex extracting claims (addressing #420) Updates the regex extracting the base-64 encoded claims in the WWW-Authenticate header. More details provided in issue #420. --- packages/http/httpx/kiota_http/httpx_request_adapter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http/httpx/kiota_http/httpx_request_adapter.py b/packages/http/httpx/kiota_http/httpx_request_adapter.py index 48c9e6a..9368322 100644 --- a/packages/http/httpx/kiota_http/httpx_request_adapter.py +++ b/packages/http/httpx/kiota_http/httpx_request_adapter.py @@ -564,10 +564,10 @@ async def retry_cae_response_if_required( if auth_header_value.casefold().startswith( self.BEARER_AUTHENTICATION_SCHEME.casefold() ): - claims_match = re.search('claims="(.+)"', auth_header_value) + claims_match = re.search('claims="([^"]+)"', auth_header_value) if not claims_match: raise ValueError("Unable to parse claims from response") - response_claims = claims_match.group().split('="')[1] + response_claims = claims_match.group(1) parent_span.add_event(AUTHENTICATE_CHALLENGED_EVENT_KEY) parent_span.set_attribute("http.retry_count", 1) return await self.get_http_response_message( From c8cdfbe7d104383533bf6d19f6c2b378c6a1bab9 Mon Sep 17 00:00:00 2001 From: Mrfence97 Date: Wed, 4 Dec 2024 13:46:28 +0000 Subject: [PATCH 2/2] fix: bug in test_retries_on_cae_failure test There is a bug in the assertion of the test_retries_on_cae_failure test in http/httpx/tests/test_httpx_request_adapter.py. The mock claim entered in mock_cae_failure_response in http/httpx/tests/conftest.py ends with a "=". It is unclear how this test ever passed previously! --- packages/http/httpx/tests/test_httpx_request_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http/httpx/tests/test_httpx_request_adapter.py b/packages/http/httpx/tests/test_httpx_request_adapter.py index 0e5e0f5..cfa5d7b 100644 --- a/packages/http/httpx/tests/test_httpx_request_adapter.py +++ b/packages/http/httpx/tests/test_httpx_request_adapter.py @@ -394,7 +394,7 @@ async def test_retries_on_cae_failure( { "claims": ( "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbH" - "VlIjoiMTYwNDEwNjY1MSJ9fX0" + "VlIjoiMTYwNDEwNjY1MSJ9fX0=" ) }, ),