diff --git a/django_altcha/__init__.py b/django_altcha/__init__.py index 83c23ce..256c1c8 100644 --- a/django_altcha/__init__.py +++ b/django_altcha/__init__.py @@ -60,14 +60,14 @@ def mark_challenge_used(challenge, timeout): def get_altcha_challenge(max_number=None, expires=None): """ - Generate and return an ALTCHA challenge. + Generate and return an ALTCHA v1 challenge. Attributes: max_number (int): Maximum number to use for the challenge. expires (int): Expiration time for the challenge in milliseconds. Returns: - altcha.Challenge: The generated challenge. + altcha.ChallengeV1: The generated challenge. """ expires = expires or get_setting("ALTCHA_CHALLENGE_EXPIRE") options = { @@ -78,7 +78,7 @@ def get_altcha_challenge(max_number=None, expires=None): if max_number is not None: options["max_number"] = max_number - challenge = altcha.create_challenge(altcha.ChallengeOptions(**options)) + challenge = altcha.create_challenge_v1(altcha.ChallengeOptionsV1(**options)) return challenge @@ -246,7 +246,7 @@ def validate(self, value): ) try: - verified, error = altcha.verify_solution( + verified, error = altcha.verify_solution_v1( payload=value, hmac_key=get_hmac_key(), check_expires=True, diff --git a/pyproject.toml b/pyproject.toml index b54d96c..14b5d2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ requires-python = ">=3.9" dependencies = [ "Django>=4.2", - "altcha>=1.0.0,<2.0.0", + "altcha>=2.0.0,<3.0.0", ] keywords = ["captcha", "django", "widget", "form", "altcha"] diff --git a/tests/test_field.py b/tests/test_field.py index eb736ce..7002c01 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -60,7 +60,7 @@ def test_altcha_field_with_missing_value_raises_required_error(self): form.errors["altcha_field"][0], "ALTCHA CAPTCHA token is missing." ) - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_altcha_field_validation_calls_verify_solution(self, mock_verify_solution): self.assertFalse(is_challenge_used(TEST_CHALLENGE)) mock_verify_solution.return_value = (True, None) @@ -81,7 +81,7 @@ def test_altcha_field_validation_calls_verify_solution(self, mock_verify_solutio form.errors["altcha_field"][0], "Challenge has already been used." ) - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_altcha_field_validation_fails_on_invalid_token(self, mock_verify_solution): mock_verify_solution.return_value = (False, "Invalid token") form = self.form_class(data={"altcha_field": "invalid_token"}) @@ -89,7 +89,7 @@ def test_altcha_field_validation_fails_on_invalid_token(self, mock_verify_soluti self.assertIn("altcha_field", form.errors) self.assertEqual(form.errors["altcha_field"][0], "Invalid CAPTCHA token.") - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_altcha_field_validation_handles_exception(self, mock_verify_solution): mock_verify_solution.side_effect = Exception("Verification failed") form = self.form_class(data={"altcha_field": "some_token"}) diff --git a/tests/test_logging.py b/tests/test_logging.py index fbe1857..1571a30 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -24,7 +24,7 @@ class TestForm(forms.Form): self.form_class = TestForm - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_invalid_token_logs_warning(self, mock_verify_solution): mock_verify_solution.return_value = (False, "bad signature") form = self.form_class(data={"altcha_field": "anything"}) @@ -34,7 +34,7 @@ def test_invalid_token_logs_warning(self, mock_verify_solution): self.assertEqual(captured.records[0].levelname, "WARNING") self.assertIn("bad signature", captured.output[0]) - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_verification_exception_is_logged_with_traceback( self, mock_verify_solution ): @@ -46,7 +46,7 @@ def test_verification_exception_is_logged_with_traceback( # Confirms traceback is captured self.assertIsNotNone(captured.records[0].exc_info) - @mock.patch("altcha.verify_solution") + @mock.patch("altcha.verify_solution_v1") def test_replay_attempt_logs_warning(self, mock_verify_solution): mock_verify_solution.return_value = (True, None) valid_payload = make_valid_payload(challenge="replay-test-1")