@@ -196,6 +196,8 @@ def _test_username_password(self,
196
196
azure_region = azure_region , # Regional endpoint does not support ROPC.
197
197
# Here we just use it to test a regional app won't break ROPC.
198
198
client_credential = client_secret )
199
+ self .assertEqual (
200
+ self .app .get_accounts (username = username ), [], "Cache starts empty" )
199
201
result = self .app .acquire_token_by_username_password (
200
202
username , password , scopes = scope )
201
203
self .assertLoosely (result )
@@ -204,6 +206,9 @@ def _test_username_password(self,
204
206
username = username , # Our implementation works even when "profile" scope was not requested, or when profile claims is unavailable in B2C
205
207
)
206
208
209
+ @unittest .skipIf (
210
+ os .getenv ("TRAVIS" ), # It is set when running on TravisCI or Github Actions
211
+ "Although it is doable, we still choose to skip device flow to save time" )
207
212
def _test_device_flow (
208
213
self , client_id = None , authority = None , scope = None , ** ignored ):
209
214
assert client_id and authority and scope
@@ -229,6 +234,7 @@ def _test_device_flow(
229
234
logger .info (
230
235
"%s obtained tokens: %s" , self .id (), json .dumps (result , indent = 4 ))
231
236
237
+ @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
232
238
def _test_acquire_token_interactive (
233
239
self , client_id = None , authority = None , scope = None , port = None ,
234
240
username = None , lab_name = None ,
@@ -289,7 +295,6 @@ def test_ssh_cert_for_service_principal(self):
289
295
result .get ("error" ), result .get ("error_description" )))
290
296
self .assertEqual ("ssh-cert" , result ["token_type" ])
291
297
292
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
293
298
def test_ssh_cert_for_user_should_work_with_any_account (self ):
294
299
result = self ._test_acquire_token_interactive (
295
300
client_id = "04b07795-8ddb-461a-bbee-02f9e1bf7b46" , # Azure CLI is one
@@ -524,8 +529,8 @@ def tearDownClass(cls):
524
529
cls .session .close ()
525
530
526
531
@classmethod
527
- def get_lab_app_object (cls , ** query ): # https://msidlab.com/swagger/index.html
528
- url = "https://msidlab.com/api/app"
532
+ def get_lab_app_object (cls , client_id = None , ** query ): # https://msidlab.com/swagger/index.html
533
+ url = "https://msidlab.com/api/app/{}" . format ( client_id or "" )
529
534
resp = cls .session .get (url , params = query )
530
535
result = resp .json ()[0 ]
531
536
result ["scopes" ] = [ # Raw data has extra space, such as "s1, s2"
@@ -546,6 +551,8 @@ def get_lab_user_secret(cls, lab_name="msidlab4"):
546
551
def get_lab_user (cls , ** query ): # https://docs.msidlab.com/labapi/userapi.html
547
552
resp = cls .session .get ("https://msidlab.com/api/user" , params = query )
548
553
result = resp .json ()[0 ]
554
+ assert result .get ("upn" ), "Found no test user but {}" .format (
555
+ json .dumps (result , indent = 2 ))
549
556
_env = query .get ("azureenvironment" , "" ).lower ()
550
557
authority_base = {
551
558
"azureusgovernment" : "https://login.microsoftonline.us/"
@@ -561,6 +568,7 @@ def get_lab_user(cls, **query): # https://docs.msidlab.com/labapi/userapi.html
561
568
"scope" : scope ,
562
569
}
563
570
571
+ @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
564
572
def _test_acquire_token_by_auth_code (
565
573
self , client_id = None , authority = None , port = None , scope = None ,
566
574
** ignored ):
@@ -583,6 +591,7 @@ def _test_acquire_token_by_auth_code(
583
591
error_description = result .get ("error_description" )))
584
592
self .assertCacheWorksForUser (result , scope , username = None )
585
593
594
+ @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
586
595
def _test_acquire_token_by_auth_code_flow (
587
596
self , client_id = None , authority = None , port = None , scope = None ,
588
597
username = None , lab_name = None ,
@@ -723,11 +732,9 @@ def test_adfs2019_fed_user(self):
723
732
self .skipTest ("MEX endpoint in our test environment tends to fail" )
724
733
raise
725
734
726
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
727
735
def test_cloud_acquire_token_interactive (self ):
728
736
self ._test_acquire_token_interactive (** self .get_lab_user (usertype = "cloud" ))
729
737
730
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
731
738
def test_msa_pt_app_signin_via_organizations_authority_without_login_hint (self ):
732
739
"""There is/was an upstream bug. See test case full docstring for the details.
733
740
@@ -751,7 +758,6 @@ def test_ropc_adfs2019_onprem(self):
751
758
config ["password" ] = self .get_lab_user_secret (config ["lab_name" ])
752
759
self ._test_username_password (** config )
753
760
754
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
755
761
def test_adfs2019_onprem_acquire_token_by_auth_code (self ):
756
762
"""When prompted, you can manually login using this account:
757
763
@@ -765,7 +771,6 @@ def test_adfs2019_onprem_acquire_token_by_auth_code(self):
765
771
config ["port" ] = 8080
766
772
self ._test_acquire_token_by_auth_code (** config )
767
773
768
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
769
774
def test_adfs2019_onprem_acquire_token_by_auth_code_flow (self ):
770
775
config = self .get_lab_user (usertype = "onprem" , federationProvider = "ADFSv2019" )
771
776
self ._test_acquire_token_by_auth_code_flow (** dict (
@@ -775,7 +780,6 @@ def test_adfs2019_onprem_acquire_token_by_auth_code_flow(self):
775
780
port = 8080 ,
776
781
))
777
782
778
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
779
783
def test_adfs2019_onprem_acquire_token_interactive (self ):
780
784
config = self .get_lab_user (usertype = "onprem" , federationProvider = "ADFSv2019" )
781
785
self ._test_acquire_token_interactive (** dict (
@@ -846,7 +850,6 @@ def _build_b2c_authority(self, policy):
846
850
base = "https://msidlabb2c.b2clogin.com/msidlabb2c.onmicrosoft.com"
847
851
return base + "/" + policy # We do not support base + "?p=" + policy
848
852
849
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
850
853
def test_b2c_acquire_token_by_auth_code (self ):
851
854
"""
852
855
When prompted, you can manually login using this account:
@@ -863,7 +866,6 @@ def test_b2c_acquire_token_by_auth_code(self):
863
866
scope = config ["scopes" ],
864
867
)
865
868
866
- @unittest .skipIf (os .getenv ("TRAVIS" ), "Browser automation is not yet implemented" )
867
869
def test_b2c_acquire_token_by_auth_code_flow (self ):
868
870
self ._test_acquire_token_by_auth_code_flow (** dict (
869
871
self .get_lab_user (usertype = "b2c" , b2cprovider = "local" ),
@@ -882,6 +884,18 @@ def test_b2c_acquire_token_by_ropc(self):
882
884
scope = config ["scopes" ],
883
885
)
884
886
887
+ def test_b2c_allows_using_client_id_as_scope (self ):
888
+ # See also https://learn.microsoft.com/en-us/azure/active-directory-b2c/access-tokens#openid-connect-scopes
889
+ config = self .get_lab_app_object (azureenvironment = "azureb2ccloud" )
890
+ config ["scopes" ] = [config ["appId" ]]
891
+ self ._test_username_password (
892
+ authority = self ._build_b2c_authority ("B2C_1_ROPC_Auth" ),
893
+ client_id = config ["appId" ],
894
+ username = "b2clocal@msidlabb2c.onmicrosoft.com" ,
895
+ password = self .get_lab_user_secret ("msidlabb2c" ),
896
+ scope = config ["scopes" ],
897
+ )
898
+
885
899
886
900
class WorldWideRegionalEndpointTestCase (LabBasedTestCase ):
887
901
region = "westus"
@@ -904,7 +918,7 @@ def _test_acquire_token_for_client(self, configured_region, expected_region):
904
918
self .app .http_client , "post" , return_value = MinimalResponse (
905
919
status_code = 400 , text = '{"error": "mock"}' )) as mocked_method :
906
920
self .app .acquire_token_for_client (scopes )
907
- expected_host = '{}.r. login.microsoftonline .com' .format (
921
+ expected_host = '{}.login.microsoft .com' .format (
908
922
expected_region ) if expected_region else 'login.microsoftonline.com'
909
923
mocked_method .assert_called_with (
910
924
'https://{}/{}/oauth2/v2.0/token' .format (
0 commit comments