Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nbxmpp/modules/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _process_pubsub_activity(
return

activity_node = item.getTag("activity", namespace=Namespace.ACTIVITY)
if not activity_node.getChildren():
if activity_node is None or not activity_node.getChildren():
self._log.info("Received activity: %s - no activity set", properties.jid)
return

Expand Down
2 changes: 1 addition & 1 deletion nbxmpp/modules/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _process_pubsub_location(
return

location_node = item.getTag("geoloc", namespace=Namespace.LOCATION)
if not location_node.getChildren():
if location_node is None or not location_node.getChildren():
self._log.info("Received location: %s - no location set", properties.jid)
return

Expand Down
2 changes: 1 addition & 1 deletion nbxmpp/modules/mood.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _process_pubsub_mood(
return

mood_node = item.getTag("mood", namespace=Namespace.MOOD)
if not mood_node.getChildren():
if mood_node is None or not mood_node.getChildren():
self._log.info("Received mood: %s - removed mood", properties.jid)
return

Expand Down
2 changes: 1 addition & 1 deletion nbxmpp/modules/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _process_pubsub_tune(
return

tune_node = item.getTag("tune", namespace=Namespace.TUNE)
if not tune_node.getChildren():
if tune_node is None or not tune_node.getChildren():
self._log.info("Received tune: %s - no tune set", properties.jid)
return

Expand Down
15 changes: 15 additions & 0 deletions test/unit/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ def _on_message(_con, _stanza, properties):
)

self.dispatcher.process_data(event)

def test_activity_item_without_payload(self):
# An item published without an <activity/> payload must not crash the handler.
event = """
<message from='test@test.test'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='http://jabber.org/protocol/activity'>
<item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'/>
</items>
</event>
</message>
"""

with self.assertNoLogs("nbxmpp", level="ERROR"):
self.dispatcher.process_data(event)
15 changes: 15 additions & 0 deletions test/unit/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,18 @@ def _on_message(_con, _stanza, properties):
)

self.dispatcher.process_data(event)

def test_location_item_without_payload(self):
# An item published without a <geoloc/> payload must not crash the handler.
event = """
<message from='test@test.test'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='http://jabber.org/protocol/geoloc'>
<item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'/>
</items>
</event>
</message>
"""

with self.assertNoLogs("nbxmpp", level="ERROR"):
self.dispatcher.process_data(event)
15 changes: 15 additions & 0 deletions test/unit/test_mood.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ def _on_message(_con, _stanza, properties):
)

self.dispatcher.process_data(event)

def test_mood_item_without_payload(self):
# An item published without a <mood/> payload must not crash the handler.
event = """
<message from='test@test.test'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='http://jabber.org/protocol/mood'>
<item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'/>
</items>
</event>
</message>
"""

with self.assertNoLogs("nbxmpp", level="ERROR"):
self.dispatcher.process_data(event)
16 changes: 16 additions & 0 deletions test/unit/test_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ def _on_message(_con, _stanza, properties):
)

self.dispatcher.process_data(event)

def test_tune_item_without_payload(self):
# Some clients signal "stopped listening" with an empty <item/> instead
# of retracting it, so the <tune/> payload can be absent.
event = """
<message from='test@test.test'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='http://jabber.org/protocol/tune'>
<item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'/>
</items>
</event>
</message>
"""

with self.assertNoLogs("nbxmpp", level="ERROR"):
self.dispatcher.process_data(event)