/**
  * Processes message from SNS
  *
  * @throws Exception
  */
 function process_message()
 {
     $this->_log('Received message');
     try {
         $message = \Message::fromRawPostData();
         $validator = new \MessageValidator();
         $error = '';
         if ($validator->isValid($message)) {
             $topic_arn = $this->_config->get_string('cluster.messagebus.sns.topic_arn');
             if (empty($topic_arn) || $topic_arn != $message->get('TopicArn')) {
                 throw new \Exception('Not my Topic. Request came from ' . $message->get('TopicArn'));
             }
             if ($message->get('Type') == 'SubscriptionConfirmation') {
                 $this->_subscription_confirmation($message);
             } elseif ($message->get('Type') == 'Notification') {
                 $this->_notification($message->get('Message'));
             }
         } else {
             $this->_log('Error processing message it was not valid.');
         }
     } catch (\Exception $e) {
         $this->_log('Error processing message: ' . $e->getMessage());
     }
     $this->_log('Message processed');
 }
 public function testValidateSucceedsWhenMessageIsValid()
 {
     $validator = new MessageValidator($this->getMockCertServerClient());
     $message = $this->getTestMessage();
     // Get the signature for a real message
     $message['Signature'] = $this->getSignature($validator->getStringToSign($message));
     // The message should validate
     $this->assertTrue($validator->isValid($message));
 }
Ejemplo n.º 3
0
 /**
  * Processes message from SNS
  *
  * @throws Exception
  */
 function process_message()
 {
     $this->_log('Received message');
     try {
         $message = Message::fromRawPostData();
         $validator = new MessageValidator();
         $error = '';
         if ($validator->isValid($message)) {
             if ($message->get('Type') == 'SubscriptionConfirmation') {
                 $this->_subscription_confirmation($message);
             } else {
                 if ($message->get('Type') == 'Notification') {
                     $this->_notification($message->get('Message'));
                 }
             }
         } else {
             $this->_log('Error processing message it was not valid.');
         }
     } catch (Exception $e) {
         $this->_log('Error processing message: ' . $e->getMessage());
     }
     $this->_log('Message processed');
 }