From dda0e2c8686df44c99d8a34a30b2cc40c40d905e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 5 Jul 2016 12:36:32 +0200 Subject: [PATCH] When creating user from BlenderID, full_name defaults to username. --- pillar/application/modules/blender_id.py | 8 ++++++-- pillar/settings.py | 2 +- tests/test_blender_id_subclient.py | 26 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pillar/application/modules/blender_id.py b/pillar/application/modules/blender_id.py index 7dfbe680..443507f8 100644 --- a/pillar/application/modules/blender_id.py +++ b/pillar/application/modules/blender_id.py @@ -209,8 +209,12 @@ def find_user_in_db(blender_id_user_id, user_info): db_user['email'] = user_info['email'] else: log.debug('User %r not yet in our database, create a new one.', blender_id_user_id) - db_user = authentication.create_new_user_document(user_info['email'], blender_id_user_id, - user_info['full_name']) + db_user = authentication.create_new_user_document( + email=user_info['email'], + user_id=blender_id_user_id, + username=user_info['full_name']) db_user['username'] = authentication.make_unique_username(user_info['email']) + if not db_user['full_name']: + db_user['full_name'] = db_user['username'] return db_user diff --git a/pillar/settings.py b/pillar/settings.py index 7596e415..5bcad025 100644 --- a/pillar/settings.py +++ b/pillar/settings.py @@ -44,7 +44,7 @@ _activity_object_type = { users_schema = { 'full_name': { 'type': 'string', - 'minlength': 3, + 'minlength': 1, 'maxlength': 128, 'required': True, }, diff --git a/tests/test_blender_id_subclient.py b/tests/test_blender_id_subclient.py index f5413d29..a95e2cf5 100644 --- a/tests/test_blender_id_subclient.py +++ b/tests/test_blender_id_subclient.py @@ -7,7 +7,7 @@ from bson import ObjectId from flask import g from common_test_class import (AbstractPillarTest, TEST_EMAIL_ADDRESS, BLENDER_ID_TEST_USERID, - TEST_SUBCLIENT_TOKEN, BLENDER_ID_USER_RESPONSE, TEST_FULL_NAME) + TEST_SUBCLIENT_TOKEN, TEST_EMAIL_USER, TEST_FULL_NAME) class BlenderIdSubclientTest(AbstractPillarTest): @@ -15,6 +15,22 @@ class BlenderIdSubclientTest(AbstractPillarTest): def test_store_scst_new_user(self): self._common_user_test(201) + @responses.activate + def test_store_scst_new_user_without_full_name(self): + + responses.add(responses.POST, + '%s/u/validate_token' % self.app.config['BLENDER_ID_ENDPOINT'], + json={'status': 'success', + 'user': {'email': TEST_EMAIL_ADDRESS, + 'full_name': None, + 'id': BLENDER_ID_TEST_USERID}, + 'token_expires': 'Mon, 1 Jan 2218 01:02:03 GMT'}, + status=200) + + self._common_user_test(201, + expected_full_name=TEST_EMAIL_USER, + mock_happy_blender_id=False) + @responses.activate def test_store_scst_existing_user(self): # Make sure the user exists in our database. @@ -58,15 +74,17 @@ class BlenderIdSubclientTest(AbstractPillarTest): self.assertEqual(db_user['_id'], g.current_user['user_id']) def _common_user_test(self, expected_status_code, scst=TEST_SUBCLIENT_TOKEN, - expected_full_name=TEST_FULL_NAME): - self.mock_blenderid_validate_happy() + expected_full_name=TEST_FULL_NAME, + mock_happy_blender_id=True): + if mock_happy_blender_id: + self.mock_blenderid_validate_happy() subclient_id = self.app.config['BLENDER_ID_SUBCLIENT_ID'] resp = self.client.post('/blender_id/store_scst', data={'user_id': BLENDER_ID_TEST_USERID, 'subclient_id': subclient_id, 'token': scst}) - self.assertEqual(expected_status_code, resp.status_code) + self.assertEqual(expected_status_code, resp.status_code, resp.data) user_info = json.loads(resp.data) # {'status': 'success', 'subclient_user_id': '...'} self.assertEqual('success', user_info['status'])