Merge branch 'Kerl/isalnum' into 'master'
Show ill-formed clipper uids in error messages See merge request cof-geek/django-allauth-ens!13
This commit is contained in:
commit
5d978e89ea
2 changed files with 14 additions and 1 deletions
|
@ -9,6 +9,7 @@ from django.core import mail
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
from allauth.socialaccount.models import SocialAccount
|
from allauth.socialaccount.models import SocialAccount
|
||||||
|
from allauth_ens.utils import get_ldap_infos
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from allauth_cas.test.testcases import CASTestCase
|
from allauth_cas.test.testcases import CASTestCase
|
||||||
|
@ -367,3 +368,11 @@ class LongTermClipperTests(CASTestCase):
|
||||||
self.assertEqual(nu0, nu1)
|
self.assertEqual(nu0, nu1)
|
||||||
self.assertEqual(nsa0, nsa1)
|
self.assertEqual(nsa0, nsa1)
|
||||||
ldap_patcher.start()
|
ldap_patcher.start()
|
||||||
|
|
||||||
|
def test_invalid_uid(self):
|
||||||
|
self._setup_ldap(12, "test")
|
||||||
|
uids = [" test", "test ", "\\test", "test)"]
|
||||||
|
for uid in uids:
|
||||||
|
with self.assertRaises(ValueError) as cm:
|
||||||
|
get_ldap_infos(uid)
|
||||||
|
self.assertIn(uid, cm.exception.message)
|
||||||
|
|
|
@ -69,7 +69,11 @@ def extract_infos_from_ldap(infos):
|
||||||
|
|
||||||
|
|
||||||
def get_ldap_infos(clipper_uid):
|
def get_ldap_infos(clipper_uid):
|
||||||
assert clipper_uid.isalnum()
|
if not clipper_uid.isalnum():
|
||||||
|
raise ValueError(
|
||||||
|
'Invalid uid "{}": contains non-alphanumeric characters'
|
||||||
|
.format(clipper_uid)
|
||||||
|
)
|
||||||
data = {}
|
data = {}
|
||||||
try:
|
try:
|
||||||
ldap_connection = init_ldap()
|
ldap_connection = init_ldap()
|
||||||
|
|
Loading…
Reference in a new issue