Changeset 9:7f5cf72c97fc in ralphm-patches
- Timestamp:
- Apr 9, 2009, 1:36:50 PM (13 years ago)
- Branch:
- default
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
s2s.patch
r7 r9 1 diff -r 842c0a2f8fa1wokkel/server.py1 diff -r 313d45b505a7 wokkel/server.py 2 2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3 +++ b/wokkel/server.py T ue Apr 07 09:17:352009 +02004 @@ -0,0 +1, 684@@3 +++ b/wokkel/server.py Thu Apr 09 12:03:24 2009 +0200 4 @@ -0,0 +1,700 @@ 5 5 +# -*- test-case-name: wokkel.test.test_server -*- 6 6 +# … … 443 443 + """ 444 444 + 445 + logTraffic = False 446 + 445 447 + def __init__(self, authenticator): 446 448 + DeferredXmlStreamFactory.__init__(self, authenticator) … … 546 548 + 547 549 + 548 + def onElement(self, element, xs):550 + def onElement(self, xs, element): 549 551 + """ 550 552 + Called when an element was received from one of the connected streams. … … 553 555 + if element.handled: 554 556 + return 555 +556 + if jid.internJID(element["from"]).host != xs.otherEntity.host:557 + xs.sendStreamError(error.StreamError('invalid-from'))558 557 + else: 559 + self.service.dispatch( element)558 + self.service.dispatch(xs, element) 560 559 + 561 560 + … … 629 628 + factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, 630 629 + self.outgoingInitialized) 630 + factory.logTraffic = self.logTraffic 631 631 + 632 632 + self._outgoingConnecting.add((thisHost, otherHost)) … … 653 653 + factory = DeferredS2SClientFactory(authenticator) 654 654 + factory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, connected) 655 + factory.logTraffic = self.logTraffic 655 656 + 656 657 + d = initiateS2S(factory) … … 682 683 + 683 684 + 684 + def dispatch(self, element):685 + def dispatch(self, xs, stanza): 685 686 + """ 686 687 + Send on element to be routed within the server. 687 688 + """ 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) 705 diff -r 313d45b505a7 wokkel/test/test_server.py 690 706 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 691 +++ b/wokkel/test/test_server.py T ue Apr 07 09:17:352009 +0200692 @@ -0,0 +1,4 12@@707 +++ b/wokkel/test/test_server.py Thu Apr 09 12:03:24 2009 +0200 708 @@ -0,0 +1,450 @@ 693 709 +# Copyright (c) 2003-2008 Ralph Meijer 694 710 +# See LICENSE for details. … … 1010 1026 + self.dispatched = [] 1011 1027 + 1012 + def dispatch(self, element):1013 + self.dispatch .append(element)1028 + def dispatch(self, xs, element): 1029 + self.dispatched.append(element) 1014 1030 + 1015 1031 + … … 1021 1037 + 1022 1038 + def setUp(self): 1023 + self.service = FakeService 1039 + self.service = FakeService() 1024 1040 + self.factory = server.XMPPS2SServerFactory(self.service) 1025 1041 + self.xmlstream = self.factory.buildProtocol(None) 1042 + self.transport = StringTransport() 1026 1043 + self.xmlstream.thisEntity = jid.JID('example.org') 1027 1044 + self.xmlstream.otherEntity = jid.JID('example.com') … … 1032 1049 + A new connection increases the stream serial count. No logs by default. 1033 1050 + """ 1034 + self.xmlstream.dispatch(self.xmlstream, 1035 + xmlstream.STREAM_CONNECTED_EVENT) 1051 + self.xmlstream.makeConnection(self.transport) 1036 1052 + self.assertEqual(0, self.xmlstream.serial) 1037 1053 + self.assertEqual(1, self.factory.serial) … … 1045 1061 + """ 1046 1062 + self.factory.logTraffic = True 1047 + self.xmlstream.dispatch(self.xmlstream, 1048 + xmlstream.STREAM_CONNECTED_EVENT) 1063 + self.xmlstream.makeConnection(self.transport) 1049 1064 + self.assertNotIdentical(None, self.xmlstream.rawDataInFn) 1050 1065 + self.assertNotIdentical(None, self.xmlstream.rawDataOutFn) … … 1055 1070 + An observer for stream errors should trigger onError to log it. 1056 1071 + """ 1057 + self.xmlstream.dispatch(self.xmlstream, 1058 + xmlstream.STREAM_CONNECTED_EVENT) 1072 + self.xmlstream.makeConnection(self.transport) 1059 1073 + 1060 1074 + class TestError(Exception): … … 1069 1083 + """ 1070 1084 + """ 1071 + self.xmlstream.dispatch(self.xmlstream, 1072 + xmlstream.STREAM_CONNECTED_EVENT) 1085 + self.xmlstream.makeConnection(self.transport) 1073 1086 + self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT) 1074 1087 + … … 1077 1090 + """ 1078 1091 + """ 1079 + self.xmlstream.dispatch(self.xmlstream, 1080 + xmlstream.STREAM_CONNECTED_EVENT) 1092 + self.xmlstream.makeConnection(self.transport) 1081 1093 + self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT) 1082 1094 + self.xmlstream.dispatch(None, xmlstream.STREAM_END_EVENT) 1083 1095 + 1084 1096 + 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 + 1085 1107 + 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 + 1089 1114 + 1090 1115 + … … 1092 1117 + 1093 1118 + 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 + 1094 1126 + self.router = component.Router() 1095 1127 + self.service = server.ServerService(self.router, 1096 1128 + secret='mysecret', 1097 1129 + domain='example.org') 1130 + self.service.xmlstream = self.xmlstream 1098 1131 + 1099 1132 + … … 1103 1136 + """ 1104 1137 + 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.patch2 release-0.5.patch3 1 component_multiple.patch 4 2 deferred_xmlstream_factory.patch
Note: See TracChangeset
for help on using the changeset viewer.