Esempio n. 1
0
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        self.protocols = []
        self.transports = []

        self.config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                           lookupd_http_address=["127.0.0.1:4161"],
                           hostname="testserver",
                           group_on_request=True,
                           user_on_request=True,
                           db=integration.DB,
                           rdb_host=integration.HOST,
                           rdb_port=integration.PORT)

        self.ctx = makeContext(self.config)

        self.factory = IRCDDFactory(self.ctx)

        self.clients = 3
        for client in xrange(0, self.clients):

            protocol = self.factory.buildProtocol(("127.0.0.%s" % client, 0))
            self.protocols.append(protocol)

            transport = proto_helpers.StringTransport()
            self.transports.append(transport)

            protocol.makeConnection(transport)
Esempio n. 2
0
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        self.protocols = []
        self.transports = []

        self.config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                           lookupd_http_address=["127.0.0.1:4161"],
                           hostname="testserver",
                           group_on_request=True,
                           user_on_request=True,
                           db=integration.DB,
                           rdb_host=integration.HOST,
                           rdb_port=integration.PORT
                           )

        self.ctx = makeContext(self.config)

        self.factory = IRCDDFactory(self.ctx)

        self.clients = 3
        for client in xrange(0, self.clients):

            protocol = self.factory.buildProtocol(("127.0.0.%s" % client, 0))
            self.protocols.append(protocol)

            transport = proto_helpers.StringTransport()
            self.transports.append(transport)

            protocol.makeConnection(transport)
Esempio n. 3
0
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT)
        self.ctx = makeContext(config)

        self.ctx["db"].createUser("john", password="******", registered=True)
        self.ctx["db"].createUser("jane", password="******", registered=True)
        self.ctx["db"].createUser("jill", password="******", registered=True)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)
Esempio n. 4
0
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT
                      )
        self.ctx = makeContext(config)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)

        self.shardedUser = ShardedUser(self.ctx, "john")
        self.shardedUser.mind = self.protocol
        self.shardedUser.mind.name = "john"
Esempio n. 5
0
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT
                      )
        self.ctx = makeContext(config)

        self.ctx["db"].createUser("john", password="******", registered=True)
        self.ctx["db"].createUser("jane", password="******", registered=True)
        self.ctx["db"].createUser("jill", password="******", registered=True)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)
