@@ -137,10 +137,15 @@ def assertCacheWorksForApp(self, result_from_wire, scope):
137
137
def _test_username_password (self ,
138
138
authority = None , client_id = None , username = None , password = None , scope = None ,
139
139
client_secret = None , # Since MSAL 1.11, confidential client has ROPC too
140
+ azure_region = None ,
141
+ http_client = None ,
140
142
** ignored ):
141
143
assert authority and client_id and username and password and scope
142
144
self .app = msal .ClientApplication (
143
- client_id , authority = authority , http_client = MinimalHttpClient (),
145
+ client_id , authority = authority ,
146
+ http_client = http_client or MinimalHttpClient (),
147
+ azure_region = azure_region , # Regional endpoint does not support ROPC.
148
+ # Here we just use it to test a regional app won't break ROPC.
144
149
client_credential = client_secret )
145
150
result = self .app .acquire_token_by_username_password (
146
151
username , password , scopes = scope )
@@ -541,11 +546,16 @@ def _test_acquire_token_by_auth_code_flow(
541
546
error_description = result .get ("error_description" )))
542
547
self .assertCacheWorksForUser (result , scope , username = None )
543
548
544
- def _test_acquire_token_obo (self , config_pca , config_cca ):
549
+ def _test_acquire_token_obo (self , config_pca , config_cca ,
550
+ azure_region = None , # Regional endpoint does not really support OBO.
551
+ # Here we just test regional apps won't adversely break OBO
552
+ http_client = None ,
553
+ ):
545
554
# 1. An app obtains a token representing a user, for our mid-tier service
546
555
pca = msal .PublicClientApplication (
547
556
config_pca ["client_id" ], authority = config_pca ["authority" ],
548
- http_client = MinimalHttpClient ())
557
+ azure_region = azure_region ,
558
+ http_client = http_client or MinimalHttpClient ())
549
559
pca_result = pca .acquire_token_by_username_password (
550
560
config_pca ["username" ],
551
561
config_pca ["password" ],
@@ -560,7 +570,8 @@ def _test_acquire_token_obo(self, config_pca, config_cca):
560
570
config_cca ["client_id" ],
561
571
client_credential = config_cca ["client_secret" ],
562
572
authority = config_cca ["authority" ],
563
- http_client = MinimalHttpClient (),
573
+ azure_region = azure_region ,
574
+ http_client = http_client or MinimalHttpClient (),
564
575
# token_cache= ..., # Default token cache is all-tokens-store-in-memory.
565
576
# That's fine if OBO app uses short-lived msal instance per session.
566
577
# Otherwise, the OBO app need to implement a one-cache-per-user setup.
@@ -778,6 +789,7 @@ def test_b2c_acquire_token_by_ropc(self):
778
789
779
790
class WorldWideRegionalEndpointTestCase (LabBasedTestCase ):
780
791
region = "westus"
792
+ timeout = 2 # Short timeout makes this test case responsive on non-VM
781
793
782
794
def test_acquire_token_for_client_should_hit_regional_endpoint (self ):
783
795
"""This is the only grant supported by regional endpoint, for now"""
@@ -808,15 +820,6 @@ def test_acquire_token_for_client_should_hit_regional_endpoint(self):
808
820
self .assertIn ('access_token' , result )
809
821
self .assertCacheWorksForApp (result , scopes )
810
822
811
-
812
- class RegionalEndpointViaEnvVarTestCase (WorldWideRegionalEndpointTestCase ):
813
-
814
- def setUp (self ):
815
- os .environ ["REGION_NAME" ] = "eastus"
816
-
817
- def tearDown (self ):
818
- del os .environ ["REGION_NAME" ]
819
-
820
823
@unittest .skipUnless (
821
824
os .getenv ("LAB_OBO_CLIENT_SECRET" ),
822
825
"Need LAB_OBO_CLIENT_SECRET from https://aka.ms/GetLabSecret?Secret=TodoListServiceV2-OBO" )
@@ -842,7 +845,11 @@ def test_cca_obo_should_bypass_regional_endpoint_therefore_still_work(self):
842
845
config_pca ["password" ] = self .get_lab_user_secret (config_pca ["lab_name" ])
843
846
config_pca ["scope" ] = ["api://%s/read" % config_cca ["client_id" ]]
844
847
845
- self ._test_acquire_token_obo (config_pca , config_cca )
848
+ self ._test_acquire_token_obo (
849
+ config_pca , config_cca ,
850
+ azure_region = self .region ,
851
+ http_client = MinimalHttpClient (timeout = self .timeout ),
852
+ )
846
853
847
854
@unittest .skipUnless (
848
855
os .getenv ("LAB_OBO_CLIENT_SECRET" ),
@@ -859,7 +866,10 @@ def test_cca_ropc_should_bypass_regional_endpoint_therefore_still_work(self):
859
866
config ["client_id" ] = os .getenv ("LAB_OBO_CONFIDENTIAL_CLIENT_ID" )
860
867
config ["scope" ] = ["https://graph.microsoft.com/.default" ]
861
868
config ["client_secret" ] = os .getenv ("LAB_OBO_CLIENT_SECRET" )
862
- self ._test_username_password (** config )
869
+ self ._test_username_password (
870
+ azure_region = self .region ,
871
+ http_client = MinimalHttpClient (timeout = self .timeout ),
872
+ ** config )
863
873
864
874
865
875
class ArlingtonCloudTestCase (LabBasedTestCase ):
0 commit comments