Skip to content

Commit 3aa81e8

Browse files
authored
Merge pull request #43 from adobe-apiplatform/v2
Fix #41 (again!). Prepare for v2.4.1 bug fix release.
2 parents e6c7780 + 2f6745f commit 3aa81e8

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ Bug fix release:
7070
* [Issue 41](https://github.com/adobe-apiplatform/umapi-client.py/issues/41)
7171
* accept unicode strings from Python 2.7 clients
7272
* do unicode-compliant validation of usernames and email addresses
73+
74+
### Version 2.4.1
75+
76+
Bug fix release:
77+
78+
* [Issue 41](https://github.com/adobe-apiplatform/umapi-client.py/issues/41)
79+
* original fix had an overly accepting email/username validator
80+
* there were formatting errors in the failed validation reports

tests/test_functional.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,27 @@ def test_user_adobeid():
3939

4040

4141
def test_user_adobeid_unicode():
42-
user = UserAction(email=u"lwałęsa@adobe.com")
42+
user = UserAction(email=u"lwalesa@adobe.com")
4343
assert user.wire_dict() == {"do": [],
44-
"user": u"lwałęsa@adobe.com",
44+
"user": u"lwalesa@adobe.com",
4545
"useAdobeID": True}
4646

4747

48-
def test_user_adobeid_unicode_error_trailing_dot():
48+
def test_user_adobeid_unicode_error_unicode_dot_above():
4949
with pytest.raises(ValueError):
50-
UserAction(email=u"lwałęsa.@adobe.com")
50+
UserAction(email=u"lwałę[email protected]")
5151

5252

53-
def test_user_adobeid_unicode_error_unicode_dot_above():
53+
def test_user_adobeid_unicode_error_trailing_dot():
5454
with pytest.raises(ValueError):
55-
UserAction(email=u"l˙wałęsa@adobe.com")
55+
UserAction(email=u"lwalesa.@adobe.com")
5656

5757

5858
def test_user_enterpriseid():
5959
user = UserAction(id_type=IdentityTypes.enterpriseID, email="[email protected]")
6060
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
6161

6262

63-
def test_user_enterpriseid_unicode():
64-
user = UserAction(id_type=IdentityTypes.enterpriseID, email=u"lwałę[email protected]")
65-
assert user.wire_dict() == {"do": [], "user": u"lwałę[email protected]"}
66-
67-
6863
def test_user_enterpriseid_username():
6964
with pytest.raises(ValueError):
7065
UserAction(id_type=IdentityTypes.enterpriseID, username="dbrotsky", domain="o.on-the-side.net")
@@ -75,19 +70,14 @@ def test_user_federatedid():
7570
assert user.wire_dict() == {"do": [], "user": "[email protected]"}
7671

7772

78-
def test_user_federatedid_unicode():
79-
user = UserAction(id_type=IdentityTypes.federatedID, email=u"lwałę[email protected]")
80-
assert user.wire_dict() == {"do": [], "user": u"lwałę[email protected]"}
81-
82-
8373
def test_user_federatedid_username():
8474
user = UserAction(id_type=IdentityTypes.federatedID, username="dbrotsky", domain="k.on-the-side.net")
8575
assert user.wire_dict() == {"do": [], "user": "dbrotsky", "domain": "k.on-the-side.net"}
8676

8777

88-
def test_user_federatedid_username_unicode():
89-
user = UserAction(id_type=IdentityTypes.federatedID, username=u"lwałęsa", domain="k.on-the-side.net")
90-
assert user.wire_dict() == {"do": [], "user": u"lwałęsa", "domain": "k.on-the-side.net"}
78+
def test_user_federatedid_username_unicode_error():
79+
with pytest.raises(ValueError):
80+
UserAction(id_type=IdentityTypes.federatedID, username=u"lwałęsa", domain="k.on-the-side.net")
9181

9282

9383
def test_create_user_adobeid():
@@ -126,13 +116,13 @@ def test_create_user_federatedid():
126116

127117

128118
def test_create_user_federated_id_unicode():
129-
user = UserAction(id_type=IdentityTypes.federatedID, email=u"lwałęsa@k.on-the-side.net")
119+
user = UserAction(id_type=IdentityTypes.federatedID, email=u"lwalesa@k.on-the-side.net")
130120
user.create(first_name="Lech", last_name=u"Wałęsa", country="PL")
131-
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwałęsa@k.on-the-side.net",
121+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwalesa@k.on-the-side.net",
132122
"firstname": "Lech", "lastname": u"Wałęsa",
133123
"country": "PL",
134124
"option": "ignoreIfAlreadyExists"}}],
135-
"user": u"lwałęsa@k.on-the-side.net"}
125+
"user": u"lwalesa@k.on-the-side.net"}
136126

