コード例 #1
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)
コード例 #2
0
ファイル: submission.py プロジェクト: RuanAragao/GlobaLeaks
    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
0
ファイル: submission.py プロジェクト: alitalia/GlobaLeaks
    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)
コード例 #4
0
ファイル: test_token.py プロジェクト: RuanAragao/GlobaLeaks
    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)
コード例 #5
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)
コード例 #6
0
ファイル: test_token.py プロジェクト: alitalia/GlobaLeaks
    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)
コード例 #7
0
ファイル: test_token.py プロジェクト: RuanAragao/GlobaLeaks
    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)
コード例 #8
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)