Esempio n. 6
0
class TestIRCDDAuth:
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT)
        self.ctx = makeContext(config)

        self.ctx["db"].createUser("john", password="******", registered=True)
        self.ctx["db"].createUser("jane", password="******", registered=True)
        self.ctx["db"].createUser("jill", password="******", registered=True)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)

    def tearDown(self):
        self.transport.loseConnection()
        self.protocol.connectionLost(None)

        integration.cleanTables()

        self.conn.close()

        for topic in _topics(self.ctx["lookupd_http_address"]):
            for chan in _channels(topic, self.ctx["lookupd_http_address"]):
                _delete_channel(topic, chan, self.ctx["lookupd_http_address"])
            _delete_topic(topic, self.ctx["lookupd_http_address"])

        self.ctx["db"].conn.close()
        self.ctx = None

    def getResponse(self):
        response = self.protocol.transport.value().splitlines()
        self.protocol.transport.clear()
        return map(irc.parsemsg, response)

    def test_anon_login(self):
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [
            ("testserver", "375",
             ["anonuser", "- testserver Message of the Day - "]),
            ("testserver", "376", ["anonuser", "End of /MOTD command."]),
            ("testserver", "001", ["anonuser", "connected to Twisted IRC"]),
            ("testserver", "002", ["anonuser", version]),
            ("testserver", "003", ["anonuser", creation]),
            ("testserver", "004", [
                "anonuser", "testserver",
                self.factory._serverInfo["serviceVersion"], "w", "n"
            ])
        ]

        response = self.getResponse()
        assert response == expected

    def test_registered_login(self):
        """
        Connecting to the server, sending /pass <pw>,
        then /nick <name> logs the registered user in.
        """

        self.protocol.irc_PASS("", ["pw"])
        self.protocol.irc_NICK("", ["john"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [("testserver", "375",
                     ["john", "- testserver Message of the Day - "]),
                    ("testserver", "376", ["john", "End of /MOTD command."]),
                    ("testserver", "001", ["john",
                                           "connected to Twisted IRC"]),
                    ("testserver", "002", ["john", version]),
                    ("testserver", "003", ["john", creation]),
                    ("testserver", "004", [
                        "john", "testserver",
                        self.factory._serverInfo["serviceVersion"], "w", "n"
                    ])]

        response = self.getResponse()
        assert response == expected

    def test_anon_login_create_fail(self):
        self.ctx["realm"].createUserOnRequest = False

        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [
            ("testserver", "375",
             ["anonuser", "- testserver Message of the Day - "]),
            ("testserver", "376", ["anonuser", "End of /MOTD command."]),
            ("testserver", "001", ["anonuser", "connected to Twisted IRC"]),
            ("testserver", "002", ["anonuser", version]),
            ("testserver", "003", ["anonuser", creation]),
            ("testserver", "004", [
                "anonuser", "testserver",
                self.factory._serverInfo["serviceVersion"], "w", "n"
            ])
        ]

        response = self.getResponse()
        # Improve this to expect a specific error output
        assert response != expected

    def test_anon_login_nick_taken_fail(self):
        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [
            ("testserver", "375",
             ["anonuser", "- testserver Message of the Day - "]),
            ("testserver", "376", ["anonuser", "End of /MOTD command."]),
            ("testserver", "001", ["anonuser", "connected to Twisted IRC"]),
            ("testserver", "002", ["anonuser", version]),
            ("testserver", "003", ["anonuser", creation]),
            ("testserver", "004", [
                "anonuser", "testserver",
                self.factory._serverInfo["serviceVersion"], "w", "n"
            ])
        ]

        response = self.getResponse()
        assert response == expected

        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        expected = [
            ('testserver', '375',
             ['anonuser', '- testserver Message of the Day - ']),
            ('testserver', '376', ['anonuser', 'End of /MOTD command.']),
            ('NickServ!NickServ@services', 'PRIVMSG',
             ['anonuser', 'Already logged in.  No pod people allowed!'])
        ]
        response_fail = self.getResponse()

        assert response_fail == expected

    def test_registered_login_pw_fail(self):
        self.protocol.irc_PASS("", ["bad_password"])
        self.protocol.irc_NICK("", ["john"])

        expected = [('testserver', '375',
                     ['john', '- testserver Message of the Day - ']),
                    ('testserver', '376', ['john', 'End of /MOTD command.']),
                    ('NickServ!NickServ@services', 'PRIVMSG',
                     ['john', 'Login failed.  Goodbye.'])]

        response = self.getResponse()
        assert response == expected
Esempio n. 7
0
class TestMessaging():
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        self.protocols = []
        self.transports = []

        self.config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                           lookupd_http_address=["127.0.0.1:4161"],
                           hostname="testserver",
                           group_on_request=True,
                           user_on_request=True,
                           db=integration.DB,
                           rdb_host=integration.HOST,
                           rdb_port=integration.PORT
                           )

        self.ctx = makeContext(self.config)

        self.factory = IRCDDFactory(self.ctx)

        self.clients = 3
        for client in xrange(0, self.clients):

            protocol = self.factory.buildProtocol(("127.0.0.%s" % client, 0))
            self.protocols.append(protocol)

            transport = proto_helpers.StringTransport()
            self.transports.append(transport)

            protocol.makeConnection(transport)

    def tearDown(self):
        for transport in self.transports:
            transport.loseConnection()
        self.transports = None

        for protocol in self.protocols:
            protocol.connectionLost(None)
        self.protocols = None

        self.factory = None
        self.config = None

        self.ctx.db.conn.close()
        self.ctx = None

        for topic in _topics(["127.0.0.1:4161"]):
            _delete_topic(topic, ["127.0.0.1:4161"])

        integration.cleanTables()

        self.conn.close()

    def getResponse(self, protocol):
        response = protocol.transport.value().splitlines()
        protocol.transport.clear()
        return map(irc.parsemsg, response)

    def test_join_msg(self):
        john_protocol = self.protocols[0]
        hostname = self.factory.ctx.hostname

        john_protocol.irc_NICK("", ["john"])
        john_protocol.irc_JOIN("", ["testchan"])

        version = ("Your host is %s, running version %s" %
                   (hostname, self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [(hostname, '375',
                    ['john', '- %s Message of the Day - ' % hostname]),
                    (hostname, '376',
                    ['john', 'End of /MOTD command.']),
                    (hostname, '001',
                    ['john', 'connected to Twisted IRC']),
                    (hostname, '002', ['john', version]),
                    (hostname, '003', ['john', creation]),
                    (hostname, '004',
                    ['john', hostname,
                     self.factory._serverInfo["serviceVersion"], 'w', 'n']),
                    ('john!john@%s' % hostname, 'JOIN', ['#testchan']),
                    (hostname, '366',
                    ['john', '#testchan', 'End of /NAMES list'])]

        assert expected == self.getResponse(john_protocol)

        jane_protocol = self.protocols[1]

        jane_protocol.irc_NICK("", ["jane"])
        jane_protocol.irc_JOIN("", ["testchan"])

        expected_notification = [('jane!jane@%s' % hostname,
                                  'JOIN', ['#testchan'])]
        assert expected_notification == self.getResponse(john_protocol)

        expected_join = [(hostname, '375',
                         ['jane', '- %s Message of the Day - ' % hostname]),
                         (hostname, '376',
                         ['jane', 'End of /MOTD command.']),
                         (hostname, '001',
                         ['jane', 'connected to Twisted IRC']),
                         (hostname, '002', ['jane', version]),
                         (hostname, '003', ['jane', creation]),
                         (hostname, '004',
                         ['jane', hostname,
                          self.factory._serverInfo["serviceVersion"],
                          'w', 'n']),
                         ('jane!jane@%s' % hostname, 'JOIN', ['#testchan']),
                         (hostname, '366',
                         ['jane', '#testchan', 'End of /NAMES list'])]

        assert expected_join == self.getResponse(jane_protocol)

    def test_part_msg(self):
        john_protocol = self.protocols[0]
        jane_protocol = self.protocols[1]

        john_protocol.irc_NICK("", ["john"])
        john_protocol.irc_JOIN("", ["testchan"])

        jane_protocol.irc_NICK("", ["jane"])
        jane_protocol.irc_JOIN("", ["testchan"])

        # Discard responses up until this point
        self.getResponse(john_protocol)
        self.getResponse(jane_protocol)

        john_protocol.irc_PART("", ["testchan"])

        expected = [('john!john@testserver', 'PART', ['#testchan', 'leaving'])]

        assert expected == self.getResponse(jane_protocol)
        assert expected == self.getResponse(john_protocol)

    def test_chan_message(self):
        pass

    def test_set_topic_msg(self):
        pass
Esempio n. 8
0
class TestMessaging():
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        self.protocols = []
        self.transports = []

        self.config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                           lookupd_http_address=["127.0.0.1:4161"],
                           hostname="testserver",
                           group_on_request=True,
                           user_on_request=True,
                           db=integration.DB,
                           rdb_host=integration.HOST,
                           rdb_port=integration.PORT)

        self.ctx = makeContext(self.config)

        self.factory = IRCDDFactory(self.ctx)

        self.clients = 3
        for client in xrange(0, self.clients):

            protocol = self.factory.buildProtocol(("127.0.0.%s" % client, 0))
            self.protocols.append(protocol)

            transport = proto_helpers.StringTransport()
            self.transports.append(transport)

            protocol.makeConnection(transport)

    def tearDown(self):
        for transport in self.transports:
            transport.loseConnection()
        self.transports = None

        for protocol in self.protocols:
            protocol.connectionLost(None)
        self.protocols = None

        self.factory = None
        self.config = None

        self.ctx.db.conn.close()
        self.ctx = None

        for topic in _topics(["127.0.0.1:4161"]):
            _delete_topic(topic, ["127.0.0.1:4161"])

        integration.cleanTables()

        self.conn.close()

    def getResponse(self, protocol):
        response = protocol.transport.value().splitlines()
        protocol.transport.clear()
        return map(irc.parsemsg, response)

    def test_join_msg(self):
        john_protocol = self.protocols[0]
        hostname = self.factory.ctx.hostname

        john_protocol.irc_NICK("", ["john"])
        john_protocol.irc_JOIN("", ["testchan"])

        version = ("Your host is %s, running version %s" %
                   (hostname, self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [(hostname, '375',
                     ['john', '- %s Message of the Day - ' % hostname]),
                    (hostname, '376', ['john', 'End of /MOTD command.']),
                    (hostname, '001', ['john', 'connected to Twisted IRC']),
                    (hostname, '002', ['john', version]),
                    (hostname, '003', ['john', creation]),
                    (hostname, '004', [
                        'john', hostname,
                        self.factory._serverInfo["serviceVersion"], 'w', 'n'
                    ]), ('john!john@%s' % hostname, 'JOIN', ['#testchan']),
                    (hostname, '366',
                     ['john', '#testchan', 'End of /NAMES list'])]

        assert expected == self.getResponse(john_protocol)

        jane_protocol = self.protocols[1]

        jane_protocol.irc_NICK("", ["jane"])
        jane_protocol.irc_JOIN("", ["testchan"])

        expected_notification = [('jane!jane@%s' % hostname, 'JOIN',
                                  ['#testchan'])]
        assert expected_notification == self.getResponse(john_protocol)

        expected_join = [
            (hostname, '375',
             ['jane', '- %s Message of the Day - ' % hostname]),
            (hostname, '376', ['jane', 'End of /MOTD command.']),
            (hostname, '001', ['jane', 'connected to Twisted IRC']),
            (hostname, '002', ['jane', version]),
            (hostname, '003', ['jane', creation]),
            (hostname, '004', [
                'jane', hostname, self.factory._serverInfo["serviceVersion"],
                'w', 'n'
            ]), ('jane!jane@%s' % hostname, 'JOIN', ['#testchan']),
            (hostname, '366', ['jane', '#testchan', 'End of /NAMES list'])
        ]

        assert expected_join == self.getResponse(jane_protocol)

    def test_part_msg(self):
        john_protocol = self.protocols[0]
        jane_protocol = self.protocols[1]

        john_protocol.irc_NICK("", ["john"])
        john_protocol.irc_JOIN("", ["testchan"])

        jane_protocol.irc_NICK("", ["jane"])
        jane_protocol.irc_JOIN("", ["testchan"])

        # Discard responses up until this point
        self.getResponse(john_protocol)
        self.getResponse(jane_protocol)

        john_protocol.irc_PART("", ["testchan"])

        expected = [('john!john@testserver', 'PART', ['#testchan', 'leaving'])]

        assert expected == self.getResponse(jane_protocol)
        assert expected == self.getResponse(john_protocol)
Esempio n. 9
0
class TestIRCDDAuth:
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT
                      )
        self.ctx = makeContext(config)

        self.ctx["db"].createUser("john", password="******", registered=True)
        self.ctx["db"].createUser("jane", password="******", registered=True)
        self.ctx["db"].createUser("jill", password="******", registered=True)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)

    def tearDown(self):
        self.transport.loseConnection()
        self.protocol.connectionLost(None)

        integration.cleanTables()

        self.conn.close()

        for topic in _topics(self.ctx["lookupd_http_address"]):
            for chan in _channels(topic, self.ctx["lookupd_http_address"]):
                _delete_channel(topic, chan, self.ctx["lookupd_http_address"])
            _delete_topic(topic, self.ctx["lookupd_http_address"])

        self.ctx["db"].conn.close()
        self.ctx = None

    def getResponse(self):
        response = self.protocol.transport.value().splitlines()
        self.protocol.transport.clear()
        return map(irc.parsemsg, response)

    def test_anon_login(self):
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [("testserver", "375",
                    ["anonuser", "- testserver Message of the Day - "]),
                    ("testserver", "376",
                    ["anonuser", "End of /MOTD command."]),
                    ("testserver", "001",
                    ["anonuser", "connected to Twisted IRC"]),
                    ("testserver", "002", ["anonuser", version]),
                    ("testserver", "003", ["anonuser", creation]),
                    ("testserver", "004",
                    ["anonuser", "testserver",
                     self.factory._serverInfo["serviceVersion"], "w", "n"])]

        response = self.getResponse()
        assert response == expected

    def test_registered_login(self):
        """
        Connecting to the server, sending /pass <pw>,
        then /nick <name> logs the registered user in.
        """

        self.protocol.irc_PASS("", ["pw"])
        self.protocol.irc_NICK("", ["john"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [("testserver", "375",
                    ["john", "- testserver Message of the Day - "]),
                    ("testserver", "376",
                    ["john", "End of /MOTD command."]),
                    ("testserver", "001",
                    ["john", "connected to Twisted IRC"]),
                    ("testserver", "002", ["john", version]),
                    ("testserver", "003", ["john", creation]),
                    ("testserver", "004",
                    ["john", "testserver",
                     self.factory._serverInfo["serviceVersion"], "w", "n"])]

        response = self.getResponse()
        assert response == expected

    def test_anon_login_create_fail(self):
        self.ctx["realm"].createUserOnRequest = False

        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [("testserver", "375",
                    ["anonuser", "- testserver Message of the Day - "]),
                    ("testserver", "376",
                    ["anonuser", "End of /MOTD command."]),
                    ("testserver", "001",
                    ["anonuser", "connected to Twisted IRC"]),
                    ("testserver", "002", ["anonuser", version]),
                    ("testserver", "003", ["anonuser", creation]),
                    ("testserver", "004",
                    ["anonuser", "testserver",
                     self.factory._serverInfo["serviceVersion"], "w", "n"])]

        response = self.getResponse()
        # Improve this to expect a specific error output
        assert response != expected

    def test_anon_login_nick_taken_fail(self):
        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        version = ("Your host is testserver, running version %s" %
                   (self.factory._serverInfo["serviceVersion"]))

        creation = ("This server was created on %s" %
                    (self.factory._serverInfo["creationDate"]))

        expected = [("testserver", "375",
                    ["anonuser", "- testserver Message of the Day - "]),
                    ("testserver", "376",
                    ["anonuser", "End of /MOTD command."]),
                    ("testserver", "001",
                    ["anonuser", "connected to Twisted IRC"]),
                    ("testserver", "002", ["anonuser", version]),
                    ("testserver", "003", ["anonuser", creation]),
                    ("testserver", "004",
                    ["anonuser", "testserver",
                     self.factory._serverInfo["serviceVersion"], "w", "n"])]

        response = self.getResponse()
        assert response == expected

        self.protocol.irc_PASS("", ["password"])
        self.protocol.irc_NICK("", ["anonuser"])

        expected = [('testserver', '375',
                     ['anonuser', '- testserver Message of the Day - ']),
                    ('testserver', '376',
                     ['anonuser', 'End of /MOTD command.']),
                    ('NickServ!NickServ@services', 'PRIVMSG',
                     ['anonuser', 'Already logged in.  No pod people allowed!']
                     )]
        response_fail = self.getResponse()

        assert response_fail == expected

    def test_registered_login_pw_fail(self):
        self.protocol.irc_PASS("", ["bad_password"])
        self.protocol.irc_NICK("", ["john"])

        expected = [('testserver', '375',
                    ['john', '- testserver Message of the Day - ']),
                    ('testserver', '376', ['john', 'End of /MOTD command.']),
                    ('NickServ!NickServ@services', 'PRIVMSG',
                    ['john', 'Login failed.  Goodbye.'])]

        response = self.getResponse()
        assert response == expected
Esempio n. 10
0
class TestShardedUser:
    def setUp(self):
        self.conn = r.connect(db=integration.DB,
                              host=integration.HOST,
                              port=integration.PORT)

        config = dict(nsqd_tcp_address=["127.0.0.1:4150"],
                      lookupd_http_address=["127.0.0.1:4161"],
                      hostname="testserver",
                      group_on_request=True,
                      user_on_request=True,
                      db=integration.DB,
                      rdb_host=integration.HOST,
                      rdb_port=integration.PORT
                      )
        self.ctx = makeContext(config)

        self.factory = IRCDDFactory(self.ctx)
        self.protocol = self.factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.transport)

        self.shardedUser = ShardedUser(self.ctx, "john")
        self.shardedUser.mind = self.protocol
        self.shardedUser.mind.name = "john"

    def tearDown(self):
        self.shardedUser = None
        self.transport.loseConnection()
        self.protocol.connectionLost(None)

        integration.cleanTables()

        self.conn.close()

        for topic in _topics(self.ctx["lookupd_http_address"]):
            for chan in _channels(topic, self.ctx["lookupd_http_address"]):
                _delete_channel(topic, chan, self.ctx["lookupd_http_address"])
            _delete_topic(topic, self.ctx["lookupd_http_address"])

        self.ctx["db"].conn.close()
        self.ctx = None

    def test_userHeartbeats(self):
        self.shardedUser.loggedIn(self.ctx.realm, None)

        session = self.ctx.db.lookupUserSession("john")

        assert session
        assert session.get("last_heartbeat")
        assert session.get("last_heartbeat") != ""

        self.ctx.db.heartbeatUserSession("john")
        updated_session = self.ctx.db.lookupUserSession("john")

        assert updated_session
        assert updated_session.get("last_heartbeat")
        assert updated_session.get("last_heartbeat") != ""

        assert session.get("last_heartbeat") != \
            updated_session.get("last_heartbeat")

    def test_userInGroupHeartbeats(self):
        group = ShardedGroup(self.ctx, "test_group")

        self.shardedUser.join(group)

        group_state = self.ctx.db.getGroupState("test_group")

        assert group_state
        assert group_state["users"]["john"]
        assert group_state["users"]["john"] != ""