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..450f254 100644 --- a/src/pas/plugins/authomatic/tests/test_useridentities.py +++ b/src/pas/plugins/authomatic/tests/test_useridentities.py @@ -132,5 +132,25 @@ 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):