def test_session_management_sched(self): authentication.GLSession('admin', 'admin', 'enabled') # 1! authentication.GLSession('admin', 'admin', 'enabled') # 2! authentication.GLSession('admin', 'admin', 'enabled') # 3! self.assertEqual(len(GLSettings.sessions), 3) authentication.reactor_override.advance(GLSettings.defaults.authentication_lifetime) self.assertEqual(len(GLSettings.sessions), 0) yield session_management_sched.SessionManagementSchedule().operation()
def test_session_management_sched(self): authentication.GLSession('admin', 'admin', 'enabled') # 1! authentication.GLSession('admin', 'admin', 'enabled') # 2! authentication.GLSession('admin', 'admin', 'enabled') # 3! self.assertEqual(len(GLSettings.sessions), 3) self.test_reactor.pump([1] * (GLSettings.authentication_lifetime - 1)) self.assertEqual(len(GLSettings.sessions), 3) self.test_reactor.advance(1) self.assertEqual(len(GLSettings.sessions), 0) yield session_management_sched.SessionManagementSchedule().operation()
def test_successful_session_update_on_auth_request(self): session = authentication.GLSession('admin', 'admin', 'enabled') date1 = session.getTime() authentication.reactor_override.advance(FUTURE) handler = self.request({}, headers={'X-Session': session.id}) yield handler.get() date2 = GLSettings.sessions[session.id].getTime() self.assertEqual(date1 + FUTURE, date2)
def test_successful_session_update_on_unauth_request(self): session = authentication.GLSession('admin', 'admin', 'enabled') date1 = session.getTime() self.test_reactor.pump([1] * FUTURE) handler = self.request({}, headers={'X-Session': session.id}) yield handler.get() date2 = GLSettings.sessions.get(session.id).getTime() self.assertEqual(date1 + FUTURE, date2)
def request(self, jbody=None, role=None, user_id=None, headers=None, body='', remote_ip='0.0.0.0', method='MOCK', kwargs={}): """ Function userful for performing mock requests. Args: jbody: The body of the request as a dict (it will be automatically converted to string) body: The body of the request as a string role: If we should perform authentication role can be either "admin", "receiver" or "wb" user_id: If when performing authentication the session should be bound to a certain user_id. method: HTTP method, e.g. "GET" or "POST" uri: URL to fetch role: the role headers: (dict or :class:`cyclone.httputil.HTTPHeaders` instance) HTTP headers to pass on the request remote_ip: If a particular remote_ip should be set. """ if jbody and not body: body = json.dumps(jbody) elif body and jbody: raise ValueError('jbody and body in conflict') application = Application([]) tr = proto_helpers.StringTransport() connection = GLHTTPConnection() connection.factory = application connection.makeConnection(tr) request = httpserver.HTTPRequest(uri='mock', method=method, headers=headers, body=body, remote_ip=remote_ip, connection=connection) handler = self._handler(application, request, **kwargs) if role: session = authentication.GLSession(user_id, role, 'enabled') handler.request.headers['X-Session'] = session.id return handler