Merge pull request #2245 from coreos-inc/recaptcha
Add support for recaptcha during the create account flow
This commit is contained in:
commit
9b65b37011
12 changed files with 88 additions and 1 deletions
|
@ -9,6 +9,7 @@ import json as py_json
|
|||
|
||||
from contextlib import contextmanager
|
||||
from calendar import timegm
|
||||
from httmock import urlmatch, HTTMock, all_requests
|
||||
from StringIO import StringIO
|
||||
from urllib import urlencode
|
||||
from urlparse import urlparse, urlunparse, parse_qs
|
||||
|
@ -667,6 +668,29 @@ class TestCreateNewUser(ApiTestCase):
|
|||
data = self.postJsonResponse(User, data=NEW_USER_DETAILS, expected_code=200)
|
||||
self.assertEquals(True, data['awaiting_verification'])
|
||||
|
||||
def test_createuser_captcha(self):
|
||||
@urlmatch(netloc=r'(.*\.)?google.com', path='/recaptcha/api/siteverify')
|
||||
def captcha_endpoint(url, request):
|
||||
if url.query.find('response=somecode') > 0:
|
||||
return {'status_code': 200, 'content': py_json.dumps({'success': True})}
|
||||
else:
|
||||
return {'status_code': 400, 'content': py_json.dumps({'success': False})}
|
||||
|
||||
with HTTMock(captcha_endpoint):
|
||||
with self.toggleFeature('RECAPTCHA', True):
|
||||
# Try with a missing captcha.
|
||||
self.postResponse(User, data=NEW_USER_DETAILS, expected_code=400)
|
||||
|
||||
# Try with an invalid captcha.
|
||||
details = dict(NEW_USER_DETAILS)
|
||||
details['recaptcha_response'] = 'someinvalidcode'
|
||||
self.postResponse(User, data=details, expected_code=400)
|
||||
|
||||
# Try with a valid captcha.
|
||||
details = dict(NEW_USER_DETAILS)
|
||||
details['recaptcha_response'] = 'somecode'
|
||||
self.postResponse(User, data=details, expected_code=200)
|
||||
|
||||
def test_createuser_withteaminvite(self):
|
||||
inviter = model.user.get_user(ADMIN_ACCESS_USER)
|
||||
team = model.team.get_organization_team(ORGANIZATION, 'owners')
|
||||
|
|
Reference in a new issue