Merge branch 'component-errors' into 'master'
Fix error namespace for components Closes #3476 and #3474 See merge request poezio/slixmpp!237
This commit is contained in:
commit
2080d08d63
@ -9,13 +9,14 @@
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
from slixmpp import Message, Iq, Presence
|
||||
from slixmpp.basexmpp import BaseXMPP
|
||||
from slixmpp.stanza import Handshake
|
||||
from slixmpp.stanza.error import Error
|
||||
from slixmpp.xmlstream import XMLStream
|
||||
from slixmpp.xmlstream import ET
|
||||
from slixmpp.xmlstream.matcher import MatchXPath
|
||||
from slixmpp.xmlstream.handler import Callback
|
||||
|
||||
from slixmpp.xmlstream.stanzabase import register_stanza_plugin
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -39,9 +40,17 @@ class ComponentXMPP(BaseXMPP):
|
||||
should be used instead of the standard
|
||||
``'jabber:component:accept'`` namespace.
|
||||
Defaults to ``False``.
|
||||
:param fix_error_ns: Fix the namespace of error stanzas.
|
||||
If you use ``use_jc_ns`` namespace, you probably want that, but
|
||||
it can be a problem if you use both a ClientXMPP and a ComponentXMPP
|
||||
in the same interpreter. This is ``False`` by default for backwards
|
||||
compatibility.
|
||||
"""
|
||||
|
||||
def __init__(self, jid, secret, host=None, port=None, plugin_config=None, plugin_whitelist=None, use_jc_ns=False):
|
||||
def __init__(self, jid, secret,
|
||||
host=None, port=None, plugin_config=None,
|
||||
plugin_whitelist=None, use_jc_ns=False,
|
||||
fix_error_ns=False):
|
||||
|
||||
if not plugin_whitelist:
|
||||
plugin_whitelist = []
|
||||
@ -52,6 +61,8 @@ class ComponentXMPP(BaseXMPP):
|
||||
default_ns = 'jabber:client'
|
||||
else:
|
||||
default_ns = 'jabber:component:accept'
|
||||
if fix_error_ns:
|
||||
self._fix_error_ns()
|
||||
BaseXMPP.__init__(self, jid, default_ns)
|
||||
|
||||
self.auto_authorize = None
|
||||
@ -77,6 +88,11 @@ class ComponentXMPP(BaseXMPP):
|
||||
self.add_event_handler('presence_probe',
|
||||
self._handle_probe)
|
||||
|
||||
def _fix_error_ns(self):
|
||||
Error.namespace = self.default_ns
|
||||
for st in Message, Iq, Presence:
|
||||
register_stanza_plugin(st, Error)
|
||||
|
||||
def connect(self, host=None, port=None, use_ssl=False):
|
||||
"""Connect to the server.
|
||||
|
||||
|
@ -10,11 +10,13 @@ from xml.parsers.expat import ExpatError
|
||||
from slixmpp.test import TestTransport
|
||||
from slixmpp import ClientXMPP, ComponentXMPP
|
||||
from slixmpp.stanza import Message, Iq, Presence
|
||||
from slixmpp.stanza.error import Error
|
||||
from slixmpp.xmlstream import ET
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
from slixmpp.xmlstream.tostring import tostring, highlight
|
||||
from slixmpp.xmlstream.matcher import StanzaPath, MatcherId, MatchIDSender
|
||||
from slixmpp.xmlstream.matcher import MatchXMLMask, MatchXPath
|
||||
from slixmpp.xmlstream.stanzabase import register_stanza_plugin
|
||||
|
||||
import asyncio
|
||||
|
||||
@ -322,6 +324,7 @@ class SlixTest(unittest.TestCase):
|
||||
if not plugin_config:
|
||||
plugin_config = {}
|
||||
|
||||
self.mode = mode
|
||||
if mode == 'client':
|
||||
self.xmpp = ClientXMPP(jid, password,
|
||||
sasl_mech=sasl_mech,
|
||||
@ -740,3 +743,10 @@ class SlixTest(unittest.TestCase):
|
||||
|
||||
# Everything matches
|
||||
return True
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
if getattr(self, "mode", None) == "component":
|
||||
Error.namespace = 'jabber:client'
|
||||
for st in Message, Iq, Presence:
|
||||
register_stanza_plugin(st, Error)
|
||||
|
@ -8,9 +8,6 @@ class TestLiveStream(SlixTest):
|
||||
Test that we can test a live stanza stream.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testClientConnection(self):
|
||||
"""Test that we can interact with a live ClientXMPP instance."""
|
||||
self.stream_start(mode='client',
|
||||
|
@ -8,9 +8,6 @@ class TestEvents(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testEventHappening(self):
|
||||
"""Test handler working"""
|
||||
happened = []
|
||||
|
@ -5,10 +5,6 @@ from slixmpp.xmlstream.stanzabase import ET
|
||||
|
||||
class TestIqStanzas(SlixTest):
|
||||
|
||||
def tearDown(self):
|
||||
"""Shutdown the XML stream after testing."""
|
||||
self.stream_close()
|
||||
|
||||
def testSetup(self):
|
||||
"""Test initializing default Iq values."""
|
||||
iq = self.Iq()
|
||||
|
@ -8,9 +8,6 @@ class TestStreamTester(SlixTest):
|
||||
Test that we can simulate and test a stanza stream.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testClientEcho(self):
|
||||
"""Test that we can interact with a ClientXMPP instance."""
|
||||
self.stream_start(mode='client')
|
||||
|
@ -10,9 +10,6 @@ class TestStreamExceptions(SlixTest):
|
||||
Test handling roster updates.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testExceptionContinueWorking(self):
|
||||
"""Test that Slixmpp continues to respond after an XMPPError is raised."""
|
||||
|
||||
|
@ -14,9 +14,6 @@ class TestFilters(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testIncoming(self):
|
||||
|
||||
data = []
|
||||
|
@ -15,9 +15,6 @@ class TestHandlers(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testCallback(self):
|
||||
"""Test using stream callback handlers."""
|
||||
|
||||
|
@ -11,9 +11,6 @@ class TestStreamPresence(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start(jid='tester@localhost', plugins=[])
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testInitialUnavailablePresences(self):
|
||||
"""
|
||||
Test receiving unavailable presences from JIDs that
|
||||
|
@ -13,9 +13,6 @@ class TestStreamRoster(SlixTest):
|
||||
Test handling roster updates.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testGetRoster(self):
|
||||
"""Test handling roster requests."""
|
||||
self.stream_start(mode='client', jid='tester@localhost')
|
||||
|
@ -11,9 +11,6 @@ class TestStreamDisco(SlixTest):
|
||||
Test using the XEP-0030 plugin.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testInfoEmptyDefaultNode(self):
|
||||
"""
|
||||
Info query result from an entity MUST have at least one identity
|
||||
|
@ -11,9 +11,6 @@ class TestInBandByteStreams(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start(plugins=['xep_0047', 'xep_0030'])
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testOpenStream(self):
|
||||
"""Test requesting a stream, successfully"""
|
||||
|
||||
|
@ -16,9 +16,6 @@ class TestAdHocCommands(SlixTest):
|
||||
# a dummy value.
|
||||
self.xmpp['xep_0050'].new_session = lambda: '_sessionid_'
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testInitialPayloadCommand(self):
|
||||
"""Test a command with an initial payload."""
|
||||
|
||||
|
@ -19,9 +19,6 @@ class TestJabberSearch(SlixTest):
|
||||
self.xmpp["xep_0055"].api.register(get_results, "search_query")
|
||||
self.xmpp["xep_0055"].api.register(get_results, "search_query")
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testRequestingSearchFields(self):
|
||||
self.recv(
|
||||
"""
|
||||
|
@ -15,9 +15,6 @@ class TestStreamPubsub(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testCreateInstantNode(self):
|
||||
"""Test creating an instant node"""
|
||||
self.xmpp['xep_0060'].create_node('pubsub.example.com', None)
|
||||
|
@ -6,9 +6,6 @@ from slixmpp.test import SlixTest
|
||||
|
||||
class TestOOB(SlixTest):
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testSendOOB(self):
|
||||
"""Test sending an OOB transfer request."""
|
||||
self.stream_start(plugins=['xep_0066', 'xep_0030'])
|
||||
|
@ -6,9 +6,6 @@ from slixmpp.test import SlixTest
|
||||
|
||||
class TestStreamChatStates(SlixTest):
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testChatStates(self):
|
||||
self.stream_start(mode='client', plugins=['xep_0030', 'xep_0085'])
|
||||
|
||||
|
@ -6,9 +6,6 @@ from slixmpp.test import SlixTest
|
||||
|
||||
class TestStreamSet(SlixTest):
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testHandleSoftwareVersionRequest(self):
|
||||
self.stream_start(mode='client', plugins=['xep_0030', 'xep_0092'])
|
||||
|
||||
|
@ -19,6 +19,7 @@ class TestStreamGateway(SlixTest):
|
||||
"xep_0100": {"component_name": "AIM Gateway", "type": "aim"}
|
||||
},
|
||||
)
|
||||
self.xmpp._fix_error_ns()
|
||||
|
||||
def next_sent(self):
|
||||
self.wait_for_send_queue()
|
||||
@ -160,7 +161,6 @@ class TestStreamGateway(SlixTest):
|
||||
</iq>
|
||||
"""
|
||||
)
|
||||
# xmlns="jabber:client" in error substanza, bug in XEP-0077 plugin or OK?
|
||||
self.send(
|
||||
"""
|
||||
<iq type='error'
|
||||
@ -171,7 +171,7 @@ class TestStreamGateway(SlixTest):
|
||||
<username>RomeoMyRomeo</username>
|
||||
<password>ILoveJuliet</password>
|
||||
</query>
|
||||
<error code='406' type='modify' xmlns="jabber:client">
|
||||
<error code='406' type='modify'>
|
||||
<not-acceptable
|
||||
xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
||||
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Not good</text>
|
||||
|
@ -8,9 +8,6 @@ class TestStreamExtendedDisco(SlixTest):
|
||||
Test using the XEP-0128 plugin.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testUsingExtendedInfo(self):
|
||||
self.stream_start(mode='client',
|
||||
jid='tester@localhost',
|
||||
|
@ -10,9 +10,6 @@ class TestStreamDirectInvite(SlixTest):
|
||||
Test using the XEP-0249 plugin.
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testReceiveInvite(self):
|
||||
self.stream_start(mode='client',
|
||||
plugins=['xep_0030',
|
||||
|
@ -9,9 +9,6 @@ class TestMAM(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start(plugins=['xep_0313'])
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testRetrieveSimple(self):
|
||||
"""Test requesting MAM messages without RSM"""
|
||||
|
||||
|
@ -24,9 +24,6 @@ class TestStreamSensorData(SlixTest):
|
||||
def _time_now(self):
|
||||
return datetime.datetime.now().replace(microsecond=0).isoformat()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testRequestAccept(self):
|
||||
self.stream_start(mode='component',
|
||||
plugins=['xep_0030',
|
||||
|
@ -30,9 +30,6 @@ class TestStreamControl(SlixTest):
|
||||
def _time_now(self):
|
||||
return datetime.datetime.now().replace(microsecond=0).isoformat()
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testRequestSetOk(self):
|
||||
self.stream_start(mode='component',
|
||||
plugins=['xep_0030',
|
||||
|
@ -14,9 +14,6 @@ class TestSIMS(SlixTest):
|
||||
mode="component", jid="whatevs.shakespeare.lit", plugins={"xep_0385"}
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def test_set_file(self):
|
||||
with NamedTemporaryFile("wb+") as f:
|
||||
n = 10
|
||||
|
@ -8,9 +8,6 @@ class TestMIXPAM(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start(plugins=['xep_0405'])
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testGetRosterEmpty(self):
|
||||
"""Test requesting an empty annotated roster"""
|
||||
|
||||
|
@ -15,8 +15,6 @@ class TestStatelessFileSharing(SlixTest):
|
||||
mode="component", jid="whatevs.shakespeare.lit", plugins={"xep_0447"}
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def test_set_file(self):
|
||||
with NamedTemporaryFile("wb+") as f:
|
||||
|
@ -7,9 +7,6 @@ class TestReply(SlixTest):
|
||||
def setUp(self):
|
||||
self.stream_start(plugins=["xep_0461"])
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def testFallBackBody(self):
|
||||
async def on_reply(msg):
|
||||
start = msg["feature_fallback"]["fallback_body"]["start"]
|
||||
|
@ -10,9 +10,6 @@ class TestToString(SlixTest):
|
||||
Test the implementation of slixmpp.xmlstream.tostring
|
||||
"""
|
||||
|
||||
def tearDown(self):
|
||||
self.stream_close()
|
||||
|
||||
def tryTostring(self, original='', expected=None, message='', **kwargs):
|
||||
"""
|
||||
Compare the result of calling tostring against an
|
||||
|
Loading…
Reference in New Issue
Block a user