You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DomainStatusTest.php 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace AuthresStatusTests;
  3. use stdClass;
  4. use authres_status;
  5. use PHPUnit\Framework\TestCase;
  6. class DomainStatusTest extends TestCase
  7. {
  8. public function test_pass_from_subdomain()
  9. {
  10. $headers = $this->create_header_object('mail.domain.net; dkim=pass (1024-bit key; secure) header.d=email.com header.i=@email.com header.b=XXXXXXXX; dkim-atps=neutral', 'Test <test@subdomain.email.com>');
  11. $plugin = new authres_status();
  12. $result = $plugin->get_authentication_status($headers);
  13. $expected = <<<EOT
  14. <img src="plugins/authres_status/images/status_pass.png" alt="Valid signature(s) from the sender's domain. verified by " title="Valid signature(s) from the sender's domain. verified by dkim=pass (1024-bit key; secure)" width="14" height="14" class="authres-status-img" />
  15. EOT;
  16. $this->assertEquals($expected, $result);
  17. }
  18. public function test_pass_single_signature()
  19. {
  20. $headers = $this->create_header_object('mail.domain.net; dkim=pass (1024-bit key; secure) header.d=email.com header.i=@email.com header.b=XXXXXXXX; dkim-atps=neutral');
  21. $plugin = new authres_status();
  22. $result = $plugin->get_authentication_status($headers);
  23. $expected = <<<EOT
  24. <img src="plugins/authres_status/images/status_pass.png" alt="Valid signature(s) from the sender's domain. verified by " title="Valid signature(s) from the sender's domain. verified by dkim=pass (1024-bit key; secure)" width="14" height="14" class="authres-status-img" />
  25. EOT;
  26. $this->assertEquals($expected, $result);
  27. }
  28. public function test_pass_multiple_signatures()
  29. {
  30. $headers = $this->create_header_object('mail.domain.net; dkim=pass header.i=@smtpcorp.com; dkim=pass header.i=@email.com; dkim=pass header.i=@email.com');
  31. $plugin = new authres_status();
  32. $result = $plugin->get_authentication_status($headers);
  33. $expected = <<<EOT
  34. <img src="plugins/authres_status/images/status_pass.png" alt="Valid signature(s) from the sender's domain. verified by " title="Valid signature(s) from the sender's domain. verified by dkim=pass; dkim=pass" width="14" height="14" class="authres-status-img" />
  35. EOT;
  36. $this->assertEquals($expected, $result);
  37. }
  38. public function test_third_signature()
  39. {
  40. $headers = $this->create_header_object('mail.domain.net; dkim=pass (1024-bit key; unprotected) header.d=mail.3rdparty.com header.i=@mail.3rdparty.com header.b=XXXXXXXX;');
  41. $plugin = new authres_status();
  42. $result = $plugin->get_authentication_status($headers);
  43. $expected = <<<EOT
  44. <img src="plugins/authres_status/images/status_third.png" alt="Signed by third party, signature is present but for different domain than from address. verified for " title="Signed by third party, signature is present but for different domain than from address. verified for mail.3rdparty.com by dkim=pass (1024-bit key; unprotected)" width="14" height="14" class="authres-status-img" />
  45. EOT;
  46. $this->assertEquals($expected, $result);
  47. }
  48. protected function create_header_object($authres_header, $from = 'Test <test@email.com>')
  49. {
  50. $headers = new stdClass;
  51. $headers->from = $from;
  52. $headers->others = array(
  53. 'x-dkim-authentication-results' => false,
  54. 'authentication-results' => $authres_header
  55. );
  56. return $headers;
  57. }
  58. }