From 23e0cf88e4cbcf66f63355044626f2630249a576 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 12 Apr 2023 17:20:24 +0200 Subject: [PATCH 1/3] Better handle values from identity data --- CHANGELOG.md | 2 +- .../authomatic/tests/test_useridentities.py | 19 +++++++++++++++++++ src/pas/plugins/authomatic/useridentities.py | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ef4e51..267ab60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 1.1.3 (unreleased) -- Nothing changed yet. +- Better handle values from identity data. @cekk ## 1.1.2 (2023-03-15) diff --git a/src/pas/plugins/authomatic/tests/test_useridentities.py b/src/pas/plugins/authomatic/tests/test_useridentities.py index db5858b..bd9507c 100644 --- a/src/pas/plugins/authomatic/tests/test_useridentities.py +++ b/src/pas/plugins/authomatic/tests/test_useridentities.py @@ -132,5 +132,24 @@ def test_provider_specific_user_attributes(self): self.assertEqual(sheet.getProperty("email"), "andrewpipkin@foobar.com") self.assertEqual(sheet.getProperty("customdomain"), "foobar.com") + def test_read_attribute_from_provider_data_if_default_is_none(self): + PNAME = "mockhub" + user = self._make_authomatic_user( + provider_name=PNAME,data={'email': 'jdoe@foobar.com'}) + user.email = None + authomatic_result = MockResult( + user=user, + provider=MockResult(name=PNAME), + ) + uis = make_user("mustermann") + uis.handle_result(authomatic_result) + + # mock cfg + with mock.patch("pas.plugins.authomatic.useridentities.authomatic_cfg") as acfg: + cfg = self._make_cfg(PNAME) + acfg.return_value = cfg + sheet = uis.propertysheet + self.assertEqual(sheet.getProperty("email"), "jdoe@foobar.com") + def test_credentials(self): pass diff --git a/src/pas/plugins/authomatic/useridentities.py b/src/pas/plugins/authomatic/useridentities.py index d45e807..8fd4de1 100644 --- a/src/pas/plugins/authomatic/useridentities.py +++ b/src/pas/plugins/authomatic/useridentities.py @@ -71,7 +71,7 @@ def propertysheet(self): for akey, pkey in cfg.get("propertymap", {}).items(): # Always search first on the user attributes, then on the raw # data this guaratees we do not break existing configurations - ainfo = identity.get(akey, identity["data"].get(akey, None)) + ainfo = identity.get(akey, None) or identity["data"].get(akey, None) if ainfo is None: continue if isinstance(pkey, dict): From 006eea11e50ae31c683a95225071751c2d3c38cf Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 12 Apr 2023 17:52:00 +0200 Subject: [PATCH 2/3] blacked --- src/pas/plugins/authomatic/tests/test_useridentities.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pas/plugins/authomatic/tests/test_useridentities.py b/src/pas/plugins/authomatic/tests/test_useridentities.py index bd9507c..f3aec7f 100644 --- a/src/pas/plugins/authomatic/tests/test_useridentities.py +++ b/src/pas/plugins/authomatic/tests/test_useridentities.py @@ -135,7 +135,8 @@ def test_provider_specific_user_attributes(self): def test_read_attribute_from_provider_data_if_default_is_none(self): PNAME = "mockhub" user = self._make_authomatic_user( - provider_name=PNAME,data={'email': 'jdoe@foobar.com'}) + provider_name=PNAME, data={'email': 'jdoe@foobar.com'} + ) user.email = None authomatic_result = MockResult( user=user, @@ -150,6 +151,6 @@ def test_read_attribute_from_provider_data_if_default_is_none(self): acfg.return_value = cfg sheet = uis.propertysheet self.assertEqual(sheet.getProperty("email"), "jdoe@foobar.com") - + def test_credentials(self): pass From 4a00b2d9f5e690ddcc1bfaa515e50065fe3d400f Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 12 Apr 2023 17:54:27 +0200 Subject: [PATCH 3/3] blacked again --- src/pas/plugins/authomatic/tests/test_useridentities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pas/plugins/authomatic/tests/test_useridentities.py b/src/pas/plugins/authomatic/tests/test_useridentities.py index f3aec7f..450f254 100644 --- a/src/pas/plugins/authomatic/tests/test_useridentities.py +++ b/src/pas/plugins/authomatic/tests/test_useridentities.py @@ -135,7 +135,7 @@ def test_provider_specific_user_attributes(self): def test_read_attribute_from_provider_data_if_default_is_none(self): PNAME = "mockhub" user = self._make_authomatic_user( - provider_name=PNAME, data={'email': 'jdoe@foobar.com'} + provider_name=PNAME, data={"email": "jdoe@foobar.com"} ) user.email = None authomatic_result = MockResult(