# Path: wokkel/component.py
# NS_COMPONENT_ACCEPT = 'jabber:component:accept'
# class Component(StreamManager, service.Service):
# class InternalComponent(xmlstream.XMPPHandlerCollection, service.Service):
# class ListenComponentAuthenticator(xmlstream.ListenAuthenticator):
# class Router(object):
# class XMPPComponentServerFactory(xmlstream.XmlStreamServerFactory):
#     def __init__(self, host, port, jid, password):
#     def _authd(self, xs):
#         def send(obj):
#     def initializationFailed(self, reason):
#     def startService(self):
#     def stopService(self):
#     def _getConnection(self):
#     def __init__(self, router, domain=None):
#     def startService(self):
#     def stopService(self):
#     def addHandler(self, handler):
#     def send(self, obj):
#     def __init__(self, secret):
#     def associateWithStream(self, xs):
#     def streamStarted(self, rootElement):
#     def onElement(self, element):
#     def onHandshake(self, handshake):
#     def __init__(self):
#     def addRoute(self, destination, xs):
#     def removeRoute(self, destination, xs):
#     def route(self, stanza):
#     def __init__(self, router, secret='secret'):
#         def authenticatorFactory():
#     def makeConnection(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
#     def connectionInitialized(self, xs):
#     def onError(self, reason):
#     def connectionLost(self, destination, xs, reason):
# 
# Path: wokkel/server.py
# NS_DIALBACK = 'jabber:server:dialback'
# def generateKey(secret, receivingServer, originatingServer, streamID):
# def trapStreamError(xs, observer):
#     def wrappedObserver(element):
#     def __init__(self, reactor, domain, factory):
#     def pickServer(self):
#     def __init__(self, xs, thisHost, otherHost, secret):
#     def initialize(self):
#     def onResult(self, result):
#     def onStreamError(self, failure):
#     def __init__(self, xs, thisHost, otherHost, originalStreamID, key):
#     def initialize(self):
#     def onVerify(self, verify):
#     def onStreamError(self, failure):
#     def __init__(self, thisHost, otherHost, secret):
#     def connectionMade(self):
#     def associateWithStream(self, xs):
#     def __init__(self, thisHost, otherHost, originalStreamID, key):
#     def connectionMade(self):
#     def associateWithStream(self, xs):
#     def __init__(self, service):
#     def streamStarted(self, rootElement):
#         def prepareStream(domain):
#     def onVerify(self, verify):
#     def onResult(self, result):
#         def reply(validity):
#         def valid(xs):
#         def invalid(failure):
#     def __init__(self, authenticator):
#     def onConnectionMade(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
# def initiateS2S(factory):
#     def __init__(self, service):
#         def authenticatorFactory():
#     def onConnectionMade(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
#     def onAuthenticated(self, xs):
#     def onConnectionLost(self, xs, reason):
#     def onError(self, reason):
#     def onElement(self, xs, element):
#     def __init__(self, router, domain=None, secret=None):
#     def outgoingInitialized(self, xs):
#     def outgoingDisconnected(self, xs):
#     def initiateOutgoingStream(self, thisHost, otherHost):
#         def resetConnecting(_):
#     def validateConnection(self, thisHost, otherHost, sid, key):
#         def connected(xs):
#             def disconnect(_):
#     def send(self, stanza):
#     def dispatch(self, xs, stanza):
# class XMPPServerConnector(SRVConnector):
# class DialbackFailed(Exception):
# class OriginatingDialbackInitializer(object):
# class ReceivingDialbackInitializer(object):
# class XMPPServerConnectAuthenticator(xmlstream.ConnectAuthenticator):
# class XMPPServerVerifyAuthenticator(xmlstream.ConnectAuthenticator):
# class XMPPServerListenAuthenticator(xmlstream.ListenAuthenticator):
# class DeferredS2SClientFactory(DeferredXmlStreamFactory):
# class XMPPS2SServerFactory(xmlstream.XmlStreamServerFactory):
# class ServerService(object):


from twisted.internet import defer
from twisted.python import failure
from twisted.test.proto_helpers import StringTransport
from twisted.trial import unittest
from twisted.words.protocols.jabber import error, jid, xmlstream
from twisted.words.xish import domish
from wokkel import component, server
    def test_Element(self):
        self.xmlstream.makeConnection(self.transport)
        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)

        stanza = domish.Element((None, "presence"))
        self.xmlstream.dispatch(stanza)
        self.assertEqual(1, len(self.service.dispatched))
        self.assertIdentical(stanza, self.service.dispatched[-1])


    def test_ElementNotAuthenticated(self):
        self.xmlstream.makeConnection(self.transport)

        stanza = domish.Element((None, "presence"))
        self.xmlstream.dispatch(stanza)
        self.assertEqual(0, len(self.service.dispatched))



class ServerServiceTest(unittest.TestCase):

    def setUp(self):
        self.output = []

        self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
        self.xmlstream.thisEntity = jid.JID('example.org')
        self.xmlstream.otherEntity = jid.JID('example.com')
        self.xmlstream.send = self.output.append

        self.router = component.Router()

