8 error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
11 $sharedLibrary =
"/var/www/html/shared/library";
12 require_once(
"$sharedLibrary/hcuCommon.i");
15 if (count($argv) >= 2) {
21 $sepLength = GetSeparatorLength();
23 print
"\n\nTest Verification\n" . str_repeat(
"+", $sepLength) .
"\n" . str_repeat(
"=", $sepLength) .
"\n\n\n";
27 print
"Test is not valid.\n";
30 print
"Command line only takes one argument: the test to run.\n";
37 function GetSeparatorLength() {
49 function AssertEquals($title, $testThis, $needsToEqual) {
50 $testThis = trim($testThis);
51 $needsToEqual = trim($needsToEqual);
52 if ($testThis == $needsToEqual) {
53 print
"$title was successful.\n";
55 print
"$title failed.\n";
56 print
"Expected: '$needsToEqual'\n";
57 print
"Received: '$testThis'\n";
69 function AssertStartsWith($title, $testThis, $needsToEqual) {
70 $testThis = trim($testThis);
71 $needsToEqual = trim($needsToEqual);
72 if (substr($testThis, 0, strlen($needsToEqual)) == $needsToEqual) {
73 print
"$title was successful.\n";
75 print
"$title failed.\n";
76 print
"Expected: '$needsToEqual'\n";
77 print
"Received: '$testThis'\n";
89 function AssertNotContains($title, $testThis, $contains) {
90 $testThis = trim($testThis);
91 $needsToEqual = trim($needsToEqual);
92 if (strpos($testThis, $contains) ===
false) {
93 print
"$title was successful.\n";
95 print
"$title failed.\n";
96 print
"Expected: '$needsToEqual'\n";
97 print
"Received: '$testThis'\n";
110 function RunPyFile($action, $emailList) {
111 $sharedScripts =
"/var/www/html/shared/scripts";
112 $pyFile =
"$sharedScripts/verifySESEmail.py";
113 $cmd =
"python3 $pyFile" . (isset($action) ?
" -a " . escapeshellarg($action) :
"");
116 if (isset($emailList) && is_array($emailList) && count($emailList) > 0) {
117 foreach($emailList as $email) {
119 $emails =
" -e \"" . str_replace(
'"',
'\x22', $email);
121 $emails .=
" " . str_replace(
'"',
'\x22', $email);
128 return HCU_JsonDecode(exec($cmd));
135 function TestVerification() {
143 print
"\n\nTesting Invalid call...\n" . str_repeat(
"*", $sepLength) .
"\n";
144 $results = RunPyFile(
null,
null);
146 AssertEquals(
"Test " . ($testn ++) .
": invalid call", $results[
"error"],
"verifySESEmail.py -e \"email1 email2 email3 ... emailN\" -a \"verifyEmails\"|\"getVerification\"|\"removeEmails\"");
148 print
"\n\nTesting getting statuses of identities...\n" . str_repeat(
"*", $sepLength) .
"\n";
149 $results = RunPyFile(
"getVerification", array(
"homecutester1@gmail.com",
"homecutester2@gmail.com",
"homecutester3@gmail.com",
"homecutester4@gmail.com",
"homecutester5@gmail.com"));
150 AssertEquals(
"Test " . ($testn ++) .
": no errors", $results[
"status"],
"000");
151 $verify = $results[
"response"][
"VerificationAttributes"];
152 AssertEquals(
"Test " . ($testn ++) .
": verification attributes", is_array($verify),
true);
153 AssertEquals(
"Test " . ($testn ++) .
": homecutester1@gmail.com", $verify[
"homecutester1@gmail.com"][
"VerificationStatus"],
"Success");
154 AssertEquals(
"Test " . ($testn ++) .
": homecutester2@gmail.com", $verify[
"homecutester2@gmail.com"][
"VerificationStatus"],
"Failed");
155 AssertEquals(
"Test " . ($testn ++) .
": homecutester3@gmail.com", $verify[
"homecutester3@gmail.com"][
"VerificationStatus"],
"Failed");
156 AssertEquals(
"Test " . ($testn ++) .
": homecutester4@gmail.com", $verify[
"homecutester4@gmail.com"][
"VerificationStatus"],
"");
157 AssertEquals(
"Test " . ($testn ++) .
": homecutester5@gmail.com", $verify[
"homecutester5@gmail.com"][
"VerificationStatus"],
"");
159 print
"\n\nTesting sending verification emails...\n" . str_repeat(
"*", $sepLength) .
"\n";
160 $results = RunPyFile(
"verifyEmails", array(
"homecutester1@gmail.com",
"homecutester3@gmail.com",
"homecutester4@gmail.com",
"homecutest"));
161 AssertEquals(
"Test " . ($testn ++) .
": invalid email syntax", $results[
"error"],
"homecutest is not valid");
162 AssertEquals(
"Test " . ($testn ++) .
": returned success from other emails", $results[
"response"][
"homecutester1@gmail.com"][
"ResponseMetadata"][
"HTTPHeaders"][
"content-type"],
"text/xml");
164 print
"\n\nTesting getting statuses of identities...\n" . str_repeat(
"*", $sepLength) .
"\n";
165 $results = RunPyFile(
"getVerification", array(
"homecutester1@gmail.com",
"homecutester2@gmail.com",
"homecutester3@gmail.com",
"homecutester4@gmail.com",
"homecutester5@gmail.com"));
166 AssertEquals(
"Test " . ($testn ++) .
": no errors", $results[
"status"],
"000");
167 $verify = $results[
"response"][
"VerificationAttributes"];
168 AssertEquals(
"Test " . ($testn ++) .
": verification attributes", is_array($verify),
true);
169 AssertEquals(
"Test " . ($testn ++) .
": homecutester1@gmail.com", $verify[
"homecutester1@gmail.com"][
"VerificationStatus"],
"Success");
170 AssertEquals(
"Test " . ($testn ++) .
": homecutester2@gmail.com", $verify[
"homecutester2@gmail.com"][
"VerificationStatus"],
"Failed");
171 AssertEquals(
"Test " . ($testn ++) .
": homecutester3@gmail.com", $verify[
"homecutester3@gmail.com"][
"VerificationStatus"],
"Pending");
172 AssertEquals(
"Test " . ($testn ++) .
": homecutester4@gmail.com", $verify[
"homecutester4@gmail.com"][
"VerificationStatus"],
"Pending");
173 AssertEquals(
"Test " . ($testn ++) .
": homecutester5@gmail.com", $verify[
"homecutester5@gmail.com"][
"VerificationStatus"],
"");
175 print
"\n\nTesting removing email identities...\n" . str_repeat(
"*", $sepLength) .
"\n";
176 $results = RunPyFile(
"removeEmails", array(
"homecutester4@gmail.com",
"homecutester5@gmail.com"));
177 AssertEquals(
"Test " . ($testn ++) .
": no errors", $results[
"status"],
"000");
178 AssertEquals(
"Test " . ($testn ++) .
": deleted email identity", $results[
"response"][
"homecutester4@gmail.com"][
"ResponseMetadata"][
"HTTPHeaders"][
"content-type"],
"text/xml");
179 AssertEquals(
"Test " . ($testn ++) .
": deleted nonexistent email identity", $results[
"response"][
"homecutester5@gmail.com"][
"ResponseMetadata"][
"HTTPHeaders"][
"content-type"],
"text/xml");
181 print
"\n\nTesting getting statuses of identities...\n" . str_repeat(
"*", $sepLength) .
"\n";
182 $results = RunPyFile(
"getVerification", array(
"homecutester1@gmail.com",
"homecutester2@gmail.com",
"homecutester3@gmail.com",
"homecutester4@gmail.com",
"homecutester5@gmail.com"));
183 AssertEquals(
"Test " . ($testn ++) .
": no errors", $results[
"status"],
"000");
184 $verify = $results[
"response"][
"VerificationAttributes"];
185 AssertEquals(
"Test " . ($testn ++) .
": verification attributes", is_array($verify),
true);
186 AssertEquals(
"Test " . ($testn ++) .
": homecutester1@gmail.com", $verify[
"homecutester1@gmail.com"][
"VerificationStatus"],
"Success");
187 AssertEquals(
"Test " . ($testn ++) .
": homecutester2@gmail.com", $verify[
"homecutester2@gmail.com"][
"VerificationStatus"],
"Failed");
188 AssertEquals(
"Test " . ($testn ++) .
": homecutester3@gmail.com", $verify[
"homecutester3@gmail.com"][
"VerificationStatus"],
"Pending");
189 AssertEquals(
"Test " . ($testn ++) .
": homecutester4@gmail.com", $verify[
"homecutester4@gmail.com"][
"VerificationStatus"],
"");
190 AssertEquals(
"Test " . ($testn ++) .
": homecutester5@gmail.com", $verify[
"homecutester5@gmail.com"][
"VerificationStatus"],
"");