Skip to content

Commit 045e8dc

Browse files
committed
remove regex validation for email, username, and domain
1 parent ce6d129 commit 045e8dc

File tree

1 file changed

+4
-75
lines changed

1 file changed

+4
-75
lines changed

umapi_client/functional.py

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,6 @@ class UserAction(Action):
5555
A sequence of commands to perform on a single user.
5656
"""
5757

58-
# regex patterns to be compiled once and used in _validate
59-
# The RFC6531 extended syntax for email addresses allows Unicode alphanumerics in the local part,
60-
# but the Adobe identity system doesn't support that extended syntax for user account emails.
61-
# This is the RFC-allowed pattern:
62-
# _atext_pattern = r"(\w|[!#$%&'*+/=?^_`{|}~;-])+"
63-
# This is the one allowed by Adobe:
64-
_atext_pattern = r"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+"
65-
_local_pattern = _atext_pattern + r"([.]" + _atext_pattern + ")*"
66-
_dns_pattern = r"[a-zA-Z0-9-]+([.][a-zA-Z0-9-]+)+"
67-
_email_regex = re.compile(r"\A" + _local_pattern + r"@" + _dns_pattern + r"\Z", re.UNICODE)
68-
_username_regex = re.compile(r"^" + _local_pattern + r"$", re.UNICODE)
69-
_domain_regex = re.compile(r"^" + _dns_pattern + r"$", re.UNICODE)
70-
71-
@classmethod
72-
def _validate_email(cls, email=None):
73-
"""
74-
Validates user email (or username if it's assumed to be in email format)
75-
Input values must be strings (standard or unicode). Throws ArgumentError if any input is invalid
76-
:param email: an email address
77-
"""
78-
if email and not cls._email_regex.match(email):
79-
raise ArgumentError("'%s': Illegal email format (must be ascii, unquoted, with no comment part)" % (email,))
80-
81-
@classmethod
82-
def _validate_username(cls, username=None):
83-
"""
84-
Validates the specified username (assuming it should be non-email)
85-
Input values must be strings (standard or unicode). Throws ArgumentError if any input is invalid
86-
:param username: a username
87-
"""
88-
if username and not cls._username_regex.match(username):
89-
raise ArgumentError("'%s': Illegal username format (must be unquoted email local part)" % (username,))
90-
91-
@classmethod
92-
def _validate_domain(cls, domain=None):
93-
"""
94-
Validates the specified domain
95-
Input values must be strings (standard or unicode). Throws ArgumentError if any input is invalid
96-
:param domain: a domain
97-
"""
98-
if domain and not cls._domain_regex.match(domain):
99-
raise ArgumentError("'%s': Illegal domain format" % (domain,))
100-
10158
def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, domain=None, **kwargs):
10259
"""
10360
Create an Action for a user identified either by email or by username and domain.
@@ -125,31 +82,13 @@ def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, dom
12582
raise ArgumentError("Identity type (%s) must be one of %s" % (id_type, [i.name for i in IdentityTypes]))
12683
self.id_type = id_type
12784
self.email = None
128-
self.domain = None
129-
if username:
130-
if email and username.lower() == email.lower():
131-
# ignore the username if it's the same as the email (policy default)
132-
username = None
133-
elif id_type is not IdentityTypes.federatedID:
134-
raise ArgumentError("Username must match email except for Federated ID")
135-
else:
136-
self._validate_username(username=username)
137-
if domain:
138-
self._validate_domain(domain=domain)
139-
self.domain = domain
140-
if email:
141-
self._validate_email(email=email)
85+
self.domain = domain
86+
if email is not None:
14287
self.email = email
143-
if not self.domain:
88+
if self.domain is None:
14489
atpos = email.index('@')
14590
self.domain = email[atpos + 1:]
146-
elif not username:
147-
raise ArgumentError("No user identity specified.")
148-
elif not domain:
149-
raise ArgumentError("Both username and domain must be specified")
150-
if username:
151-
Action.__init__(self, user=username, domain=self.domain, **kwargs)
152-
elif id_type == IdentityTypes.adobeID:
91+
if id_type == IdentityTypes.adobeID:
15392
# by default if two users have the same email address, the UMAPI server will prefer the matching
15493
# Federated or Enterprise ID user; so we use the undocumented option to prefer the AdobeID match
15594
Action.__init__(self, user=email, useAdobeID=True, **kwargs)
@@ -176,10 +115,7 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
176115
if not self.email:
177116
raise ArgumentError("You must specify email when creating a user")
178117
elif self.email is None:
179-
self._validate_email(email=email)
180118
self.email = email
181-
elif self.email.lower() != email.lower():
182-
raise ArgumentError("Specified email (%s) doesn't match user's email (%s)" % (email, self.email))
183119
create_params["email"] = self.email
184120
if on_conflict in IfAlreadyExistsOptions.__members__:
185121
on_conflict = IfAlreadyExistsOptions[on_conflict]
@@ -209,13 +145,6 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
209145
:param country: new country for this user
210146
:return: the User, so you can do User(...).update(...).add_to_groups(...)
211147
"""
212-
if email:
213-
self._validate_email(email=email)
214-
# if username contains @ (federated only), validate as email address
215-
if self.id_type == IdentityTypes.federatedID and username and '@' in username:
216-
self._validate_email(email=username)
217-
elif username:
218-
self._validate_username(username=username)
219148
updates = {}
220149
for k, v in six.iteritems(dict(email=email, username=username,
221150
firstname=first_name, lastname=last_name,

0 commit comments

Comments
 (0)