Beispiel #1
0
    def lookupUser(self, name):
        """
        Looks for the given user first in the local store and
        failing that in the database. If found in the databse,
        checks the session for validity - if the session is valid
        the user must be connected to some other node, so a ShardedUser
        with a ProxyIRCDDUser for mind is returned. If the session is
        not valid, fail with NoSuchUser.

        :param name: the name of the user to look for.
        """
        assert isinstance(name, unicode)
        name = name.lower()

        local_user = self.users.get(name)
        if local_user:
            return defer.succeed(local_user)

        remote_user = self.ctx.db.lookupUser(name)
        user_session = self.ctx.db.lookupUserSession(name)

        # User exists and session is active, so he must be
        # connected to some remote
        if remote_user and user_session and user_session["active"]:
            return defer.succeed(
                ShardedUser(self.ctx, name, ProxyIRCDDUser(self.ctx, name)))

        return defer.fail(failure.Failure(ewords.NoSuchUser(name)))
Beispiel #2
0
 def userFactory(self, name):
     """
     Returns a new ShardedUser for the given avatar id.
     The ShardedUser serves as a controller to the user's
     model.
     """
     return ShardedUser(self.ctx, name)
Beispiel #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.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"
Beispiel #4
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"] != ""