From 428802b9d0707f31dffcb68f91a9e87a6178215a Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 22 Jul 2021 10:44:41 -0400 Subject: [PATCH 1/3] Modify LDAP script so that it doesn't raise an error when we don't get a record back from LDAP. We now return an empty dictionary --- crc/scripts/ldap.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/crc/scripts/ldap.py b/crc/scripts/ldap.py index 061219a3..dfaf7b07 100644 --- a/crc/scripts/ldap.py +++ b/crc/scripts/ldap.py @@ -48,21 +48,29 @@ supervisor_info = ldap(supervisor_uid) // Sets the supervisor information to l "UID for the person we want to look up.") if len(args) < 1: if UserService.has_user(): - uid = UserService.current_user().uid + uid = UserService.current_user().uid else: uid = args[0] - user_info = LdapService.user_info(uid) - user_info_dict = { - "display_name": user_info.display_name, - "given_name": user_info.given_name, - "email_address": user_info.email_address, - "telephone_number": user_info.telephone_number, - "title": user_info.title, - "department": user_info.department, - "affiliation": user_info.affiliation, - "sponsor_type": user_info.sponsor_type, - "uid": user_info.uid, - "proper_name": user_info.proper_name() - } - return user_info_dict + try: + user_info = LdapService.user_info(uid) + except ApiError as ae: + app.logger.info(ae) + return {} + except Exception as e: + app.logger.info(e) + return {} + else: + user_info_dict = { + "display_name": user_info.display_name, + "given_name": user_info.given_name, + "email_address": user_info.email_address, + "telephone_number": user_info.telephone_number, + "title": user_info.title, + "department": user_info.department, + "affiliation": user_info.affiliation, + "sponsor_type": user_info.sponsor_type, + "uid": user_info.uid, + "proper_name": user_info.proper_name() + } + return user_info_dict From 8df1145471b822f5e65fdbf76eaf83fc1852575c Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 22 Jul 2021 10:46:09 -0400 Subject: [PATCH 2/3] Modify the LDAP service to only use lowercase UIDs. UVA always returns the UID as lowercase. This caused a postgres unique value problem for us. --- crc/services/ldap_service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/crc/services/ldap_service.py b/crc/services/ldap_service.py index da6976b7..3ecd634d 100644 --- a/crc/services/ldap_service.py +++ b/crc/services/ldap_service.py @@ -58,6 +58,7 @@ class LdapService(object): @staticmethod def user_info(uva_uid): + uva_uid = uva_uid.lower() user_info = db.session.query(LdapModel).filter(LdapModel.uid == uva_uid).first() if not user_info: app.logger.info("No cache for " + uva_uid) From 6b51fc7c065c612c77f5d614f3372a1025a77177 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 22 Jul 2021 10:47:25 -0400 Subject: [PATCH 3/3] Added a test with uppercase UID Modified the script test to expect an empty dictionary now, instead of raising an error --- tests/ldap/test_ldap_lookup_script.py | 4 ++-- tests/test_ldap_service.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/ldap/test_ldap_lookup_script.py b/tests/ldap/test_ldap_lookup_script.py index c8c72e63..e7bdf658 100644 --- a/tests/ldap/test_ldap_lookup_script.py +++ b/tests/ldap/test_ldap_lookup_script.py @@ -45,8 +45,8 @@ class TestLdapLookupScript(BaseTest): } script = Ldap() - with(self.assertRaises(ApiError)): - user_details = script.do_task(task, workflow.study_id, workflow.id, "PIComputingID") + user_details = script.do_task(task, workflow.study_id, workflow.id, "PIComputingID") + self.assertEqual({}, user_details) def test_get_current_user_details(self): self.load_example_data() diff --git a/tests/test_ldap_service.py b/tests/test_ldap_service.py index d1e0ee21..3463662e 100644 --- a/tests/test_ldap_service.py +++ b/tests/test_ldap_service.py @@ -31,3 +31,8 @@ class TestLdapService(BaseTest): self.assertFalse(True, "An API error should be raised.") except ApiError as ae: self.assertEqual("missing_ldap_record", ae.code) + + def test_get_user_with_caps(self): + user_info = LdapService.user_info("LB3DP") + self.assertIsNotNone(user_info) + self.assertEqual("lb3dp", user_info.uid)