Skip to content

Commit 84fca2d

Browse files
committed
Assert regional request reaches regional endpoint
1 parent 46f7592 commit 84fca2d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
# We will go with "<4" for now, which is also what our another dependency,
8585
# pyjwt, currently use.
8686

87+
"mock;python_version<'3.3'",
8788
]
8889
)
8990

tests/test_e2e.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
import time
55
import unittest
66
import sys
7+
try:
8+
from unittest.mock import patch, ANY
9+
except:
10+
from mock import patch, ANY
711

812
import requests
913

1014
import msal
11-
from tests.http_client import MinimalHttpClient
15+
from tests.http_client import MinimalHttpClient, MinimalResponse
1216
from msal.oauth2cli import AuthCodeReceiver
1317

1418
logger = logging.getLogger(__name__)
@@ -758,13 +762,21 @@ def test_acquire_token_for_client_should_hit_regional_endpoint(self):
758762
timeout=2, # Short timeout makes this test case responsive on non-VM
759763
)
760764
scopes = ["https://graph.microsoft.com/.default"]
765+
766+
with patch.object( # Test the request hit the regional endpoint
767+
self.app.http_client, "post", return_value=MinimalResponse(
768+
status_code=400, text='{"error": "mock"}')) as mocked_method:
769+
self.app.acquire_token_for_client(scopes)
770+
mocked_method.assert_called_with(
771+
'https://westus.login.microsoft.com/{}/oauth2/v2.0/token'.format(
772+
self.app.authority.tenant),
773+
params=ANY, data=ANY, headers=ANY)
761774
result = self.app.acquire_token_for_client(
762775
scopes,
763776
params={"AllowEstsRNonMsi": "true"}, # For testing regional endpoint. It will be removed once MSAL Python 1.12+ has been onboard to ESTS-R
764777
)
765778
self.assertIn('access_token', result)
766779
self.assertCacheWorksForApp(result, scopes)
767-
# TODO: Test the request hit the regional endpoint self.region?
768780

769781

770782
class RegionalEndpointViaEnvVarTestCase(WorldWideRegionalEndpointTestCase):

0 commit comments

Comments
 (0)