当前位置: 首页>>代码示例>>Python>>正文


Python Token.set_difficulty方法代码示例

本文整理汇总了Python中globaleaks.utils.token.Token.set_difficulty方法的典型用法代码示例。如果您正苦于以下问题:Python Token.set_difficulty方法的具体用法?Python Token.set_difficulty怎么用?Python Token.set_difficulty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在globaleaks.utils.token.Token的用法示例。


在下文中一共展示了Token.set_difficulty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_token_validate

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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}
        )
开发者ID:RuanAragao,项目名称:GlobaLeaks,代码行数:35,代码来源:test_token.py

示例2: post

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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)
开发者ID:RuanAragao,项目名称:GlobaLeaks,代码行数:33,代码来源:submission.py

示例3: test_token_create_and_get_upload_expire

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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))
开发者ID:alitalia,项目名称:GlobaLeaks,代码行数:36,代码来源:test_token.py

示例4: post

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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)
开发者ID:alitalia,项目名称:GlobaLeaks,代码行数:32,代码来源:submission.py

示例5: test_token_obj_zero_stress

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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)
开发者ID:RuanAragao,项目名称:GlobaLeaks,代码行数:16,代码来源:test_token.py

示例6: test_token_obj_level1_stress

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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)
开发者ID:alitalia,项目名称:GlobaLeaks,代码行数:21,代码来源:test_token.py

示例7: test_token_obj_level1_stress

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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)
开发者ID:RuanAragao,项目名称:GlobaLeaks,代码行数:25,代码来源:test_token.py

示例8: test_token_validate

# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import set_difficulty [as 别名]
    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})
开发者ID:alitalia,项目名称:GlobaLeaks,代码行数:25,代码来源:test_token.py


注:本文中的globaleaks.utils.token.Token.set_difficulty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。