NativeMailerHandlerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\TestCase;
  12. class NativeMailerHandlerTest extends TestCase
  13. {
  14. /**
  15. * @expectedException InvalidArgumentException
  16. */
  17. public function testConstructorHeaderInjection()
  18. {
  19. $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org");
  20. }
  21. /**
  22. * @expectedException InvalidArgumentException
  23. */
  24. public function testSetterHeaderInjection()
  25. {
  26. $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
  27. $mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org");
  28. }
  29. /**
  30. * @expectedException InvalidArgumentException
  31. */
  32. public function testSetterArrayHeaderInjection()
  33. {
  34. $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
  35. $mailer->addHeader(array("Content-Type: text/html\r\nFrom: faked@attacker.org"));
  36. }
  37. /**
  38. * @expectedException InvalidArgumentException
  39. */
  40. public function testSetterContentTypeInjection()
  41. {
  42. $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
  43. $mailer->setContentType("text/html\r\nFrom: faked@attacker.org");
  44. }
  45. /**
  46. * @expectedException InvalidArgumentException
  47. */
  48. public function testSetterEncodingInjection()
  49. {
  50. $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
  51. $mailer->setEncoding("utf-8\r\nFrom: faked@attacker.org");
  52. }
  53. }