IpnHandlerTest.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace AmazonPay;
  3. require_once 'AmazonPay/IpnHandler.php';
  4. class IpnHandlertest extends \PHPUnit_Framework_TestCase
  5. {
  6. private $configParams = array(
  7. 'cabundle_file' => null,
  8. 'proxy_host' => null,
  9. 'proxy_port' => -1,
  10. 'proxy_username' => null,
  11. 'proxy_Password' => null
  12. );
  13. public function testConstructor()
  14. {
  15. try {
  16. $headers = array();
  17. $headers = array('ab'=>'abc');
  18. $body = 'abctest';
  19. $ipnHandler = new IpnHandler($headers,$body,$this->configParams);
  20. } catch (\Exception $expected) {
  21. $this->assertRegExp('/Error with message - header./i', strval($expected));
  22. }
  23. try {
  24. $headers['x-amz-sns-message-type'] = 'Notification';
  25. $body = 'abctest';
  26. $ipnHandler = new IpnHandler($headers,$body,$this->configParams);
  27. } catch (\Exception $expected) {
  28. $this->assertRegExp('/Error with message - content is not in json format./i', strval($expected));
  29. }
  30. try {
  31. $ConfigParams = array(
  32. 'a' => 'A',
  33. 'b' => 'B'
  34. );
  35. $ipnHandler = new IpnHandler(array(),null,$ConfigParams);
  36. } catch (\Exception $expected) {
  37. $this->assertRegExp('/is either not part of the configuration or has incorrect Key name./i', strval($expected));
  38. }
  39. }
  40. public function testValidateUrl()
  41. {
  42. $headers = array('x-amz-sns-message-type' => 'Notification');
  43. try {
  44. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"http://sns.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"}';
  45. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  46. } catch (\Exception $expected) {
  47. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  48. }
  49. try {
  50. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"https://sns.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.exe"}';
  51. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  52. } catch (\Exception $expected) {
  53. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  54. }
  55. try {
  56. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"https://sns.us-east-1.example.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"}';
  57. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  58. } catch (\Exception $expected) {
  59. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  60. }
  61. try {
  62. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"https://sni.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"}';
  63. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  64. } catch (\Exception $expected) {
  65. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  66. }
  67. try {
  68. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"https://sns.us.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"}';
  69. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  70. } catch (\Exception $expected) {
  71. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  72. }
  73. try {
  74. $body = '{"Type":"Notification", "Message":"Test", "MessageId":"Test", "Timestamp":"Test", "Subject":"Test", "TopicArn":"Test", "Signature":"Test", "SigningCertURL":"https://sns.us-east-1.amazonaws.com.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"}';
  75. $ipnHandler = new IpnHandler($headers, $body, $this->configParams);
  76. } catch (\Exception $expected) {
  77. $this->assertRegExp('/The certificate is located on an invalid domain./i', strval($expected));
  78. }
  79. }
  80. }