def testBuffer(self):
     output = StringIOWithoutClosing()
     a = DummySMTP()
     a.makeConnection(protocol.FileWrapper(output))
     a.dataReceived(self.input)
     if a.messages != self.messages:
         raise AssertionError(a.messages)
     if output.getvalue() != self.expected_output:
         raise AssertionError(`output.getvalue()`)
 def testBuffer(self):
     for packet_size in range(1, 10):
         t = StringIOWithoutClosing()
         a = LineTester()
         a.makeConnection(protocol.FileWrapper(t))
         for i in range(len(self.buffer)/packet_size + 1):
             s = self.buffer[i*packet_size:(i+1)*packet_size]
             a.dataReceived(s)
         self.failUnlessEqual(self.output, a.received)
Exemple #3
0
def connectedServerAndClient():
    """Returns a 3-tuple: (client, server, pump)
    """
    c = pb.Broker()
    app = main.Application("pb-test")
    ident = passport.Identity("guest", app)
    ident.setPassword("guest")
    svc = DummyService("test", app)
    ident.addKeyForPerspective(svc.getPerspectiveNamed("any"))
    app.authorizer.addIdentity(ident)
    svr = pb.BrokerFactory(pb.AuthRoot(app))
    s = svr.buildProtocol(('127.0.0.1', ))
    s.copyTags = {}

    cio = StringIO()
    sio = StringIO()
    c.makeConnection(protocol.FileWrapper(cio))
    s.makeConnection(protocol.FileWrapper(sio))
    pump = IOPump(c, s, cio, sio)
    # Challenge-response authentication:
    while pump.pump():
        pass
    return c, s, pump
 def testBuffer(self):
     for packet_size in range(1, 10):
         t = StringIOWithoutClosing()
         a = TestNetstring()
         a.makeConnection(protocol.FileWrapper(t))
         for s in self.strings:
             a.sendString(s)
         out = t.getvalue()
         for i in range(len(out)/packet_size + 1):
             s = out[i*packet_size:(i+1)*packet_size]
             if s:
                 a.dataReceived(s)
         if a.received != self.strings:
             raise AssertionError(a.received)
Exemple #5
0
    def setUp(self):
        self.service = DummyService("twisted.words.TendrilTest")
        self.tendril = tendril.TendrilClient(self.service,
                                             groupList=['tendriltest'],
                                             networkSuffix='@unittest')
        self.file = StringIOWithoutClosing()
        self.transport = protocol.FileWrapper(self.file)
        self.transport.connected = 1
        self.tendril.makeConnection(self.transport)

        self.tendril.signedOn()
        self.tendril.joinGroup('tendriltest')

        self.group = self.service.getGroup('tendriltest')
        self.participant = self.service.createParticipant('TheParticipant')
        self.participant.joinGroup('tendriltest')
Exemple #6
0
 def runTest(self):
     sends=["FLAPON\r\n\r\n",\
      flap(1,"\000\000\000\001\000\001\000\004test"),\
      flap(2,"toc_signon localhost 9999 test 0x00 english penguin\000"),\
      flap(2,"toc_init_done\000"),\
      flap(2,"toc_add_deny\000"),\
      flap(2,"toc_send_im test 1\000"),\
      flap(2,"toc_add_deny test\000"),\
      flap(2,"toc_send_im test 2\000"),\
      flap(2,"toc_add_permit\000"),\
      flap(2,"toc_send_im test 3\000"),\
      flap(2,"toc_add_permit test\000"),\
      flap(2,"toc_send_im test 4\000")]
     expect=[[1,"\000\000\000\001"],\
      [2,"SIGN_ON:TOC1.0\000"],\
      [2,"NICK:test\000"],\
      [2,"CONFIG:\000"],\
      [2,"IM_IN:test:F:1\000"],\
      [2,"ERROR:901:test\000"],\
      [2,"ERROR:901:test\000"],\
      [2,"IM_IN:test:F:4\000"]]
     d = DummyTOC()
     d.factory = toc.TOCFactory()
     s = StringIOWithoutClosing()
     d.makeConnection(protocol.FileWrapper(s))
     for i in sends:
         d.dataReceived(i)
     d.connectionLost()
     v = s.getvalue()
     flaps = []
     f, v = readFlap(v)
     while f:
         flaps.append(f)
         f, v = readFlap(v)
     if flaps != expect:
         for i in range(len(flaps)):
             if flaps[i] != expect[i]:
                 raise AssertionError(
                     "PrivacyTest Before Failed!\nactual:%s\nshould be:%s" %
                     (flaps[i], expect[i]))
         raise AssertionError(
             "PrivacyTest Before Failed with incorrect length!\nactual:%s\nshould be:%s"
             % (flaps, expect))
    def testBuffer(self):
        a = StringIOWithoutClosing()
        dummy = DummyPOP3()
        dummy.makeConnection(protocol.FileWrapper(a))
        lines = string.split('''\
APOP moshez dummy
LIST
UIDL
RETR 1
RETR 2
DELE 1
RETR 1
QUIT''', '\n')
        expected_output = '+OK <moshez>\r\n+OK \r\n+OK 1\r\n1 44\r\n.\r\n+OK \r\n1 0\r\n.\r\n+OK 44\r\nFrom: moshe\r\nTo: moshe\r\n\r\nHow are you, friend?\r\n.\r\n-ERR index out of range\r\n+OK \r\n-ERR message deleted\r\n+OK \r\n'
        for line in lines:
            dummy.lineReceived(line)
        self.failUnlessEqual(expected_output, a.getvalue(),
                             "\nExpected:\n%s\nResults:\n%s\n"
                             % (expected_output, a.getvalue()))
    def testBuffer(self):
        b = StringIOWithoutClosing()
        a = DummyHTTPHandler()
        a.makeConnection(protocol.FileWrapper(b))
        # one byte at a time, to stress it.
        for byte in self.requests:
            a.dataReceived(byte)
        a.connectionLost()
        value = b.getvalue()
        if value != self.expected_response:
	    for i in range(len(value)):
                if value[i] != self.expected_response[i]:
                    print `value[i-5:i+10]`, `self.expected_response[i-5:i+10]`
                    break
            print '---VALUE---'
            print repr(value)
            print '---EXPECTED---'
            print repr(self.expected_response)
            raise AssertionError
