Ejemplo n.º 1
0
 public function testValidateFailsWhenMessageIsInvalid()
 {
     $this->setExpectedException('Aws\\Sns\\MessageValidator\\Exception\\InvalidMessageSignatureException');
     // Get the signature for some dummy data
     list($signature, $certificate) = $this->getSignature('foo');
     // Create the validator with a mock HTTP client that will respond with the certificate
     $client = $this->getMockClient(new Response(200, null, $certificate));
     $validator = new MessageValidator($client);
     $message = new Message(new Collection(array('SigningCertURL' => 'https://sns.foo.amazonaws.com/bar.pem', 'Signature' => $signature)));
     $validator->validate($message);
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @return int
  */
 public function handleRequest(Request $request)
 {
     if (!$request->isMethod('POST')) {
         return 405;
     }
     try {
         $data = json_decode($request->getContent(), true);
         $message = Message::fromArray($data);
         $validator = new MessageValidator();
         $validator->validate($message);
     } catch (\Exception $e) {
         return 404;
         // not valid message, we return 404
     }
     if (isset($data['Message'])) {
         $message = json_decode($data['Message'], true);
         if (!is_null($message)) {
             if (isset($message['notificationType']) && $message['notificationType'] == self::MESSAGE_TYPE_SUBSCRIPTION_SUCCESS) {
                 return 200;
             }
             if (isset($message['notificationType']) && $message['notificationType'] == self::MESSAGE_TYPE_BOUNCE) {
                 foreach ($message['bounce']['bouncedRecipients'] as $bounceRecipient) {
                     $email = $bounceRecipient['emailAddress'];
                     $bounce = $this->repo->findBounceByEmail($email);
                     if ($bounce instanceof Bounce) {
                         $bounce->incrementBounceCounter();
                         $bounce->setLastTimeBounce(new \DateTime());
                         $bounce->setPermanent($message['bounce']['bounceType'] == 'Permanent');
                     } else {
                         $bounce = new Bounce($email, new \DateTime(), 1, $message['bounce']['bounceType'] == 'Permanent');
                     }
                     $this->repo->save($bounce);
                 }
                 return 200;
             }
         }
     }
     return 404;
 }