Changeset 9:7f5cf72c97fc in ralphm-patches


Ignore:
Timestamp:
Apr 9, 2009, 1:36:50 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Save recent work.

Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • s2s.patch

    r7 r9  
    1 diff -r 842c0a2f8fa1 wokkel/server.py
     1diff -r 313d45b505a7 wokkel/server.py
    22--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    3 +++ b/wokkel/server.py  Tue Apr 07 09:17:35 2009 +0200
    4 @@ -0,0 +1,684 @@
     3+++ b/wokkel/server.py  Thu Apr 09 12:03:24 2009 +0200
     4@@ -0,0 +1,700 @@
    55+# -*- test-case-name: wokkel.test.test_server -*-
    66+#
     
    443443+    """
    444444+
     445+    logTraffic = False
     446+
    445447+    def __init__(self, authenticator):
    446448+        DeferredXmlStreamFactory.__init__(self, authenticator)
     
    546548+
    547549+
    548 +    def onElement(self, element, xs):
     550+    def onElement(self, xs, element):
    549551+        """
    550552+        Called when an element was received from one of the connected streams.
     
    553555+        if element.handled:
    554556+            return
    555 +
    556 +        if jid.internJID(element["from"]).host != xs.otherEntity.host:
    557 +            xs.sendStreamError(error.StreamError('invalid-from'))
    558557+        else:
    559 +            self.service.dispatch(element)
     558+            self.service.dispatch(xs, element)
    560559+
    561560+
     
    629628+        factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,
    630629+                             self.outgoingInitialized)
     630+        factory.logTraffic = self.logTraffic
    631631+
    632632+        self._outgoingConnecting.add((thisHost, otherHost))
     
    653653+        factory = DeferredS2SClientFactory(authenticator)
    654654+        factory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, connected)
     655+        factory.logTraffic = self.logTraffic
    655656+
    656657+        d = initiateS2S(factory)
     
    682683+
    683684+
    684 +    def dispatch(self, element):
     685+    def dispatch(self, xs, stanza):
    685686+        """
    686687+        Send on element to be routed within the server.
    687688+        """
    688 +        self.xmlstream.send(element)
    689 diff -r 842c0a2f8fa1 wokkel/test/test_server.py
     689+        stanzaFrom = stanza.getAttribute('from')
     690+        stanzaTo = stanza.getAttribute('to')
     691+
     692+        if not stanzaFrom or not stanzaTo:
     693+            xs.sendStreamError(error.StreamError('improper-addressing'))
     694+        else:
     695+            try:
     696+                sender = jid.internJID(stanzaFrom)
     697+                recipient = jid.internJID(stanzaTo)
     698+            except jid.InvalidFormat:
     699+                log.msg("Dropping error stanza with malformed JID")
     700+
     701+            if sender.host != xs.otherEntity.host:
     702+                xs.sendStreamError(error.StreamError('invalid-from'))
     703+            else:
     704+                self.xmlstream.send(stanza)
     705diff -r 313d45b505a7 wokkel/test/test_server.py
    690706--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    691 +++ b/wokkel/test/test_server.py        Tue Apr 07 09:17:35 2009 +0200
    692 @@ -0,0 +1,412 @@
     707+++ b/wokkel/test/test_server.py        Thu Apr 09 12:03:24 2009 +0200
     708@@ -0,0 +1,450 @@
    693709+# Copyright (c) 2003-2008 Ralph Meijer
    694710+# See LICENSE for details.
     
    10101026+        self.dispatched = []
    10111027+
    1012 +    def dispatch(self, element):
    1013 +        self.dispatch.append(element)
     1028+    def dispatch(self, xs, element):
     1029+        self.dispatched.append(element)
    10141030+
    10151031+
     
    10211037+
    10221038+    def setUp(self):
    1023 +        self.service = FakeService
     1039+        self.service = FakeService()
    10241040+        self.factory = server.XMPPS2SServerFactory(self.service)
    10251041+        self.xmlstream = self.factory.buildProtocol(None)
     1042+        self.transport = StringTransport()
    10261043+        self.xmlstream.thisEntity = jid.JID('example.org')
    10271044+        self.xmlstream.otherEntity = jid.JID('example.com')
     
    10321049+        A new connection increases the stream serial count. No logs by default.
    10331050+        """
    1034 +        self.xmlstream.dispatch(self.xmlstream,
    1035 +                                xmlstream.STREAM_CONNECTED_EVENT)
     1051+        self.xmlstream.makeConnection(self.transport)
    10361052+        self.assertEqual(0, self.xmlstream.serial)
    10371053+        self.assertEqual(1, self.factory.serial)
     
    10451061+        """
    10461062+        self.factory.logTraffic = True
    1047 +        self.xmlstream.dispatch(self.xmlstream,
    1048 +                                xmlstream.STREAM_CONNECTED_EVENT)
     1063+        self.xmlstream.makeConnection(self.transport)
    10491064+        self.assertNotIdentical(None, self.xmlstream.rawDataInFn)
    10501065+        self.assertNotIdentical(None, self.xmlstream.rawDataOutFn)
     
    10551070+        An observer for stream errors should trigger onError to log it.
    10561071+        """
    1057 +        self.xmlstream.dispatch(self.xmlstream,
    1058 +                                xmlstream.STREAM_CONNECTED_EVENT)
     1072+        self.xmlstream.makeConnection(self.transport)
    10591073+
    10601074+        class TestError(Exception):
     
    10691083+        """
    10701084+        """
    1071 +        self.xmlstream.dispatch(self.xmlstream,
    1072 +                                xmlstream.STREAM_CONNECTED_EVENT)
     1085+        self.xmlstream.makeConnection(self.transport)
    10731086+        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)
    10741087+
     
    10771090+        """
    10781091+        """
    1079 +        self.xmlstream.dispatch(self.xmlstream,
    1080 +                                xmlstream.STREAM_CONNECTED_EVENT)
     1092+        self.xmlstream.makeConnection(self.transport)
    10811093+        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)
    10821094+        self.xmlstream.dispatch(None, xmlstream.STREAM_END_EVENT)
    10831095+
    10841096+
     1097+    def test_Element(self):
     1098+        self.xmlstream.makeConnection(self.transport)
     1099+        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)
     1100+
     1101+        stanza = domish.Element((None, "presence"))
     1102+        self.xmlstream.dispatch(stanza)
     1103+        self.assertEqual(1, len(self.service.dispatched))
     1104+        self.assertIdentical(stanza, self.service.dispatched[-1])
     1105+
     1106+
    10851107+    def test_ElementNotAuthenticated(self):
    1086 +        self.xmlstream.dispatch(self.xmlstream,
    1087 +                                xmlstream.STREAM_CONNECTED_EVENT)
    1088 +        self.xmlstream.dataReceived("<presence/>")
     1108+        self.xmlstream.makeConnection(self.transport)
     1109+
     1110+        stanza = domish.Element((None, "presence"))
     1111+        self.xmlstream.dispatch(stanza)
     1112+        self.assertEqual(0, len(self.service.dispatched))
     1113+
    10891114+
    10901115+
     
    10921117+
    10931118+    def setUp(self):
     1119+        self.output = []
     1120+
     1121+        self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
     1122+        self.xmlstream.thisEntity = jid.JID('example.org')
     1123+        self.xmlstream.otherEntity = jid.JID('example.com')
     1124+        self.xmlstream.send = self.output.append
     1125+
    10941126+        self.router = component.Router()
    10951127+        self.service = server.ServerService(self.router,
    10961128+                                            secret='mysecret',
    10971129+                                            domain='example.org')
     1130+        self.service.xmlstream = self.xmlstream
    10981131+
    10991132+
     
    11031136+        """
    11041137+        self.assertIn(self.service.defaultDomain, self.service.domains)
     1138+
     1139+
     1140+    def test_dispatch(self):
     1141+        stanza = domish.Element((None, "presence"))
     1142+        stanza['to'] = 'user@example.org'
     1143+        stanza['from'] = 'other@example.com'
     1144+        self.service.dispatch(self.xmlstream, stanza)
     1145+
     1146+        self.assertEqual(1, len(self.output))
     1147+        self.assertIdentical(stanza, self.output[-1])
     1148+
     1149+
     1150+    def test_dispatchNoTo(self):
     1151+        errors = []
     1152+        self.xmlstream.sendStreamError = errors.append
     1153+
     1154+        stanza = domish.Element((None, "presence"))
     1155+        stanza['from'] = 'other@example.com'
     1156+        self.service.dispatch(self.xmlstream, stanza)
     1157+
     1158+        self.assertEqual(1, len(errors))
  • series

    r8 r9  
    1 compat-pre-twisted-8.0.0.patch
    2 release-0.5.patch
    31component_multiple.patch
    42deferred_xmlstream_factory.patch
Note: See TracChangeset for help on using the changeset viewer.