Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        orig_question = u'77+33'
        token.human_captcha = {
            'question': orig_question,
            'answer': 1,
            'solved': False
        }

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

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

        self.assertFalse(token.human_captcha['solved'])

        self.assertEqual(new_token['human_captcha'],
                         token.human_captcha['question'])
        self.assertNotEqual(new_token['human_captcha'], orig_question)

        self.assertIsNot(new_token['human_captcha'], False)
        self.assertNotIn('human_captcha_anwser', new_token)
Exemplo n.º 5
0
 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])
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
 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)
     response = yield handler.put(token.id)
     returnValue(response['receipt'])
Exemplo n.º 8
0
    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())
Exemplo n.º 9
0
    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)
Exemplo n.º 10
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']
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
0
 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])
Exemplo n.º 14
0
    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)
Exemplo n.º 15
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")
Exemplo n.º 16
0
    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()
Exemplo n.º 17
0
    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()
Exemplo n.º 18
0
    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')
Exemplo n.º 19
0
 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)
     response = yield handler.put(token.id)
     returnValue(response)
Exemplo n.º 20
0
    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')
Exemplo n.º 21
0
    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)
Exemplo n.º 22
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" )
Exemplo n.º 23
0
    def test_token_update_right_answer(self):
        token = Token('submission')

        token.human_captcha = {'question': '1 + 0','answer': 1}

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

        # verify that the challenge is changed
        self.assertFalse(token.human_captcha)
Exemplo n.º 24
0
    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))
Exemplo n.º 25
0
    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))
Exemplo n.º 26
0
    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)
Exemplo n.º 27
0
    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'])
Exemplo n.º 28
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)
Exemplo n.º 29
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        # This is at the beginning
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield anomaly.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
Exemplo n.º 30
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        # This is at the beginning
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield anomaly.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
Exemplo n.º 31
0
    def test_token_obj_zero_stress(self):

        # This is at the beginning
        anomaly.EventTrackQueue.reset()

        # Token submission
        st = Token('submission', context_id="ignored")
        st.set_difficulty(TestToken.shared_alarm_obj.get_token_difficulty())

        for indicator in TestToken.stress_indicator:
            self.assertFalse(getattr(st, indicator), indicator)

        st_dict = st.serialize_token()
        self.assertEqual(st_dict['remaining_allowed_attempts'], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
Exemplo n.º 32
0
    def test_token_validate(self):
        # This is at the beginning
        event.EventTrackQueue.reset()

        token = Token('submission', context_id='ignored')

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

        token.set_difficulty(difficulty)

        token = TokenList.get(token.token_id)
        token.human_captcha = {'answer': 1}
        token.remaining_allowed_attempts = 1

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

        # validate with wrong value: FAIL
        self.assertRaises(errors.TokenFailure, token.validate,
                          {'human_captcha_answer': 0})

        # validate with right value but with no additional
        # attemps available: FAIL
        self.assertRaises(errors.TokenFailure, token.validate,
                          {'human_captcha_answer': 1})
Exemplo n.º 33
0
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')

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

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

        handler = self.request(request_payload)
        self.assertRaises(errors.TokenFailure, handler.put, token.id)
Exemplo n.º 34
0
    def test_put_wrong_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

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

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

        handler = self.request(request_payload)
        self.assertRaises(errors.TokenFailure, handler.put, token.id)
Exemplo n.º 35
0
    def test_token_obj_zero_stress(self):

        # This is at the beginning
        event.EventTrackQueue.reset()

        # Token submission
        st = Token('submission', context_id="ignored")
        st.set_difficulty(TestToken.shared_alarm_obj.get_token_difficulty())

        for indicator in TestToken.stress_indicator:
            self.assertFalse(getattr(st, indicator), indicator)

        st_dict = st.serialize_token()
        self.assertEqual(st_dict['remaining_allowed_attempts'],
                         Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
Exemplo n.º 36
0
    def test_token_create_and_get_upload_expire(self):
        file_list = []

        token_collection = []
        for _ in range(20):
            st = Token(1, 'submission')
            token_collection.append(st)

        for t in token_collection:
            token = TokenList.get(t.id)

            self.emulate_file_upload(token, 3)

            for f in token.uploaded_files:
                filepath = os.path.abspath(os.path.join(self.state.settings.tmp_path, f['filename']))
                self.assertTrue(os.path.exists(filepath))
                file_list.append(filepath)

        self.test_reactor.advance(TokenList.get_timeout() + 1)

        for t in token_collection:
            self.assertRaises(errors.TokenFailure, TokenList.get, t.id)

            for filepath in file_list:
                self.assertFalse(os.path.exists(filepath))
Exemplo n.º 37
0
    def test_put(self):
        self.submission_desc = yield self.get_dummy_submission(
            self.dummyContext['id'])
        token = Token('submission', self.dummyContext['id'])

        handler = self.request(self.submission_desc)
        yield handler.put(token.token_id)
Exemplo n.º 38
0
    def test_token_create_and_get_upload_expire(self):
        file_list = []

        token_collection = []
        for i in xrange(20):
            st = Token('submission')

            token_collection.append(st)

        for t in token_collection:
            token = TokenList.get(t.id)

            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'])

        TokenList.reactor.pump([1] * TokenList.get_timeout())

        for t in token_collection:
            self.assertRaises(errors.TokenFailure, TokenList.get, t.id)

            for f in file_list:
                self.assertFalse(os.path.exists(f))
Exemplo n.º 39
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)
Exemplo n.º 40
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)
Exemplo n.º 41
0
    def test_token_validate(self):
        # This is at the beginning
        anomaly.EventTrackQueue.reset()

        token = Token('submission', context_id='ignored')

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

        token.set_difficulty(difficulty)

        token = TokenList.get(token.token_id)
        token.human_captcha = { 'answer': 1 }
        token.remaining_allowed_attempts = 1

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

        # validate with wrong value: FAIL
        self.assertRaises(
            errors.TokenFailure,
            token.validate, {'human_captcha_answer': 0}
        )

        # validate with right value but with no additional
        # attemps available: FAIL
        self.assertRaises(
            errors.TokenFailure,
            token.validate, {'human_captcha_answer': 1}
        )