137127

138128
def test_create_user_federatedid_username():
@@ -146,13 +136,13 @@ def test_create_user_federatedid_username():
146136

147137

148138
def test_create_user_federatedid_username_unicode():
149-
user = UserAction(id_type=IdentityTypes.federatedID, username=u"lwałęsa", domain="k.on-the-side.net")
150-
user.create(first_name="Lech", last_name=u"Wałęsa", country="PL", email=u"lwałęsa@k.on-the-side.net")
151-
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwałęsa@k.on-the-side.net",
139+
user = UserAction(id_type=IdentityTypes.federatedID, username=u"lwalesa", domain="k.on-the-side.net")
140+
user.create(first_name="Lech", last_name=u"Wałęsa", country="PL", email=u"lwalesa@k.on-the-side.net")
141+
assert user.wire_dict() == {"do": [{"createFederatedID": {"email": u"lwalesa@k.on-the-side.net",
152142
"firstname": "Lech", "lastname": u"Wałęsa",
153143
"country": "PL",
154144
"option": "ignoreIfAlreadyExists"}}],
155-
"user": u"lwałęsa", "domain": "k.on-the-side.net"}
145+
"user": u"lwalesa", "domain": "k.on-the-side.net"}
156146

157147

158148
def test_create_user_federatedid_username_email():
@@ -310,14 +300,6 @@ def test_remove_from_organization_adobeid():
310300
"useAdobeID": True}
311301

312302

313-
def test_remove_from_organization_adobeid_unicode():
314-
user = UserAction(id_type='adobeID', email=u"lwałę[email protected]")
315-
user.remove_from_organization()
316-
assert user.wire_dict() == {"do": [{"removeFromOrg": {"deleteAccount": False}}],
317-
"user": u"lwałę[email protected]",
318-
"useAdobeID": True}
319-
320-
321303
def test_remove_from_organization_delete_federatedid():
322304
user = UserAction(id_type=IdentityTypes.federatedID, email="[email protected]")
323305
user.remove_from_organization(delete_account=True)

umapi_client/functional.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ class UserAction(Action):
5555
"""
5656

5757
# regex patterns to be compiled once and used in _validate
58-
_atext_pattern = r"(\w|[!#$%&'*+/=?^_`{|}~;-])+"
58+
# The RFC6531 extended syntax for email addresses allows Unicode alphanumerics in the local part,
59+
# but the Adobe identity system doesn't support that extended syntax for user account emails.
60+
# This is the RFC-allowed pattern:
61+
# _atext_pattern = r"(\w|[!#$%&'*+/=?^_`{|}~;-])+"
62+
# This is the one allowed by Adobe:
63+
_atext_pattern = r"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+"
5964
_local_pattern = _atext_pattern + r"([.]" + _atext_pattern + ")*"
6065
_dns_pattern = r"[a-zA-Z0-9-]+([.][a-zA-Z0-9-]+)+"
6166
_email_regex = re.compile(r"\A" + _local_pattern + r"@" + _dns_pattern + r"\Z", re.UNICODE)
@@ -72,10 +77,13 @@ def _validate(cls, email=None, username=None, domain=None):
7277
:param domain: a domain
7378
'''
7479
if email and not cls._email_regex.match(email):
75-
raise ValueError("'%s': Illegal email format (must not be quoted or contain comments)" % (email,))
80+
email = email.encode('utf-8')
81+
raise ValueError("'%s': Illegal email format (must be ascii, unquoted, with no comment part)" % (email,))
7682
if domain and not cls._domain_regex.match(domain):
83+
domain = domain.encode('utf-8')
7784
raise ValueError("'%s': Illegal domain format" % (domain,))
7885
if username and not cls._username_regex.match(username):
86+
username = username.encode('utf-8')
7987
raise ValueError("'%s': Illegal username format (must be unquoted email local part)" % (username,))
8088

8189
def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, domain=None, **kwargs):

umapi_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__ = "2.4"
21+
__version__ = "2.4.1"

0 commit comments

Comments
 (0)