Exemple #9
0
 def runTest(self):
     packets=["FLAPON\r\n\r\n",\
      flap(1,"\000\000\000\001\000\001\000\004test"),\
      flap(2,"toc_signon null 9999 test 0x100000 english \"penguin 0.1\"\000"),\
      flap(2,"toc_init_done\000"),\
      flap(2,"toc_send_im test hi\000")]
     shouldbe=[[1,"\000\000\000\001"],\
      [2,"SIGN_ON:TOC1.0\000"],\
      [2,"NICK:test\000"],\
      [2,"CONFIG:\000"],\
      [2,"IM_IN:test:F:hi\000"]]
     data = ""
     for i in packets:
         data = data + i
     s = StringIOWithoutClosing()
     d = DummyTOC()
     fac = toc.TOCFactory()
     d.factory = fac
     d.makeConnection(protocol.FileWrapper(s))
     d.dataReceived(data)
     d.connectionLost()
     value = s.getvalue()
     flaps = []
     f, value = readFlap(value)
     while f:
         flaps.append(f)
         f, value = readFlap(value)
     if flaps != shouldbe:
         for i in range(len(flaps)):
             if flaps[i] != shouldbe[i]:
                 raise AssertionError(
                     "MultiPacketTest Failed!\nactual:%s\nshould be:%s" %
                     (flaps[i], shouldbe[i]))
         raise AssertionError(
             "MultiPacketTest Failed with incorrect length!, printing both lists\nactual:%s\nshould be:%s"
             % (flaps, shouldbe))
