This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
test_email.h
94 lines (84 loc) · 3.32 KB
/
test_email.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @file
*
* @brief Tests for email plugin
*
* @copyright BSD License (see doc/LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdio.h>
#include <tests_plugin.h>
#include <kdbconfig.h>
static void testEmail (char const * const email, const int ret)
{
Key * parentKey = keyNew ("user:/tests/email", KEY_VALUE, "", KEY_END);
KeySet * conf = ksNew (0, KS_END);
KeySet * ks = ksNew (10, keyNew ("user:/tests/email/totest", KEY_VALUE, email, KEY_META, "check/email", "", KEY_END), KS_END);
PLUGIN_OPEN (PLUGIN_NAME);
const int pluginStatus = plugin->kdbSet (plugin, ks, parentKey);
char message[300];
(void) snprintf (message, 300, "validation of email address “%s” returned %d instead of %d", email, pluginStatus, ret);
succeed_if (pluginStatus == ret, message);
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
static void testEmailAll (void)
{
// valid email addresses
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("test/[email protected]", 1);
testEmail ("admin@mailserver1", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("user%[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("[email protected]", 1);
testEmail ("ast*[email protected]", 1);
testEmail ("#$%!^/&@elektra.io", 1);
testEmail ("elektra@io", 1);
// invalid email addresses
testEmail ("notAn@address-", -1);
testEmail ("A@b@[email protected]", -1);
testEmail ("a\"b(c)d,e:f;g<h>i[j\\k][email protected]", -1);
testEmail ("just\"not\"[email protected]", -1);
testEmail ("this is\"not\\[email protected]", -1);
testEmail ("this\\ still\\\"not\\[email protected]", -1);
testEmail ("i_like_underscore@but_its_not_allowed_in_this_part.example.com", -1);
testEmail ("QA[icon]CHOCOLATE[icon]@test.com", -1);
testEmail ("hi@", -1);
testEmail ("[email protected]", -1);
testEmail ("[email protected]", -1);
testEmail ("!#$%&'*(-/[email protected]", -1);
testEmail ("h(a)[email protected]", -1);
testEmail ("em@[email protected]", -1);
testEmail ("\"<\\\"@\\\".!#%[email protected]", -1);
testEmail ("<\\\"@\\\\\".!#%[email protected]", -1);
testEmail ("hi\"@\"[email protected]", -1);
testEmail ("hi\\ [email protected]", -1);
// false positives because of missing top level domain and length check
testEmail ("1@23456789", 1);
testEmail ("valid+part@invalidtopleveldomain", 1);
testEmail ("1234567890123456789012345678901234567890123456789012345678901234+x@example.com", 1);
// valid but not supported email address formats:
testEmail ("\" \"@example.org", -1);
testEmail ("\"john..doe\"@example.org", -1);
testEmail ("(ele)[email protected]", -1);
testEmail ("[email protected](io)", -1);
testEmail ("\"hi@you\"@elektra.io", -1);
testEmail ("\"hi you\"@elektra.io", -1);
testEmail ("\" \"@elektra.io", -1);
testEmail ("\"<\\\"@\\\\\".!.#%$@@elektra.io", -1);
testEmail ("cow@[dead::beef]", -1);
testEmail ("是是@是是.是是", -1);
testEmail ("1@[23456789]", -1);
}