def test_session_attach(): # Create environment server, session, transport, conn = _get_test_environment(a=[10]) # Check if connection opened eq_(conn.is_open, True) eq_(conn.request.arguments, {'a': [10]}) eq_(conn.request.get_argument('a'), 10) # Send message and check if it was handled by connection transport.recv(proto.message(None, 'abc')) # Check if incoming queue has abc eq_(conn.pop_incoming(), 'abc') # Check if outgoing transport has abc eq_(transport.pop_outgoing(), '3:::abc') # Close session conn.close() # Check if it sent disconnect packet to the client eq_(transport.pop_outgoing(), '0::') # Detach session.remove_handler(transport) eq_(session.handler, None) # Check if session is still open eq_(transport.is_open, False) eq_(conn.is_open, False) eq_(session.is_closed, True)
def __authenticate_user(self, session_id): conn = httplib.HTTPSConnection("127.0.0.1") conn.request("GET", "/session/%s" % session_id) r = conn.getresponse() if r.status == 200: body = r.read() else: body = None conn.close() if body: self.user = ujson.decode(body) self.session_id = session_id CONNECTIONS.add(self) log_msg = ["Connection authenticated"] log_msg.append("remote-address=%s" % self.infos.ip) log_msg.append("user=%s" % self.user['username']) log_msg.append("session-id=%s" % self.session_id) logging.info(', '.join(log_msg))
def __authenticate_user(self, session_id): conn = httplib.HTTPSConnection("127.0.0.1") conn.request("GET", "/session/%s" % session_id) r = conn.getresponse() if r.status == 200: body = r.read() else: body = None conn.close() if body: self.user = ujson.decode(body) self.session_id = session_id CONNECTIONS.add(self) log_msg = ["Connection authenticated"] log_msg.append("remote-address=%s" % self.infos.ip) log_msg.append("user=%s" % self.user["username"]) log_msg.append("session-id=%s" % self.session_id) logging.info(", ".join(log_msg))