changeset 3250:e4d3ba75b1b2

core (memory/disco): fixed types of disco extensions: typeCheck() is not automatically called on reception by Wokkel, as a result extensions fields values may be strings instead of the field type. TypeCheck is now explicitly called in memory.disco to avoid that. It is not called immediately on reception as the string value is needed to calculate the capability hash
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 20:25:05 +0200 (2020-04-14)
parents f16c96c7a91a
children f21412896620
files sat/memory/disco.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/disco.py	Fri Apr 03 18:02:31 2020 +0200
+++ b/sat/memory/disco.py	Tue Apr 14 20:25:05 2020 +0200
@@ -87,6 +87,9 @@
             for hash_, xml in hashes.items():
                 element = xml_tools.ElementParser()(xml)
                 disco_info = disco.DiscoInfo.fromElement(element)
+                for ext_form in disco_info.extensions.values():
+                    # wokkel doesn't call typeCheck on reception, so we do it here
+                    ext_form.typeCheck()
                 if not disco_info.features and not disco_info.identities:
                     log.warning(
                         _(
@@ -180,6 +183,12 @@
             # capability hash is not available, we'll compute one
             def infosCb(disco_infos):
                 cap_hash = self.generateHash(disco_infos)
+                for ext_form in disco_infos.extensions.values():
+                    # wokkel doesn't call typeCheck on reception, so we do it here
+                    # to avoid ending up with incorrect types. We have to do it after
+                    # the hash has been generated (str value is needed to compute the
+                    # hash)
+                    ext_form.typeCheck()
                 self.hashes[cap_hash] = disco_infos
                 self.host.memory.updateEntityData(
                     jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile
@@ -405,7 +414,7 @@
     def _discoInfos(
         self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE
     ):
-        """ Discovery method for the bridge
+        """Discovery method for the bridge
         @param entity_jid_s: entity we want to discover
         @param use_cache(bool): if True, use cached data if available
         @param node(unicode): optional node to use