-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email: validate addresses following the HTML specs
If we are going to try and validate email addresses, at least do it by following some existing specification and document it. It remains on app developpers to: * make sure their addresses are ASCII-only, by converting international labels to Punycode * remove anything but the addresses, `Some Name <[email protected]>` is not accepted [smcv: Fix merge conflicts in tests/test_email.py] Co-authored-by: Simon McVittie <[email protected]>
- Loading branch information
1 parent
83953d2
commit a2ccb56
Showing
6 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,48 @@ test_email_address (void) | |
g_main_context_iteration (NULL, TRUE); | ||
} | ||
|
||
/* test that punycode-encoded email addresses pass validation | ||
*/ | ||
void | ||
test_email_punycode_address (void) | ||
{ | ||
g_autoptr(XdpPortal) portal = NULL; | ||
g_autoptr(GKeyFile) keyfile = NULL; | ||
g_autoptr(GError) error = NULL; | ||
g_autofree char *path = NULL; | ||
const char *addresses[2] = { "[email protected]", NULL }; | ||
|
||
keyfile = g_key_file_new (); | ||
|
||
g_key_file_set_string (keyfile, "input", "address", "[email protected]"); | ||
g_key_file_set_string (keyfile, "input", "subject", "Re: portal tests"); | ||
g_key_file_set_string (keyfile, "input", "body", "To ASCII and beyond"); | ||
|
||
g_key_file_set_integer (keyfile, "backend", "delay", 0); | ||
g_key_file_set_integer (keyfile, "backend", "response", 0); | ||
g_key_file_set_integer (keyfile, "result", "response", 0); | ||
|
||
path = g_build_filename (outdir, "email", NULL); | ||
g_key_file_save_to_file (keyfile, path, &error); | ||
g_assert_no_error (error); | ||
|
||
portal = xdp_portal_new (); | ||
|
||
got_info = 0; | ||
xdp_portal_compose_email (portal, NULL, | ||
addresses, NULL, NULL, | ||
"Re: portal tests", | ||
"To ASCII and beyond", | ||
NULL, | ||
0, | ||
NULL, | ||
email_cb, | ||
keyfile); | ||
|
||
while (!got_info) | ||
g_main_context_iteration (NULL, TRUE); | ||
} | ||
|
||
/* test that an invalid subject triggers an error | ||
*/ | ||
void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,34 @@ def test_email_address(self, portal_mock): | |
method_calls = portal_mock.mock_interface.GetMethodCalls("ComposeEmail") | ||
assert len(method_calls) == 0 | ||
|
||
def test_email_punycode_address(self, portal_mock): | ||
addresses = ["[email protected]"] | ||
subject = "Re: portal tests" | ||
body = "To ASCII and beyond" | ||
|
||
request = portal_mock.create_request() | ||
options = { | ||
"addresses": addresses, | ||
"subject": subject, | ||
"body": body, | ||
} | ||
response = request.call( | ||
"ComposeEmail", | ||
parent_window="", | ||
options=options, | ||
) | ||
|
||
assert response.response == 0 | ||
|
||
# Check the impl portal was called with the right args | ||
method_calls = portal_mock.mock_interface.GetMethodCalls("ComposeEmail") | ||
assert len(method_calls) > 0 | ||
_, args = method_calls[-1] | ||
assert args[2] == "" # parent window | ||
assert args[3]["addresses"] == addresses | ||
assert args[3]["subject"] == subject | ||
assert args[3]["body"] == body | ||
|
||
def test_email_subject_multiline(self, portal_mock): | ||
"""test that an multiline subject triggers an error""" | ||
|
||
|