Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions django_altcha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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


Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 3 additions & 3 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -81,15 +81,15 @@ 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"})
self.assertFalse(form.is_valid())
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"})
Expand Down
6 changes: 3 additions & 3 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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
):
Expand All @@ -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")
Expand Down