From ce038d48f5f3173daf69933c900da3e9586d9948 Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Wed, 29 May 2024 16:26:45 -0400 Subject: [PATCH] fix: add utf-8 encoding for user fields --- lti_consumer/lti_xblock.py | 2 +- lti_consumer/tests/unit/test_lti_xblock.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py index 08789041..51021775 100644 --- a/lti_consumer/lti_xblock.py +++ b/lti_consumer/lti_xblock.py @@ -1130,7 +1130,7 @@ def extract_real_user_data(self): user_data = { 'user_email': None, 'user_username': None, - 'user_full_name': user.full_name, + 'user_full_name': user.full_name.encode(), 'user_language': None, } diff --git a/lti_consumer/tests/unit/test_lti_xblock.py b/lti_consumer/tests/unit/test_lti_xblock.py index f489ee27..2e812505 100644 --- a/lti_consumer/tests/unit/test_lti_xblock.py +++ b/lti_consumer/tests/unit/test_lti_xblock.py @@ -957,7 +957,8 @@ def setUp(self): fake_user_email = 'abc@example.com' fake_user.emails = [fake_user_email] - full_name_mock = PropertyMock(return_value='fake_full_name') + fake_name = 'fáke fǔll ñamë' + full_name_mock = PropertyMock(return_value=fake_name) type(fake_user).full_name = full_name_mock fake_username = 'fake' @@ -1077,7 +1078,7 @@ def test_lti_launch_pii_sharing( set_user_data_kwargs['person_sourcedid'] = 'fake' if pii_sharing_enabled and ask_to_send_username else None set_user_data_kwargs['person_name_full'] = ( - 'fake_full_name' if pii_sharing_enabled and ask_to_send_full_name else None + 'fáke fǔll ñamë'.encode() if pii_sharing_enabled and ask_to_send_full_name else None ) set_user_data_kwargs['person_contact_email_primary'] = ( 'abc@example.com' if pii_sharing_enabled and ask_to_send_email else None @@ -1814,7 +1815,7 @@ def test_get_lti_1p3_launch_data( fake_user_email = 'fake_email@example.com' fake_username = 'fake_username' - fake_name = 'fake_full_name' + fake_name = 'fáke fǔll ñamë' full_name_mock = PropertyMock(return_value=fake_name) type(fake_user).full_name = full_name_mock @@ -1866,7 +1867,7 @@ def test_get_lti_1p3_launch_data( expected_launch_data_kwargs["preferred_username"] = fake_username if ask_to_send_full_name: - expected_launch_data_kwargs["name"] = fake_name + expected_launch_data_kwargs["name"] = fake_name.encode() if ask_to_send_email: expected_launch_data_kwargs["email"] = fake_user_email