1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

Captcha fallback for where re-captcha is unavailable (#38)

This commit is contained in:
Stefan Pratter
2019-05-02 17:57:55 +00:00
parent 7b1861a58d
commit e49d7c9b68
12 changed files with 183 additions and 31 deletions

View File

@@ -27,6 +27,7 @@ settings.configure(
'dal',
'dal_select2',
'corsheaders',
'captcha',
],
CACHES={
"default": {
@@ -159,6 +160,8 @@ settings.configure(
DATA_QUALITY_MIN_PREFIXLEN_V6 = 64,
DATA_QUALITY_MAX_PREFIXLEN_V6 = 116,
TUTORIAL_MODE=False,
CAPTCHA_TEST_MODE=True,
SITE_ID=1,
RATELIMITS={
"view_affiliate_to_org_POST": "100/m",
"resend_confirmation_mail": "2/m",

View File

@@ -1,9 +1,13 @@
import pytest
import json
import re
import pytest
from django.test import Client, TestCase, RequestFactory
from django.contrib.auth.models import Group
from captcha.models import CaptchaStore
import peeringdb_server.models as models
import peeringdb_server.views as views
@@ -271,3 +275,29 @@ class UserTests(TestCase):
with self.assertRaises(KeyError):
email = c.session["username_retrieve_email"]
def test_signup(self):
"""
test user signup with captcha fallback
"""
c = Client()
response = c.get("/register")
self.assertGreater(response.content.find('name="captcha_generator_0"'), -1)
m = re.search('name="captcha_generator_0" value="([^"]+)"', response.content)
captcha_obj = CaptchaStore.objects.get(hashkey=m.group(1))
response = c.post("/register", {
"username": "signuptest",
"password1": "signuptest_123",
"password2": "signuptest_123",
"email": "signuptest@localhost",
"captcha": "{}:{}".format(captcha_obj.hashkey, captcha_obj.response)
})
self.assertEqual( json.loads(response.content), {"status":"ok"})