# HG changeset patch # User Goffi # Date 1557210331 -7200 # Node ID 371e72871e192afabce889bf8794bcccadbbc4c1 # Parent 2521c53bc3590f320068c2a340772fce7ddc37db privilege: fill hash_map before jid_caps to avoid KeyError in getAutoSubscribers diff -r 2521c53bc359 -r 371e72871e19 src/privilege.py --- a/src/privilege.py Mon May 06 09:37:47 2019 +0200 +++ b/src/privilege.py Tue May 07 08:25:31 2019 +0200 @@ -255,9 +255,6 @@ # FIXME: hash is not checked (cf. XEP-0115) disco_tuple = (hash_, ver) - jid_caps = self.caps_map.setdefault(from_jid_bare, {}) - if from_jid.resource not in jid_caps: - jid_caps[from_jid.resource] = disco_tuple if disco_tuple not in self.hash_map: # first time we se this hash, what is behind it? @@ -267,6 +264,12 @@ 'infos': infos } + # jid_caps must be filled only after hash_map is set, to be sure that + # the hash data is available in getAutoSubscribers + jid_caps = self.caps_map.setdefault(from_jid_bare, {}) + if from_jid.resource not in jid_caps: + jid_caps[from_jid.resource] = disco_tuple + # nodes are the nodes subscribed with +notify nodes = tuple(self.hash_map[disco_tuple]['notify']) if not nodes: @@ -301,8 +304,8 @@ online_resources = self.caps_map[roster_jid] except KeyError: continue - for res, hash_ in online_resources.iteritems(): - notify = self.hash_map[hash_]['notify'] + for res, disco_tuple in online_resources.iteritems(): + notify = self.hash_map[disco_tuple]['notify'] if nodeIdentifier in notify: full_jid = jid.JID(tuple=(roster_jid.user, roster_jid.host, res)) auto_subscribers.append(full_jid)