@@ -97,7 +97,8 @@ def test_pem_with_certificate_only_uses_sha256(
9797 self , mock_extract , mock_load_cert , mock_jwt_creator_class , mock_authority_class ):
9898 """Test that providing only public_certificate (no thumbprint) uses SHA-256"""
9999 authority = "https://login.microsoftonline.com/common"
100- self ._setup_mocks (mock_authority_class , authority )
100+ mock_authority = self ._setup_mocks (mock_authority_class , authority )
101+ mock_authority ._is_oidc = False # AAD is not OIDC generic
101102 self ._setup_certificate_mocks (mock_extract , mock_load_cert )
102103
103104 # Create app with certificate credential WITHOUT thumbprint
@@ -243,7 +244,8 @@ def test_pem_with_both_thumbprints_aad_uses_sha256(
243244 self , mock_jwt_creator_class , mock_authority_class ):
244245 """Test that with both thumbprints, AAD authority uses SHA-256"""
245246 authority = "https://login.microsoftonline.com/common"
246- self ._setup_mocks (mock_authority_class , authority )
247+ mock_authority = self ._setup_mocks (mock_authority_class , authority )
248+ mock_authority ._is_oidc = False # AAD is not OIDC generic
247249
248250 # Create app with BOTH thumbprints for AAD
249251 app = ConfidentialClientApplication (
@@ -295,6 +297,7 @@ def test_pem_with_both_thumbprints_b2c_uses_sha256(
295297 authority = "https://contoso.b2clogin.com/contoso.onmicrosoft.com/B2C_1_susi"
296298 mock_authority = self ._setup_mocks (mock_authority_class , authority )
297299 mock_authority ._is_b2c = True # Manually set _is_b2c to True for this B2C authority
300+ mock_authority ._is_oidc = False # B2C is not OIDC generic
298301
299302 # Create app with BOTH thumbprints for B2C
300303 app = ConfidentialClientApplication (
@@ -320,6 +323,8 @@ def test_pem_with_both_thumbprints_ciam_uses_sha256(
320323 """Test that with both thumbprints, CIAM authority uses SHA-256"""
321324 authority = "https://contoso.ciamlogin.com/contoso.onmicrosoft.com"
322325 mock_authority = self ._setup_mocks (mock_authority_class , authority )
326+ mock_authority ._is_b2c = True # CIAM sets _is_b2c to True
327+ mock_authority ._is_oidc = False # CIAM is not OIDC generic
323328
324329 # Create app with BOTH thumbprints for CIAM
325330 app = ConfidentialClientApplication (
@@ -342,15 +347,16 @@ def test_pem_with_both_thumbprints_ciam_uses_sha256(
342347
343348 def test_pem_with_both_thumbprints_generic_uses_sha1 (
344349 self , mock_jwt_creator_class , mock_authority_class ):
345- """Test that with both thumbprints, generic authority uses SHA-1"""
346- authority = "https://custom.authority.com/tenant"
350+ """Test that with both thumbprints, OIDC generic authority uses SHA-1"""
351+ authority = "https://custom.oidc. authority.com/tenant"
347352 mock_authority = self ._setup_mocks (mock_authority_class , authority )
348353
349- # Set up as a generic authority (not ADFS, not B2C, not in known hosts)
354+ # Set up as an OIDC generic authority
350355 mock_authority .is_adfs = False
351- mock_authority ._is_b2c = False
356+ mock_authority ._is_b2c = True # OIDC sets this but it's not truly B2C
357+ mock_authority ._is_oidc = True # This distinguishes OIDC from B2C/CIAM
352358
353- # Create app with BOTH thumbprints for generic authority
359+ # Create app with BOTH thumbprints for OIDC generic authority
354360 app = ConfidentialClientApplication (
355361 client_id = "my_client_id" ,
356362 client_credential = {
@@ -361,14 +367,44 @@ def test_pem_with_both_thumbprints_generic_uses_sha1(
361367 authority = authority
362368 )
363369
364- # For generic authorities, should use SHA-1 when both are provided
370+ # For OIDC generic authorities, should use SHA-1 when both are provided
365371 self ._verify_assertion_params (
366372 mock_jwt_creator_class ,
367373 expected_algorithm = 'RS256' ,
368374 expected_thumbprint_type = 'sha1' ,
369375 expected_thumbprint_value = self .test_sha1_thumbprint
370376 )
371377
378+ def test_pem_with_both_thumbprints_unknown_aad_uses_sha256 (
379+ self , mock_jwt_creator_class , mock_authority_class ):
380+ """Test that with both thumbprints, unknown AAD authority (e.g., sovereign cloud) uses SHA-256"""
381+ authority = "https://login.microsoftonline.de/tenant" # Example of sovereign cloud not in known list
382+ mock_authority = self ._setup_mocks (mock_authority_class , authority )
383+
384+ # Set up as an AAD authority (not ADFS, not B2C, not OIDC)
385+ mock_authority .is_adfs = False
386+ mock_authority ._is_b2c = False
387+ mock_authority ._is_oidc = False
388+
389+ # Create app with BOTH thumbprints for unknown AAD authority
390+ app = ConfidentialClientApplication (
391+ client_id = "my_client_id" ,
392+ client_credential = {
393+ "private_key" : self .test_private_key ,
394+ "thumbprint" : self .test_sha1_thumbprint ,
395+ "thumbprint_sha256" : self .test_sha256_thumbprint ,
396+ },
397+ authority = authority
398+ )
399+
400+ # For AAD authorities (even unknown ones), should use SHA-256 when both are provided
401+ self ._verify_assertion_params (
402+ mock_jwt_creator_class ,
403+ expected_algorithm = 'PS256' ,
404+ expected_thumbprint_type = 'sha256' ,
405+ expected_thumbprint_value = self .test_sha256_thumbprint
406+ )
407+
372408
373409if __name__ == "__main__" :
374410 unittest .main ()
0 commit comments