Exemple #1
0
    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']
    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)
Exemple #3
0
    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)
Exemple #4
0
    def test_submission_file_delivery_pgp(self):
        new_fields = MockDict().dummyFields
        new_context = MockDict().dummyContext

        new_context['name'] = "Context Name"
        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")
Exemple #5
0
    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" )
Exemple #6
0
    def test_proof_of_work_right_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}

        # validate with right value: OK
        self.assertTrue(token.update({'proof_of_work_answer': 26}))
        token.use()
Exemple #7
0
    def test_proof_of_work_right_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}

        # validate with right value: OK
        self.assertTrue(token.update({'proof_of_work_answer': 26}))
        token.use()
    def test_proof_of_work_wrong_answer(self):
        token = Token(1, '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)
Exemple #9
0
    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)
Exemple #10
0
    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)
Exemple #11
0
    def test_token_uses_limit(self):
        token = Token('submission')

        token.human_captcha = False
        token.proof_of_work = False

        # validate with right value: OK
        token.update({'human_captcha_answer': 1})

        for i in range(0, token.MAX_USES):
            token.use()

        # validate with right value but with no additional
        # attempts available: FAIL
        self.assertRaises(errors.TokenFailure, token.use)
Exemple #12
0
    def test_put_right_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX','answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertEqual(self.responses[0]['human_captcha'], False)
Exemple #13
0
    def test_put_right_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX', 'answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertEqual(self.responses[0]['human_captcha'], False)
Exemple #14
0
    def test_proof_of_work_right_answer(self):
        token = Token('submission')

        difficulty = {
            'human_captcha': False,
            'proof_of_work': False
        }

        token.generate_token_challenge(difficulty)

        token = TokenList.get(token.id)
        # 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"}

        # validate with right value: OK
        self.assertTrue(token.update({'proof_of_work_answer': 0}))
Exemple #15
0
    def test_proof_of_work_right_answer(self):
        token = Token('submission')

        difficulty = {
            'human_captcha': False,
            'graph_captcha': False,
            'proof_of_work': False
        }

        token.generate_token_challenge(difficulty)

        token = TokenList.get(token.id)
        # 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" }

        # validate with right value: OK
        self.assertTrue(token.update({'proof_of_work_answer': 0}))
Exemple #16
0
    def test_token_uses_limit(self):
        token = Token('submission')

        token.human_captcha = False
        token.proof_of_work = False

        # validate with right value: OK
        token.update({'human_captcha_answer': 1})

        for i in range(0, token.MAX_USES):
            token.use()

        # validate with right value but with no additional
        # attempts available: FAIL
        self.assertRaises(
            errors.TokenFailure,
            token.use
        )
Exemple #17
0
    def test_put_wrong_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX','answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 2

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertNotEqual(self.responses[0]['human_captcha'], False)

        # verify that the question is changed
        self.assertNotEqual(self.responses[0]['human_captcha'], 'XXX')
Exemple #18
0
    def test_put_wrong_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX', 'answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 2

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertNotEqual(self.responses[0]['human_captcha'], False)

        # verify that the question is changed
        self.assertNotEqual(self.responses[0]['human_captcha'], 'XXX')
Exemple #19
0
    def test_proof_of_work_right_answer(self):
        # This is at the beginning
        event.EventTrackQueue.reset()

        token = Token('submission')

        difficulty = {
            'human_captcha': False,
            'graph_captcha': False,
            'proof_of_work': False
        }

        token.generate_token_challenge(difficulty)

        token = TokenList.get(token.id)
        # 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" }

        # validate with right value: OK
        self.assertFalse(token.update({'proof_of_work_answer': 26}))

        # verify that the challenge is marked as solved
        self.assertFalse(token.proof_of_work)
Exemple #20
0
    def test_proof_of_work_right_answer(self):
        # This is at the beginning
        event.EventTrackQueue.reset()

        token = Token('submission')

        difficulty = {
            'human_captcha': False,
            'graph_captcha': False,
            'proof_of_work': False
        }

        token.generate_token_challenge(difficulty)

        token = TokenList.get(token.id)
        # 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"}

        # validate with right value: OK
        self.assertFalse(token.update({'proof_of_work_answer': 26}))

        # verify that the challenge is marked as solved
        self.assertFalse(token.proof_of_work)
 def create_submission_with_files(self, request):
     token = Token('submission')
     token.proof_of_work = False
     yield self.emulate_file_upload(token, 3)
     output = yield create_submission(token.id, request, False, 'en')
     returnValue(output)
Exemple #22
0
 def create_submission(self, request):
     token = Token('submission')
     token.proof_of_work = False
     output = yield create_submission(token.id, request, True, 'en')
     returnValue(output)
 def create_submission(self, request):
     token = Token('submission')
     token.proof_of_work = False
     output = yield create_submission(token.id, request, True, 'en')
     returnValue(output)
Exemple #24
0
 def create_submission_with_files(self, request):
     token = Token('submission')
     token.proof_of_work = False
     yield self.emulate_file_upload(token, 3)
     output = yield create_submission(token.id, request, False, 'en')
     returnValue(output)