コード例 #1
0
class FileTransferTestCase(unittest.TestCase):
    """
    test FileSend against FileReceive
    """

    def setUp(self):
        self.input = 'a' * 7000
        self.output = StringIOWithoutClosing()


    def tearDown(self):
        self.input = None
        self.output = None


    def test_fileTransfer(self):
        """
        Test L{FileSend} against L{FileReceive} using a loopback transport.
        """
        auth = 1234
        sender = msn.FileSend(StringIO.StringIO(self.input))
        sender.auth = auth
        sender.fileSize = 7000
        client = msn.FileReceive(auth, "*****@*****.**", self.output)
        client.fileSize = 7000
        def check(ignored):
            self.assertTrue(
                client.completed and sender.completed,
                msg="send failed to complete")
            self.assertEqual(
                self.input, self.output.getvalue(),
                msg="saved file does not match original")
        d = loopback.loopbackAsync(sender, client)
        d.addCallback(check)
        return d
コード例 #2
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(failure.Failure(main.CONNECTION_DONE))
     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))
コード例 #3
0
ファイル: test_irc.py プロジェクト: swift1911/twisted
class BasicServerFunctionalityTestCase(unittest.TestCase):
    def setUp(self):
        self.f = StringIOWithoutClosing()
        self.t = protocol.FileWrapper(self.f)
        self.p = irc.IRC()
        self.p.makeConnection(self.t)


    def check(self, s):
        self.assertEquals(self.f.getvalue(), s)


    def testPrivmsg(self):
        self.p.privmsg("this-is-sender", "this-is-recip", "this is message")
        self.check(":this-is-sender PRIVMSG this-is-recip :this is message\r\n")


    def testNotice(self):
        self.p.notice("this-is-sender", "this-is-recip", "this is notice")
        self.check(":this-is-sender NOTICE this-is-recip :this is notice\r\n")


    def testAction(self):
        self.p.action("this-is-sender", "this-is-recip", "this is action")
        self.check(":this-is-sender ACTION this-is-recip :this is action\r\n")


    def testJoin(self):
        self.p.join("this-person", "#this-channel")
        self.check(":this-person JOIN #this-channel\r\n")


    def testPart(self):
        self.p.part("this-person", "#that-channel")
        self.check(":this-person PART #that-channel\r\n")


    def testWhois(self):
        """
        Verify that a whois by the client receives the right protocol actions
        from the server.
        """
        timestamp = int(time.time()-100)
        hostname = self.p.hostname
        req = 'requesting-nick'
        targ = 'target-nick'
        self.p.whois(req, targ, 'target', 'host.com',
                'Target User', 'irc.host.com', 'A fake server', False,
                12, timestamp, ['#fakeusers', '#fakemisc'])
        expected = '\r\n'.join([
':%(hostname)s 311 %(req)s %(targ)s target host.com * :Target User',
':%(hostname)s 312 %(req)s %(targ)s irc.host.com :A fake server',
':%(hostname)s 317 %(req)s %(targ)s 12 %(timestamp)s :seconds idle, signon time',
':%(hostname)s 319 %(req)s %(targ)s :#fakeusers #fakemisc',
':%(hostname)s 318 %(req)s %(targ)s :End of WHOIS list.',
'']) % dict(hostname=hostname, timestamp=timestamp, req=req, targ=targ)
        self.check(expected)
コード例 #4
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(failure.Failure(main.CONNECTION_DONE))
     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))
コード例 #5
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(failure.Failure(main.CONNECTION_DONE))
     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))         
コード例 #6
0
class CTCPTest(unittest.TestCase):
    def setUp(self):
        self.file = StringIOWithoutClosing()
        self.transport = protocol.FileWrapper(self.file)
        self.client = IRCClientWithoutLogin()
        self.client.makeConnection(self.transport)

    def test_ERRMSG(self):
        """Testing CTCP query ERRMSG.

        Not because this is this is an especially important case in the
        field, but it does go through the entire dispatch/decode/encode
        process.
        """

        errQuery = (":[email protected] PRIVMSG #theChan :"
                    "%(X)cERRMSG t%(X)c%(EOL)s" % {
                        'X': irc.X_DELIM,
                        'EOL': irc.CR + irc.LF
                    })

        errReply = ("NOTICE nick :%(X)cERRMSG t :"
                    "No error has occoured.%(X)c%(EOL)s" % {
                        'X': irc.X_DELIM,
                        'EOL': irc.CR + irc.LF
                    })

        self.client.dataReceived(errQuery)
        reply = self.file.getvalue()

        self.failUnlessEqual(errReply, reply)

    def tearDown(self):
        self.transport.loseConnection()
        self.client.connectionLost()
        del self.client
        del self.transport
コード例 #7
0
ファイル: test_irc.py プロジェクト: Almad/twisted
class CTCPTest(unittest.TestCase):
    def setUp(self):
        self.file = StringIOWithoutClosing()
        self.transport = protocol.FileWrapper(self.file)
        self.client = IRCClientWithoutLogin()
        self.client.makeConnection(self.transport)


    def test_ERRMSG(self):
        """Testing CTCP query ERRMSG.

        Not because this is this is an especially important case in the
        field, but it does go through the entire dispatch/decode/encode
        process.
        """

        errQuery = (":[email protected] PRIVMSG #theChan :"
                    "%(X)cERRMSG t%(X)c%(EOL)s"
                    % {'X': irc.X_DELIM,
                       'EOL': irc.CR + irc.LF})

        errReply = ("NOTICE nick :%(X)cERRMSG t :"
                    "No error has occoured.%(X)c%(EOL)s"
                    % {'X': irc.X_DELIM,
                       'EOL': irc.CR + irc.LF})

        self.client.dataReceived(errQuery)
        reply = self.file.getvalue()

        self.failUnlessEqual(errReply, reply)


    def tearDown(self):
        self.transport.loseConnection()
        self.client.connectionLost()
        del self.client
        del self.transport
コード例 #8
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(failure.Failure(main.CONNECTION_DONE))
     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))
コード例 #9
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(failure.Failure(main.CONNECTION_DONE))
     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(failure.Failure(main.CONNECTION_DONE))
     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(failure.Failure(main.CONNECTION_DONE))
     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))
コード例 #10
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(failure.Failure(main.CONNECTION_DONE))
     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(failure.Failure(main.CONNECTION_DONE))
     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(failure.Failure(main.CONNECTION_DONE))
     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))