2020-05-24 13:00:20 +00:00
|
|
|
import unittest
|
|
|
|
from slixmpp import Iq
|
|
|
|
from slixmpp.test import SlixTest
|
|
|
|
import slixmpp.plugins.xep_0191 as xep_0191
|
|
|
|
import slixmpp.plugins.xep_0377 as xep_0377
|
|
|
|
from slixmpp.xmlstream import register_stanza_plugin
|
|
|
|
|
|
|
|
|
|
|
|
class TestSpamReporting(SlixTest):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
register_stanza_plugin(Iq, xep_0191.Block)
|
|
|
|
register_stanza_plugin(
|
|
|
|
xep_0191.Block,
|
|
|
|
xep_0377.Report,
|
|
|
|
)
|
|
|
|
register_stanza_plugin(
|
|
|
|
xep_0377.Report,
|
|
|
|
xep_0377.Text,
|
|
|
|
)
|
|
|
|
|
|
|
|
def testCreateReport(self):
|
|
|
|
report = """
|
|
|
|
<iq type="set">
|
|
|
|
<block xmlns="urn:xmpp:blocking">
|
2023-04-04 10:07:56 +00:00
|
|
|
<report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:spam"/>
|
2020-05-24 13:00:20 +00:00
|
|
|
</block>
|
|
|
|
</iq>
|
|
|
|
"""
|
|
|
|
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['type'] = 'set'
|
2023-04-04 10:07:56 +00:00
|
|
|
iq['block']['report']['reason'] = xep_0377.XEP_0377.SPAM
|
2020-05-24 13:00:20 +00:00
|
|
|
|
2023-04-04 10:07:56 +00:00
|
|
|
self.check(iq, report, use_values=False)
|
2020-05-24 13:00:20 +00:00
|
|
|
|
|
|
|
def testEnforceOnlyOneSubElement(self):
|
|
|
|
report = """
|
|
|
|
<iq type="set">
|
|
|
|
<block xmlns="urn:xmpp:blocking">
|
2023-04-04 10:07:56 +00:00
|
|
|
<report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:abuse"/>
|
2020-05-24 13:00:20 +00:00
|
|
|
</block>
|
|
|
|
</iq>
|
|
|
|
"""
|
|
|
|
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['type'] = 'set'
|
2023-04-04 10:07:56 +00:00
|
|
|
iq['block']['report']['reason'] = xep_0377.XEP_0377.SPAM
|
|
|
|
iq['block']['report']['reason'] = xep_0377.XEP_0377.ABUSE
|
|
|
|
self.check(iq, report, use_values=False)
|
2020-05-24 13:00:20 +00:00
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestSpamReporting)
|