Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 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)
Exemplo n.º 10
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.º 11
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.º 12
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)
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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
        )
Exemplo n.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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})