def test_get_future_epoch(self): a = time.time() b = utility.get_future_epoch(seconds=1) c = utility.get_future_epoch(seconds=2) d = utility.get_future_epoch(seconds=3) self.assertTrue(a < b) self.assertTrue(b < c) self.assertTrue(c < d)
def test_get_future_epoch(self): a = time.time() b = utility.get_future_epoch(seconds=1) c = utility.get_future_epoch(seconds=2) d = utility.get_future_epoch(seconds=3) self.assertTrue(a<b) self.assertTrue(b<c) self.assertTrue(c<d)
def update_session(user): """ Returns True if the session is still valid, False instead. Timed out sessions are destroyed. """ session_info = GLSetting.sessions[user.id] if utility.is_expired(session_info.refreshdate, seconds=GLSetting.defaults.lifetimes[user.role]): log.debug("Authentication Expired (%s) %s seconds" % ( user.role, GLSetting.defaults.lifetimes[user.role] )) del GLSetting.sessions[user.id] return False else: # update the access time to the latest GLSetting.sessions[user.id].refreshdate = utility.datetime_now() GLSetting.sessions[user.id].expirydate = utility.get_future_epoch( seconds=GLSetting.defaults.lifetimes[user.role]) return True
def test_020_expiry_date(self): auth_request = { 'username': self.dummyReceiverUser_1['username'], 'password': helpers.VALID_PASSWORD1, 'role': 'receiver' } handler = self.request(auth_request) yield handler.post() self.assertTrue('session_id' in self.responses[0]) self.assertTrue('session_expiration' in self.responses[0]) # may differ of one or two seconds ? may! expected_expiration = utility.get_future_epoch(GLSetting.defaults.lifetimes[auth_request['role']]) expiration_date = self.responses[0]['session_expiration'] self.assertApproximates(expected_expiration, expiration_date, 2)
def generate_session(self, role, user_id): """ Args: role: can be either 'admin', 'wb' or 'receiver' user_id: will be in the case of the receiver the receiver.id in the case of an admin it will be set to 'admin', in the case of the 'wb' it will be the whistleblower id. """ self.session_id = rstr.xeger(r'[A-Za-z0-9]{42}') # This is the format to preserve sessions in memory # Key = session_id, values "last access" "id" "role" new_session = OD( refreshdate=utility.datetime_now(), id=self.session_id, role=role, user_id=user_id, expirydate=utility.get_future_epoch(seconds=GLSetting.defaults.lifetimes[role]) ) GLSetting.sessions[self.session_id] = new_session return self.session_id