Exemple #10
0
 def runTest(self):
     USERS = 2
     data = range(USERS)
     data[0]=("FLAPON\r\n\r\n",\
     flap(1,"\000\000\000\001\000\001\000\004test"),\
     flap(2,"toc_signon localhost 9999 test 0x100000 english \"penguin 0.1\"\000"),\
     flap(2,"toc_add_buddy test\000"),\
     flap(2,"toc_init_done\000"),\
     flap(2,"toc_send_im test \"hi\"\000"),\
     flap(2,"toc_send_im test2 \"hello\"\000"),\
     flap(2,"toc_set_away \"not here\"\000"),\
     flap(2,"toc_set_idle 602\000"),\
     flap(2,"toc_set_idle 0\000"),\
     flap(2,"toc_set_away\000"),\
     flap(2,"toc_evil test norm\000"),\
     flap(2,"toc_chat_join 4 \"Test Chat\"\000"),\
     flap(2,"toc_chat_send 0 \"hello\"\000"),\
     #flap(2,"toc_chat_leave 0\000")) #,\
     flap(2,"toc_chat_invite 0 \"come\" ooga\000"),\
     #flap(2,"toc_chat_accept 0\000"),\
     flap(5,"\000"),\
     flap(2,"toc_chat_whisper 0 ooga \"boo ga\"\000"),\
     flap(2,"toc_chat_leave 0"),\
     flap(5,"\000"))
     data[1]=("FLAPON\r\n\r\n",\
     flap(1,"\000\000\000\001\000\001\000\004ooga"),\
     flap(2,"toc_signon localhost 9999 ooga 0x100000 english \"penguin 0.1\"\000"),\
     flap(2,"toc_add_buddy test\000"),\
     flap(2,"toc_init_done\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     #flap(5,"\000"),\
     #flap(5,"\000"),\
     #flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     flap(5,"\000"),\
     #flap(5,"\000"),\
     flap(2,"toc_chat_accept 0\000"),\
     flap(2,"toc_chat_send 0 \"hi test\"\000"),\
     flap(5,"\000"),\
     flap(2,"toc_chat_leave 0\000"))
     strings = range(USERS)
     for i in strings:
         strings[i] = StringIOWithoutClosing()
     fac = toc.TOCFactory()
     dummy = range(USERS)
     for i in dummy:
         dummy[i] = DummyTOC()
         dummy[i].factory = fac
         dummy[i].makeConnection(protocol.FileWrapper(strings[i]))
     while reduce(lambda x, y: x + y, map(lambda x: x ==
                                          (), data)) != USERS:
         for i in range(USERS):
             d = data[i]
             if len(d) > 0:
                 k, data[i] = d[0], d[1:]
                 for j in k:
                     dummy[i].dataReceived(
                         j)  # test by doing a character at a time
             else:
                 dummy[i].connectionLost()
     values = range(USERS)
     for i in values:
         values[i] = strings[i].getvalue()
     flaps = map(lambda x: [], range(USERS))
     for value in values:
         i = values.index(value)
         f, value = readFlap(value)
         while f:
             flaps[i].append(f)
             f, value = readFlap(value)
     ts = range(USERS)
     for t in ts:
         ts[t] = dummy[t].signontime
     shouldequal = range(USERS)
     shouldequal[0]=[ \
     [1,"\000\000\000\001"],\
     [2,"SIGN_ON:TOC1.0\000"],\
     [2,"NICK:test\000"],\
     [2,"CONFIG:\00"],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: O\000"%ts[0]],\
     [2,"IM_IN:test:F:hi\000"],\
     [2,"ERROR:901:test2\000"],\
     #[2,"UPDATE_BUDDY:test:T:0:%s:0: O\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:10: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: O\000"%ts[0]],\
     [2,"EVILED:10:test\000"],\
     [2,"UPDATE_BUDDY:test:T:10:%s:0: O\000"%ts[0]],\
     [2,"CHAT_JOIN:0:Test Chat\000"],\
     [2,"CHAT_UPDATE_BUDDY:0:T:test\000"],\
     [2,"CHAT_IN:0:test:F:hello\000"],\
     [2,"CHAT_UPDATE_BUDDY:0:T:ooga\000"],\
     [2,"CHAT_IN:0:ooga:F:hi test\000"],\
     [2,"CHAT_LEFT:0\000"]]
     shouldequal[1]=[ \
     [1,"\000\000\000\001"],\
     [2,"SIGN_ON:TOC1.0\000"],\
     [2,"NICK:ooga\000"],\
     [2,"CONFIG:\000"],\
     #[2,"UPDATE_BUDDY:test:T:0:%s:0: O\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:10: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: OU\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:0:%s:0: O\000"%ts[0]],\
     [2,"UPDATE_BUDDY:test:T:10:%s:0: O\000"%ts[0]],\
     [2,"CHAT_INVITE:Test Chat:0:test:come\000"],\
     [2,"CHAT_JOIN:0:Test Chat\000"],\
     [2,"CHAT_UPDATE_BUDDY:0:T:test:ooga\000"],\
     [2,"CHAT_IN:0:ooga:F:hi test\000"],\
     [2,"CHAT_IN:0:test:T:boo ga\000"],\
     [2,"CHAT_UPDATE_BUDDY:0:F:test\000"],\
     [2,"CHAT_LEFT:0\000"]]
     if flaps != shouldequal:
         for i in range(len(shouldequal)):
             for j in range(len(shouldequal[i])):
                 if shouldequal[i][j] != flaps[i][j]:
                     raise AssertionError(
                         "GeneralTest Failed!\nUser %s Line %s\nactual:%s\nshould be:%s"
                         % (i, j, flaps[i][j], shouldequal[i][j]))
         raise AssertionError("GeneralTest Failed with incorrect lengths!")
Exemple #11
0
 def runTest(self):
     password1 = toc.roast("test pass")
     password2 = toc.roast("pass test")
     beforesend=[\
      "FLAPON\r\n\r\n",\
      flap(1,"\000\000\000\001\000\001\000\004test"),\
      flap(2,"toc_signon localhost 9999 test %s english \"penguin 0.1\"\000"%password1),\
      flap(2,"toc_init_done\000"),\
      flap(2,"toc_set_config \"{m 4}\"\000"),\
      flap(2,"toc_format_nickname BOOGA\000"),\
      flap(2,"toc_format_nickname \"T E S T\"\000"),\
      flap(2,"toc_change_passwd \"testpass\" \"pass test\"\000"),\
      flap(2,"toc_change_passwd \"test pass\" \"pass test\"\000")]
     beforeexpect=[\
      [1,"\000\000\000\001"],\
      [2,"SIGN_ON:TOC1.0\000"],\
      [2,"NICK:test\000"],\
      [2,"CONFIG:\000"],\
      [2,"ERROR:911\000"],\
      [2,"ADMIN_NICK_STATUS:0\000"],\
      [2,"ERROR:911\000"],\
      [2,"ADMIN_PASSWD_STATUS:0\000"]]
     badpasssend=[\
      "FLAPON\r\n\r\n",\
      flap(1,"\000\000\000\001\000\001\000\004test"),\
      flap(2,"toc_signon localhost 9999 test 0x1000 english \"penguin 0.1\"\000"),\
      flap(2,"toc_init_done")]
     badpassexpect=[\
      [1,"\000\00\000\001"],\
      [2,"ERROR:980\000"]]
     goodpasssend=[\
      "FLAPON\r\n\r\n",\
      flap(1,"\000\000\000\001\000\001\000\004test"),\
      flap(2,"toc_signon localhost 9999 test %s english \"penguin 0.1\"\000"%password2),\
      flap(2,"toc_init_done")]
     goodpassexpect=[\
      [1,"\000\000\000\001"],\
      [2,"SIGN_ON:TOC1.0\000"],\
      [2,"NICK:T E S T\000"],\
      [2,"CONFIG:{m 4}\000"]]
     fac = toc.TOCFactory()
     d = DummyTOC()
     d.factory = fac
     s = StringIOWithoutClosing()
     d.makeConnection(protocol.FileWrapper(s))
     for i in beforesend:
         d.dataReceived(i)
     d.connectionLost()
     v = s.getvalue()
     flaps = []
     f, v = readFlap(v)
     while f:
         flaps.append(f)
         f, v = readFlap(v)
     if flaps != beforeexpect:
         for i in range(len(flaps)):
             if flaps[i] != beforeexpect[i]:
                 raise AssertionError(
                     "SavedValuesTest Before Failed!\nactual:%s\nshould be:%s"
                     % (flaps[i], beforeexpect[i]))
         raise AssertionError(
             "SavedValuesTest Before Failed with incorrect length!\nactual:%s\nshould be:%s"
             % (flaps, beforeexpect))
     d = DummyTOC()
     d.factory = fac
     s = StringIOWithoutClosing()
     d.makeConnection(protocol.FileWrapper(s))
     for i in badpasssend:
         d.dataReceived(i)
     d.connectionLost()
     v = s.getvalue()
     flaps = []
     f, v = readFlap(v)
     while f:
         flaps.append(f)
         f, v = readFlap(v)
     if flaps != badpassexpect:
         for i in range(len(flaps)):
             if flaps[i] != badpassexpect[i]:
                 raise AssertionError(
                     "SavedValuesTest BadPass Failed!\nactual:%s\nshould be:%s"
                     % (flaps[i], badpassexpect[i]))
         raise AssertionError(
             "SavedValuesTest BadPass Failed with incorrect length!\nactual:%s\nshould be:%s"
             % (flaps, badpassexpect))
     d = DummyTOC()
     d.factory = fac
     s = StringIOWithoutClosing()
     d.makeConnection(protocol.FileWrapper(s))
     for i in goodpasssend:
         d.dataReceived(i)
     d.connectionLost()
     v = s.getvalue()
     flaps = []
     f, v = readFlap(v)
     while f:
         flaps.append(f)
         f, v = readFlap(v)
     if flaps != goodpassexpect:
         for i in range(len(flaps)):
             if flaps[i] != goodpassexpect[i]:
                 raise AssertionError(
                     "SavedValuesTest GoodPass Failed!\nactual:%s\nshould be:%s"
                     % (flaps[i], goodpassexpect[i]))
         raise AssertionError(
             "SavedValuesTest GoodPass Failed with incorrect length!\nactual:%s\nshould be:%s"
             % (flaps, beforeexpect))
 def getSafeNS(self):
     t = StringIOWithoutClosing()
     a = TestSafeNetstring()
     a.makeConnection(protocol.FileWrapper(t))
     return a
Exemple #13
0
 def setUp(self):
     self.file = StringIOWithoutClosing()
     self.transport = protocol.FileWrapper(self.file)
     self.client = IRCClientWithoutLogin()
     self.client.makeConnection(self.transport)
Exemple #14
0
 def setUp(self):
     self.io = cStringIO.StringIO()
     self.enc = banana.Banana()
     self.enc.makeConnection(protocol.FileWrapper(self.io))
     self.enc.expressionReceived = self.putResult