本文整理汇总了Python中globaleaks.utils.token.Token类的典型用法代码示例。如果您正苦于以下问题:Python Token类的具体用法?Python Token怎么用?Python Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_tip_environment
def setup_tip_environment(self):
self.context_desc = yield admin.context.create_context(self.dummyContext, 'en')
self.dummyReceiver_1['contexts'] = self.dummyReceiver_2['contexts'] = [self.context_desc['id']]
self.dummyReceiver_1['can_postpone_expiration'] = False
self.dummyReceiver_2['can_postpone_expiration'] = True
self.dummyReceiver_1['can_delete_submission'] = True
self.dummyReceiver_2['can_delete_submission'] = False
self.receiver1_desc = yield admin.receiver.create_receiver(self.dummyReceiver_1, 'en')
self.receiver2_desc = yield admin.receiver.create_receiver(self.dummyReceiver_2, 'en')
self.assertEqual(self.receiver1_desc['contexts'], [ self.context_desc['id']])
self.assertEqual(self.receiver2_desc['contexts'], [ self.context_desc['id']])
dummySubmissionDict = yield self.get_dummy_submission(self.context_desc['id'])
token = Token(token_kind='submission')
token.proof_of_work = False
self.submission_desc = yield submission.create_submission(token.id, dummySubmissionDict, False, 'en')
self.assertEqual(self.submission_desc['answers'], dummySubmissionDict['answers'])
tips_receiver_1 = yield receiver.get_receivertip_list(self.receiver1_desc['id'], 'en')
tips_receiver_2 = yield receiver.get_receivertip_list(self.receiver2_desc['id'], 'en')
self.rtip1_id = tips_receiver_1[0]['id']
self.rtip2_id = tips_receiver_2[0]['id']
self.rtip1_questionnaire_hash = tips_receiver_1[0]['questionnaire_hash']
self.rtip1_questionnaire_hash = tips_receiver_2[0]['questionnaire_hash']
示例2: post
def post(self):
"""
Request: SubmissionDesc
Response: SubmissionDesc
Errors: ContextIdNotFound, InvalidInputFormat, SubmissionFailFields
This creates an empty submission for the requested context,
and returns submissionStatus with empty fields and a Submission Unique String,
This is the unique token used during the submission procedure.
header session_id is used as authentication secret for the next interaction.
expire after the time set by Admin (Context dependent setting)
--- has to became:
Request: empty
Response: SubmissionDesc + Token
Errors: None
This create a Token, require to complete the submission later
"""
request = self.validate_message(self.request.body, requests.SubmissionDesc)
token = Token('submission', request['context_id'])
token.set_difficulty(Alarm().get_token_difficulty())
token_answer = token.serialize_token()
token_answer.update({'id': token_answer['token_id']})
token_answer.update({'context_id': request['context_id']})
token_answer.update({'human_captcha_answer': 0})
self.set_status(201) # Created
self.finish(token_answer)
示例3: create_submission
def create_submission(self, request):
token = Token("submission")
token.solve()
self.submission_desc = yield self.get_dummy_submission(self.dummyContext["id"])
handler = self.request(self.submission_desc)
yield handler.put(token.id)
returnValue(self.responses[0])
示例4: post
def post(self):
"""
Request: None
Response: SubmissionDesc (Token)
Errors: ContextIdNotFound, InvalidInputFormat, SubmissionValidationFailure
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 GLSettings.memory_copy.accept_submissions:
raise errors.SubmissionDisabled
request = self.validate_message(self.request.body, requests.SubmissionDesc)
token = Token('submission', request['context_id'])
token.set_difficulty(Alarm().get_token_difficulty())
token_answer = token.serialize_token()
token_answer.update({'id': token_answer['token_id']})
token_answer.update({'context_id': request['context_id']})
token_answer.update({'receivers': []})
token_answer.update({'answers': {}})
token_answer.update({'human_captcha_answer': 0})
token_answer.update({'graph_captcha_answer': ""})
token_answer.update({'proof_of_work': 0})
self.set_status(201) # Created
self.finish(token_answer)
示例5: test_token_create_and_get_upload_expire
def test_token_create_and_get_upload_expire(self):
# This is at the beginning
event.EventTrackQueue.reset()
file_list = []
token_collection = []
for i in xrange(20):
st = Token("submission", context_id="ignored")
st.set_difficulty(TestToken.shared_alarm_obj.get_token_difficulty())
token_collection.append(st)
for t in token_collection:
token = TokenList.get(t.id)
difficulty = {"human_captcha": True, "graph_captcha": False, "proof_of_work": False}
token.set_difficulty(difficulty)
self.assertRaises(errors.TokenFailure, token.validate, {"human_captcha_answer": 0})
yield self.emulate_file_upload(token, 3)
for f in token.uploaded_files:
self.assertTrue(os.path.exists(f["encrypted_path"]))
file_list.append(f["encrypted_path"])
token.expire()
self.assertRaises(errors.TokenFailure, TokenList.get, t.id)
for f in file_list:
self.assertFalse(os.path.exists(f))
示例6: test_put
def test_put(self):
self.submission_desc = yield self.get_dummy_submission(self.dummyContext['id'])
token = Token('submission')
token.proof_of_work = False
handler = self.request(self.submission_desc)
yield handler.put(token.id)
示例7: create_submission_with_files
def create_submission_with_files(self, request):
token = Token("submission")
token.solve()
yield self.emulate_file_upload(token, 3)
self.submission_desc = yield self.get_dummy_submission(self.dummyContext["id"])
handler = self.request(self.submission_desc)
result = yield handler.put(token.id)
returnValue(self.responses[0])
示例8: test_token_reuse_blocked
def test_token_reuse_blocked(self):
token = Token()
token.solve()
self.submission_desc = yield self.get_dummy_submission(self.dummyContext["id"])
handler = self.request(self.submission_desc)
yield handler.put(token.id)
yield self.assertFailure(handler.put(token.id), errors.TokenFailure)
示例9: test_token_update_wrong_answer
def test_token_update_wrong_answer(self):
token = Token('submission')
token.human_captcha = {'question': 'XXX','answer': 1}
token.update({'human_captcha_answer': 0})
# verify that the challenge is changed
self.assertNotEqual(token.human_captcha['question'], 'XXX')
示例10: setUp
def setUp(self):
yield helpers.TestGL.setUp(self)
pollute_events_for_testing()
yield Alarm.compute_activity_level()
# Token submission
st = Token('submission')
st.generate_token_challenge()
示例11: test_submission_file_delivery_pgp
def test_submission_file_delivery_pgp(self):
new_fields = MockDict().dummyFields
new_context = MockDict().dummyContext
new_context['name'] = "this uniqueness is no more checked due to the lang"
new_context_output = yield create_context(new_context, 'en')
self.context_assertions(new_context, new_context_output)
doubletest = yield get_context_list('en')
self.assertEqual(len(doubletest), 2)
yanr = self.get_dummy_receiver("antani1")
yanr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
yanr['contexts'] = [ new_context_output['id']]
yanr_output = yield receiver.create_receiver(yanr, 'en')
self.receiver_assertions(yanr, yanr_output)
asdr = self.get_dummy_receiver("antani2")
asdr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
asdr['contexts'] = [ new_context_output['id']]
asdr_output = yield receiver.create_receiver(asdr, 'en')
self.receiver_assertions(asdr, asdr_output)
new_subm = dict(MockDict().dummySubmission)
new_subm['finalize'] = False
new_subm['context_id'] = new_context_output['id']
new_subm['receivers'] = [ asdr_output['id'],
yanr_output['id'] ]
new_subm['identity_provided'] = False
new_subm['answers'] = yield self.fill_random_answers(new_context_output['id'])
token = Token('submission')
token.proof_of_work = False
yield self.emulate_file_upload(token, 3)
new_subm_output = yield submission.create_submission(token.id, new_subm, False, 'en')
yield DeliverySchedule().operation()
# now get a lots of receivertips/receiverfiles and check!
ifilist = yield self.get_internalfiles_by_wbtip(new_subm_output['id'])
self.assertTrue(isinstance(ifilist, list))
self.assertEqual(len(ifilist), 3)
rfilist = yield self.get_receiverfiles_by_wbtip(new_subm_output['id'])
self.assertTrue(isinstance(ifilist, list))
self.assertEqual(len(rfilist), 6)
for i in range(0, 3):
self.assertLess(ifilist[0]['size'], rfilist[i]['size'])
self.assertEqual(rfilist[0]['status'], u"encrypted" )
示例12: test_token
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))
示例13: test_token_update_right_answer
def test_token_update_right_answer(self):
token = Token('submission')
token.human_captcha = {'question': '1 + 0','answer': 1}
token.proof_of_work = False
# validate with right value: OK
token.update({'human_captcha_answer': 1})
# verify that the challenge is marked as solved
self.assertFalse(token.human_captcha)
示例14: test_proof_of_work_wrong_answer
def test_proof_of_work_wrong_answer(self):
token = Token('submission')
token.solve()
# Note, this solution works with two '00' at the end, if the
# difficulty changes, also this dummy value has to.
token.proof_of_work = {'question': "7GJ4Sl37AEnP10Zk9p7q", 'solved': False}
self.assertFalse(token.update({'proof_of_work_answer': 0}))
# validate with right value: OK
self.assertRaises(errors.TokenFailure, token.use)
示例15: test_token_update_right_answer
def test_token_update_right_answer(self):
token = Token('submission')
token.solve()
token.human_captcha = {'question': '1 + 0', 'answer': 1, 'solved': False}
# validate with right value: OK
self.assertTrue(token.update({'human_captcha_answer': 1}))
# verify that the challenge is marked as solved
self.assertTrue(token.human_captcha['solved'])