コード例 #1
0
ファイル: test_token.py プロジェクト: zshell/GlobaLeaks
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        TokenList.clear()

        self.pollute_events()

        yield anomalies.Anomalies().run()
コード例 #2
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        self.state.tokens.clear()

        self.pollute_events()

        yield anomalies.Anomalies().run()
コード例 #3
0
ファイル: test_token.py プロジェクト: crosstuck/GlobaLeaks
    def test_post(self):
        yield anomalies.Anomalies().run()

        handler = self.request({'type': 'submission'})

        handler.request.client_using_tor = True

        response = yield handler.post()

        self.assert_default_token_values(response)
コード例 #4
0
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield anomalies.Anomalies().run()

        token = self.getToken()

        request_payload = token.serialize()
        request_payload['answer'] = 0

        handler = self.request(request_payload)

        yield handler.put(token.id)

        self.assertRaises(Exception, token.tokenlist.use, token.id)
コード例 #5
0
    def test_anomalies(self):
        self.n = 0

        full_ammo = 1000000

        original_get_disk_anomaly_conditions = anomaly.get_disk_anomaly_conditions

        conditions_count = len(
            original_get_disk_anomaly_conditions(full_ammo, full_ammo))

        def mock_get_disk_anomaly_conditions(*args, **kwargs):
            conditions = original_get_disk_anomaly_conditions(*args, **kwargs)
            # activate one condition at once
            for condition in enumerate(conditions):
                conditions[condition[0]]['condition'] = (
                    condition[0] == self.n)

            return conditions

        anomaly.get_disk_anomaly_conditions = mock_get_disk_anomaly_conditions

        # testing the scheduler with all the conditions unmet
        self.n = -1
        yield anomalies.Anomalies().run()

        # testing the scheduler enabling all conditions one at once
        for j in range(conditions_count):
            self.n = j
            yield anomalies.Anomalies().run()

        yield anomalies.Anomalies().run()

        # testing the scheduler with all the conditions unmet
        # a second time in order test the accept_submissions value
        self.n = -1
        yield anomalies.Anomalies().run()
コード例 #6
0
ファイル: test_token.py プロジェクト: crosstuck/GlobaLeaks
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield anomalies.Anomalies().run()

        token = self.state.tokens.new(1, 'submission')
        token.solved = False
        token.question = '7GJ4Sl37AEnP10Zk9p7q'

        request_payload = token.serialize()
        request_payload['answer'] = 0

        handler = self.request(request_payload)

        response = yield handler.put(token.id)

        self.assertRaises(Exception, token.use)
コード例 #7
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield anomalies.Anomalies().run()

        token = self.getToken()

        request_payload = token.serialize()
        request_payload['answer'] = token.answer

        handler = self.request(request_payload)

        yield handler.put(token.id)

        token.tokenlist.use(token.id)

        self.assertTrue(token.solved)
コード例 #8
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield anomalies.Anomalies().run()

        token = Token(1, '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'])
コード例 #9
0
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield anomalies.Anomalies().run()

        token = Token(1, '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)