# Path: wokkel/component.py
# NS_COMPONENT_ACCEPT = 'jabber:component:accept'
# class Component(StreamManager, service.Service):
# class InternalComponent(xmlstream.XMPPHandlerCollection, service.Service):
# class ListenComponentAuthenticator(xmlstream.ListenAuthenticator):
# class Router(object):
# class XMPPComponentServerFactory(xmlstream.XmlStreamServerFactory):
#     def __init__(self, host, port, jid, password):
#     def _authd(self, xs):
#         def send(obj):
#     def initializationFailed(self, reason):
#     def startService(self):
#     def stopService(self):
#     def _getConnection(self):
#     def __init__(self, router, domain=None):
#     def startService(self):
#     def stopService(self):
#     def addHandler(self, handler):
#     def send(self, obj):
#     def __init__(self, secret):
#     def associateWithStream(self, xs):
#     def streamStarted(self, rootElement):
#     def onElement(self, element):
#     def onHandshake(self, handshake):
#     def __init__(self):
#     def addRoute(self, destination, xs):
#     def removeRoute(self, destination, xs):
#     def route(self, stanza):
#     def __init__(self, router, secret='secret'):
#         def authenticatorFactory():
#     def makeConnection(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
#     def connectionInitialized(self, xs):
#     def onError(self, reason):
#     def connectionLost(self, destination, xs, reason):
# 
# Path: wokkel/server.py
# NS_DIALBACK = 'jabber:server:dialback'
# def generateKey(secret, receivingServer, originatingServer, streamID):
# def trapStreamError(xs, observer):
#     def wrappedObserver(element):
#     def __init__(self, reactor, domain, factory):
#     def pickServer(self):
#     def __init__(self, xs, thisHost, otherHost, secret):
#     def initialize(self):
#     def onResult(self, result):
#     def onStreamError(self, failure):
#     def __init__(self, xs, thisHost, otherHost, originalStreamID, key):
#     def initialize(self):
#     def onVerify(self, verify):
#     def onStreamError(self, failure):
#     def __init__(self, thisHost, otherHost, secret):
#     def connectionMade(self):
#     def associateWithStream(self, xs):
#     def __init__(self, thisHost, otherHost, originalStreamID, key):
#     def connectionMade(self):
#     def associateWithStream(self, xs):
#     def __init__(self, service):
#     def streamStarted(self, rootElement):
#         def prepareStream(domain):
#     def onVerify(self, verify):
#     def onResult(self, result):
#         def reply(validity):
#         def valid(xs):
#         def invalid(failure):
#     def __init__(self, authenticator):
#     def onConnectionMade(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
# def initiateS2S(factory):
#     def __init__(self, service):
#         def authenticatorFactory():
#     def onConnectionMade(self, xs):
#         def logDataIn(buf):
#         def logDataOut(buf):
#     def onAuthenticated(self, xs):
#     def onConnectionLost(self, xs, reason):
#     def onError(self, reason):
#     def onElement(self, xs, element):
#     def __init__(self, router, domain=None, secret=None):
#     def outgoingInitialized(self, xs):
#     def outgoingDisconnected(self, xs):
#     def initiateOutgoingStream(self, thisHost, otherHost):
#         def resetConnecting(_):
#     def validateConnection(self, thisHost, otherHost, sid, key):
#         def connected(xs):
#             def disconnect(_):
#     def send(self, stanza):
#     def dispatch(self, xs, stanza):
# class XMPPServerConnector(SRVConnector):
# class DialbackFailed(Exception):
# class OriginatingDialbackInitializer(object):
# class ReceivingDialbackInitializer(object):
# class XMPPServerConnectAuthenticator(xmlstream.ConnectAuthenticator):
# class XMPPServerVerifyAuthenticator(xmlstream.ConnectAuthenticator):
# class XMPPServerListenAuthenticator(xmlstream.ListenAuthenticator):
# class DeferredS2SClientFactory(DeferredXmlStreamFactory):
# class XMPPS2SServerFactory(xmlstream.XmlStreamServerFactory):
# class ServerService(object):


# Path: wokkel/test/test_server.py
from twisted.internet import defer
from twisted.python import failure
from twisted.test.proto_helpers import StringTransport
from twisted.trial import unittest
from twisted.words.protocols.jabber import error, jid, xmlstream
from twisted.words.xish import domish
from wokkel import component, server

    def test_Element(self):
        self.xmlstream.makeConnection(self.transport)
        self.xmlstream.dispatch(self.xmlstream, xmlstream.STREAM_AUTHD_EVENT)

        stanza = domish.Element((None, "presence"))
        self.xmlstream.dispatch(stanza)
        self.assertEqual(1, len(self.service.dispatched))
        self.assertIdentical(stanza, self.service.dispatched[-1])


    def test_ElementNotAuthenticated(self):
        self.xmlstream.makeConnection(self.transport)

        stanza = domish.Element((None, "presence"))
        self.xmlstream.dispatch(stanza)
        self.assertEqual(0, len(self.service.dispatched))



class ServerServiceTest(unittest.TestCase):

    def setUp(self):
        self.output = []

        self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
        self.xmlstream.thisEntity = jid.JID('example.org')
        self.xmlstream.otherEntity = jid.JID('example.com')
        self.xmlstream.send = self.output.append

        self.router = component.Router()

        self.service = server.ServerService(self.router,