@@ -283,6 +283,7 @@ def test_api_rooms_retrieve_authenticated_trusted(mock_token):
283283 Authenticated users should be allowed to retrieve a room and get a token for a room to
284284 which they are not related, provided the room has a trusted access_level.
285285 They should not see related users.
286+ The username should be forced to the user's official name.
286287 """
287288 room = RoomFactory (access_level = RoomAccessLevel .TRUSTED )
288289
@@ -310,10 +311,84 @@ def test_api_rooms_retrieve_authenticated_trusted(mock_token):
310311 "slug" : room .slug ,
311312 }
312313
314+ # Username is forced to user's full_name in trusted rooms
313315 mock_token .assert_called_once_with (
314316 room = expected_name ,
315317 user = user ,
316- username = None ,
318+ username = user .full_name ,
319+ color = None ,
320+ sources = None ,
321+ is_admin_or_owner = False ,
322+ participant_id = None ,
323+ )
324+
325+
326+ @mock .patch ("core.utils.generate_token" , return_value = "foo" )
327+ @override_settings (
328+ LIVEKIT_CONFIGURATION = {
329+ "api_key" : "key" ,
330+ "api_secret" : "secret" ,
331+ "url" : "test_url_value" ,
332+ }
333+ )
334+ def test_api_rooms_retrieve_authenticated_trusted_forces_official_name (mock_token ):
335+ """
336+ When a room has trusted access level and the user is authenticated,
337+ the username should be forced to the user's official ProConnect name
338+ (full_name), ignoring any custom username passed as query parameter.
339+ """
340+ room = RoomFactory (access_level = RoomAccessLevel .TRUSTED )
341+
342+ user = UserFactory (full_name = "Jean Dupont" )
343+ client = APIClient ()
344+ client .force_login (user )
345+
346+ response = client .get (
347+ f"/api/v1.0/rooms/{ room .id !s} /?username=FakeIdentity" ,
348+ )
349+ assert response .status_code == 200
350+
351+ expected_name = f"{ room .id !s} "
352+ mock_token .assert_called_once_with (
353+ room = expected_name ,
354+ user = user ,
355+ username = "Jean Dupont" ,
356+ color = None ,
357+ sources = None ,
358+ is_admin_or_owner = False ,
359+ participant_id = None ,
360+ )
361+
362+
363+ @mock .patch ("core.utils.generate_token" , return_value = "foo" )
364+ @override_settings (
365+ LIVEKIT_CONFIGURATION = {
366+ "api_key" : "key" ,
367+ "api_secret" : "secret" ,
368+ "url" : "test_url_value" ,
369+ }
370+ )
371+ def test_api_rooms_retrieve_authenticated_trusted_fallback_to_email (mock_token ):
372+ """
373+ When a room has trusted access level and the user is authenticated but has no
374+ full_name, the username should fall back to str(user) (email).
375+ """
376+ room = RoomFactory (access_level = RoomAccessLevel .TRUSTED )
377+
378+ user = UserFactory (full_name = "" )
379+ client = APIClient ()
380+ client .force_login (user )
381+
382+ response = client .get (
383+ f"/api/v1.0/rooms/{ room .id !s} /?username=FakeIdentity" ,
384+ )
385+ assert response .status_code == 200
386+
387+ expected_name = f"{ room .id !s} "
388+ mock_token .assert_called_once_with (
389+ room = expected_name ,
390+ user = user ,
391+ username = str (user ),
317392 color = None ,
318393 sources = None ,
319394 is_admin_or_owner = False ,
0 commit comments