Skip to content

Commit 6e5b786

Browse files
committed
Improve test cases to test header-less response
1 parent 5a1a0ff commit 6e5b786

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

tests/http_client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ class MinimalResponse(object): # Not for production use
2828
def __init__(self, requests_resp=None, status_code=None, text=None, headers=None):
2929
self.status_code = status_code or requests_resp.status_code
3030
self.text = text if text is not None else requests_resp.text
31-
self.headers = {} if headers is None else headers
31+
if headers:
32+
# Early versions of MSAL did not require http response to contain headers.
33+
# As of April 2025, some Azure Identity code paths still yield response without headers.
34+
# Here we mimic the behavior of header-less response by default,
35+
# so that test cases can cover header-less response scenarios.
36+
self.headers = headers
3237
self._raw_resp = requests_resp
3338

3439
def raise_for_status(self):

tests/test_throttled_http_client.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ def close(self):
4949
raise CloseMethodCalled("Not used by MSAL, but our customers may use it")
5050

5151

52-
class DummyHttpClientWithoutResponseHeaders(DummyHttpClient):
53-
def post(self, url, params=None, data=None, headers=None, **kwargs):
54-
response = super().post(url, params, data, headers, **kwargs)
55-
del response.headers # Early versions of MSAL did not require http client to return headers
56-
return response
57-
58-
def get(self, url, params=None, headers=None, **kwargs):
59-
response = super().get(url, params, headers, **kwargs)
60-
del response.headers # Early versions of MSAL did not require http client to return headers
61-
return response
62-
63-
6452
class CloseMethodCalled(Exception):
6553
pass
6654

@@ -82,9 +70,10 @@ def test_pickled_minimal_response_should_contain_signature(self):
8270
status_code=200, headers={}, text="foo")))
8371

8472
def test_throttled_http_client_base_response_should_tolerate_headerless_response(self):
85-
http_client = ThrottledHttpClientBase(DummyHttpClientWithoutResponseHeaders(
86-
status_code=200, response_text="foo"))
87-
response = http_client.post("https://example.com")
73+
http_client = DummyHttpClient(status_code=200, response_text="foo")
74+
raw_response = http_client.post("https://example.com")
75+
self.assertFalse(hasattr(raw_response, "headers"), "Should not contain headers")
76+
response = ThrottledHttpClientBase(http_client).post("https://example.com")
8877
self.assertEqual(response.text, "foo", "Should return the same response text")
8978

9079
def test_throttled_http_client_base_response_should_not_contain_signature(self):

0 commit comments

Comments
 (0)