@@ -1197,6 +1197,37 @@ def mock_post(url, headers=None, data=None, *args, **kwargs):
11971197 self .assertNotIn ("username" , captured_data ,
11981198 "username should NOT be in body when user_object_id is provided" )
11991199
1200+ def test_ccs_routing_header_with_username (self ):
1201+ app = self ._make_app ()
1202+ captured_headers = {}
1203+
1204+ def mock_post (url , headers = None , data = None , * args , ** kwargs ):
1205+ captured_headers .update (headers or {})
1206+ return MinimalResponse (status_code = 200 , text = _build_user_fic_response ())
1207+
1208+ app .acquire_token_by_user_federated_identity_credential (
1209+ ["scope" ], assertion = "t2" , username = "user@contoso.com" , post = mock_post )
1210+ self .assertEqual ("upn:user@contoso.com" ,
1211+ captured_headers .get ("X-AnchorMailbox" ),
1212+ "CCS routing header should use UPN format for username path" )
1213+
1214+ def test_ccs_routing_header_with_oid (self ):
1215+ app = self ._make_app ()
1216+ captured_headers = {}
1217+
1218+ def mock_post (url , headers = None , data = None , * args , ** kwargs ):
1219+ captured_headers .update (headers or {})
1220+ return MinimalResponse (status_code = 200 , text = _build_user_fic_response ())
1221+
1222+ app .acquire_token_by_user_federated_identity_credential (
1223+ ["scope" ], assertion = "t2" ,
1224+ user_object_id = "user_oid_123" , post = mock_post )
1225+ self .assertIn ("X-AnchorMailbox" , captured_headers ,
1226+ "CCS routing header should be present for OID path" )
1227+ self .assertTrue (
1228+ captured_headers ["X-AnchorMailbox" ].startswith ("Oid:" ),
1229+ "CCS routing header should use Oid format for user_object_id path" )
1230+
12001231
12011232@patch (_OIDC_DISCOVERY , new = _OIDC_DISCOVERY_MOCK )
12021233class TestUserFicCacheBehavior (unittest .TestCase ):
@@ -1291,6 +1322,24 @@ def mock_post(url, headers=None, data=None, *args, **kwargs):
12911322 self .assertIn ("access_token" , silent_result )
12921323 self .assertEqual ("oid_fic_at" , silent_result ["access_token" ])
12931324
1325+ def test_account_source_is_set_to_user_fic (self ):
1326+ """Accounts created by user_fic should have account_source set."""
1327+ app = self ._make_app ()
1328+
1329+ def mock_post (url , headers = None , data = None , * args , ** kwargs ):
1330+ return MinimalResponse (status_code = 200 , text = _build_user_fic_response (
1331+ uid = "user_oid" , utid = "tenant_id" ))
1332+
1333+ app .acquire_token_by_user_federated_identity_credential (
1334+ ["https://graph.microsoft.com/.default" ],
1335+ assertion = "t2" , username = "user@contoso.com" , post = mock_post )
1336+
1337+ accounts = app .get_accounts ()
1338+ self .assertTrue (len (accounts ) > 0 )
1339+ self .assertEqual ("user_fic" , accounts [0 ].get ("account_source" ),
1340+ "FIC accounts should have account_source='user_fic' to avoid "
1341+ "broker path misrouting" )
1342+
12941343
12951344@patch (_OIDC_DISCOVERY , new = _OIDC_DISCOVERY_MOCK )
12961345class TestUserFicInputValidation (unittest .TestCase ):
0 commit comments