-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds altcha in addition to existing match captcha. Issue #1462
- Loading branch information
Showing
15 changed files
with
206 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@altcha/crypto@^0.0.1": | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/@altcha/crypto/-/crypto-0.0.1.tgz#0e2f254559fb350c80ff56d29b8e3ab2e6bbea95" | ||
integrity sha512-qZMdnoD3lAyvfSUMNtC2adRi666Pxdcw9zqfMU5qBOaJWqpN9K+eqQGWqeiKDMqL0SF+EytNG4kR/Pr/99GJ6g== | ||
|
||
"@discoveryjs/json-ext@^0.5.0": | ||
version "0.5.7" | ||
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" | ||
|
@@ -47,6 +52,11 @@ | |
"@jridgewell/resolve-uri" "^3.1.0" | ||
"@jridgewell/sourcemap-codec" "^1.4.14" | ||
|
||
"@rollup/[email protected]": | ||
version "4.18.0" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.18.0.tgz#1a7481137a54740bee1ded4ae5752450f155d942" | ||
integrity sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w== | ||
|
||
"@sentry-internal/[email protected]": | ||
version "8.37.1" | ||
resolved "https://registry.yarnpkg.com/@sentry-internal/browser-utils/-/browser-utils-8.37.1.tgz#374028d8e37047aeda14b226707e6601de65996e" | ||
|
@@ -322,6 +332,15 @@ ajv@^6.12.5: | |
json-schema-traverse "^0.4.1" | ||
uri-js "^4.2.2" | ||
|
||
[email protected]: | ||
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/altcha/-/altcha-1.0.6.tgz#415ab2b52d4936bb50f95316fd854435dccd2705" | ||
integrity sha512-H5bXDfbn/H9UQhW4kVdqPPRODvFsdOrftPUQ/hFWehjhV0LI8Mnq67knvJqCC3mw+s06h4KbIYGw43uVHCHEtQ== | ||
dependencies: | ||
"@altcha/crypto" "^0.0.1" | ||
optionalDependencies: | ||
"@rollup/rollup-linux-x64-gnu" "4.18.0" | ||
|
||
[email protected]: | ||
version "6.0.1" | ||
resolved "https://registry.yarnpkg.com/autosize/-/autosize-6.0.1.tgz#64ee78dd7029be959eddd3afbbd33235b957e10f" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,14 @@ | |
|
||
"""Test for user handling.""" | ||
|
||
from __future__ import annotations | ||
|
||
import base64 | ||
import json | ||
from urllib.parse import parse_qs, urlparse | ||
|
||
import responses | ||
from altcha import Challenge, Solution, solve_challenge | ||
from django.conf import settings | ||
from django.core import mail | ||
from django.test import Client, TestCase | ||
|
@@ -26,6 +31,7 @@ | |
"email": "[email protected]", | ||
"fullname": "First Last", | ||
"captcha": "9999", | ||
"altcha": "value", | ||
} | ||
|
||
GH_BACKENDS = ( | ||
|
@@ -151,14 +157,59 @@ class RegistrationTest(BaseRegistrationTest): | |
def test_register_captcha_fail(self) -> None: | ||
response = self.do_register() | ||
self.assertContains(response, "That was not correct, please try again.") | ||
self.assertContains(response, "Validation failed, please try again.") | ||
|
||
def solve_altcha(self, response, data: dict): | ||
form = response.context["form"] | ||
challenge: Challenge = form.challenge | ||
solution: Solution = solve_challenge( | ||
challenge=challenge.challenge, | ||
salt=challenge.salt, | ||
algorithm=challenge.algorithm, | ||
max_number=challenge.maxnumber, | ||
start=0, | ||
) | ||
data["altcha"] = base64.b64encode( | ||
json.dumps( | ||
{ | ||
"algorithm": challenge.algorithm, | ||
"challenge": challenge.challenge, | ||
"number": solution.number, | ||
"salt": challenge.salt, | ||
"signature": challenge.signature, | ||
} | ||
).encode("utf-8") | ||
).decode("utf-8") | ||
|
||
def solve_math(self, response, data: dict): | ||
form = response.context["form"] | ||
data["captcha"] = form.mathcaptcha.result | ||
|
||
@override_settings(REGISTRATION_CAPTCHA=True) | ||
def test_register_partial_altcha(self) -> None: | ||
"""Test registration with captcha enabled.""" | ||
response = self.client.get(reverse("register")) | ||
data = REGISTRATION_DATA.copy() | ||
self.solve_altcha(response, data) | ||
response = self.do_register(data) | ||
self.assertContains(response, "That was not correct, please try again.") | ||
|
||
@override_settings(REGISTRATION_CAPTCHA=True) | ||
def test_register_partial_match(self) -> None: | ||
"""Test registration with captcha enabled.""" | ||
response = self.client.get(reverse("register")) | ||
data = REGISTRATION_DATA.copy() | ||
self.solve_math(response, data) | ||
response = self.do_register(data) | ||
self.assertContains(response, "Validation failed, please try again.") | ||
|
||
@override_settings(REGISTRATION_CAPTCHA=True) | ||
def test_register_captcha(self) -> None: | ||
"""Test registration with captcha enabled.""" | ||
response = self.client.get(reverse("register")) | ||
form = response.context["form"] | ||
data = REGISTRATION_DATA.copy() | ||
data["captcha"] = form.mathcaptcha.result | ||
self.solve_altcha(response, data) | ||
self.solve_math(response, data) | ||
response = self.do_register(data) | ||
self.assertContains(response, REGISTRATION_SUCCESS) | ||
|
||
|
Oops, something went wrong.