Exemplo n.º 42
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}))
Exemplo n.º 43
0
    def test_put_right_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield anomaly.compute_activity_level()

        token = Token('submission')

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

        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)
Exemplo n.º 44
0
    def test_tokens_garbage_collected(self):
        self.assertTrue(len(TokenList) == 0)

        for i in range(100):
            Token('submission')

        self.test_reactor.advance(TokenList.get_timeout() + 1)

        self.assertTrue(len(TokenList) == 0)
Exemplo n.º 45
0
    def test_put_right_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield anomaly.compute_activity_level()

        token = Token('submission')

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

        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)
Exemplo n.º 46
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()
Exemplo n.º 47
0
    def test_token_usage_limit(self):
        token = Token('submission')
        token.solve()

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

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

        for _ in range(token.MAX_USES-1):
            token.use()

        # validate with right value but with no additional
        # attempts available: FAIL
        self.assertRaises(errors.TokenFailure, token.use)
Exemplo n.º 48
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 = dict(MockDict().dummyReceiver)
        yanr['name'] = u"Receiver1"
        yanr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        yanr['contexts'] = [ new_context_output['id']]
        yanr_output = yield create_receiver(yanr, 'en')
        self.receiver_assertions(yanr, yanr_output)

        asdr = dict(MockDict().dummyReceiver)
        asdr['name'] = u"Receiver2"
        asdr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        asdr['contexts'] = [ new_context_output['id']]
        asdr_output = yield 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['wb_steps'] = yield self.fill_random_answers(new_context_output['id'])

        token = Token('submission')
        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 get_files_by_itip(new_subm_output['id'])

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(ifilist), 3)

        rfilist = yield get_receiverfile_by_itip(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" )
Exemplo n.º 49
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')
        token.human_captcha = {'question': 'XXX','answer': 1, 'solved': False}
        token.proof_of_work['solved'] = True

        request_payload = token.serialize()
        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)

        yield handler.put(token.id)

        token.use()

        self.assertFalse(self.responses[0]['human_captcha'])
        self.assertTrue(token.human_captcha['solved'])
Exemplo n.º 50
0
    def test_token_obj_level1_stress(self):

        mock_high_difficulty = {"human_captcha": True, "graph_captcha": True, "proof_of_work": True}

        # Token submission
        st = Token("submission", context_id="ignored")
        st.set_difficulty(mock_high_difficulty)

        st_dict = st.serialize_token()

        if st.graph_captcha:
            self.assertTrue(st.graph_captcha.has_key("answer"))
            self.assertTrue(isinstance(st.graph_captcha["answer"], list))

        if st.human_captcha:
            self.assertTrue(st.human_captcha.has_key("answer"))
            self.assertTrue(isinstance(st.human_captcha["answer"], unicode))

        self.assertEqual(st_dict["remaining_allowed_attempts"], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
Exemplo n.º 51
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')
        token.human_captcha = {'question': 'XXX', 'answer': 1, 'solved': False}
        token.proof_of_work['solved'] = True

        request_payload = token.serialize()
        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)

        response = yield handler.put(token.id)

        token.use()

        self.assertFalse(response['human_captcha'])
        self.assertTrue(token.human_captcha['solved'])
Exemplo n.º 52
0
    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))
Exemplo n.º 53
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')
Exemplo n.º 54
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')
Exemplo n.º 55
0
    def test_token_usage_limit(self):
        token = Token('submission')
        token.solve()

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

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

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

        # validate with right value but with no additional
        # attempts available: FAIL
        self.assertRaises(errors.TokenFailure, token.use)
Exemplo n.º 56
0
    def test_token_obj_level1_stress(self):

        mock_high_difficulty = {
            'human_captcha': True,
            'graph_captcha': True,
            'proof_of_work': True,
        }

        # Token submission
        st = Token('submission', context_id='ignored')
        st.set_difficulty(mock_high_difficulty)

        st_dict = st.serialize_token()

        if st.graph_captcha:
            self.assertTrue(st.graph_captcha.has_key('answer'))
            self.assertTrue(isinstance(st.graph_captcha['answer'], list))

        if st.human_captcha:
            self.assertTrue(st.human_captcha.has_key('answer'))
            self.assertTrue(isinstance(st.human_captcha['answer'], unicode))

        self.assertEqual(st_dict['remaining_allowed_attempts'], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
Exemplo n.º 57
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)
Exemplo n.º 58
0
    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())
Exemplo n.º 59
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
        )