def post(self): """ Request: None Response: TokenDesc (Token) Errors: InvalidInputFormat This API create a Token, a temporary memory only object able to keep track of the submission. If the system is under stress, complete the submission will require some actions to be performed before the submission can be concluded (e.g. hashcash and captchas). """ request = self.validate_message(self.request.body, requests.TokenReqDesc) if request['type'] == 'submission': if not GLSettings.accept_submissions: raise errors.SubmissionDisabled # TODO implement further validations for different token options based on type # params = self.validate_message(request['params'], requests.TokenParamsSubmissionDesc) token = Token(request['type']) self.set_status(201) # Created self.write(token.serialize())
def post(self): """ Request: None Response: TokenDesc (Token) Errors: InvalidInputFormat This API create a Token, a temporary memory only object able to keep track of the submission. If the system is under stress, complete the submission will require some actions to be performed before the submission can be concluded (e.g. hashcash and captchas). """ if not self.request.client_using_tor and not State.tenant_cache[ 1].accept_tor2web_access['whistleblower']: raise errors.TorNetworkRequired request = self.validate_message(self.request.content.read(), requests.TokenReqDesc) if request['type'] == 'submission' and not State.accept_submissions: raise errors.SubmissionDisabled token = Token(request['type']) if not self.request.client_using_tor and (self.request.client_proto == 'http' and \ self.request.hostname not in ['127.0.0.1', 'localhost']): # Due to https://github.com/globaleaks/GlobaLeaks/issues/2088 the proof of work if currently # implemented only over Tor and HTTPS that are the production conditions. token.proof_of_work['solved'] = True return token.serialize()
def test_token(self): st = Token('submission') st_dict = st.serialize() self.assertEqual(st_dict['remaining_uses'], Token.MAX_USES) if st.human_captcha: self.assertTrue(st.human_captcha.has_key('answer')) self.assertTrue(isinstance(st.human_captcha['answer'], int))
def post(self): """ Request: None Response: TokenDesc (Token) Errors: InvalidInputFormat This API create a Token, a temporary memory only object able to keep track of the submission. If the system is under stress, complete the submission will require some actions to be performed before the submission can be concluded (e.g. hashcash and captchas). """ request = self.validate_message(self.request.body, requests.TokenReqDesc) if request['type'] == 'submission': if not GLSettings.memory_copy.accept_submissions: raise errors.SubmissionDisabled # TODO implement further validations for different token options based on type # params = self.validate_message(request['params'], requests.TokenParamsSubmissionDesc) token = Token(request['type']) self.set_status(201) # Created self.finish(token.serialize())