Skip to content

Commit a51483f

Browse files
committed
Create a standard Message object from a Lambda style Message when validating.
1 parent 87706c3 commit a51483f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/MessageValidator.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ class MessageValidator
2727
private static $defaultHostPattern
2828
= '/^sns\.[a-zA-Z0-9\-]{3,}\.amazonaws\.com(\.cn)?$/';
2929

30+
private static function isLambdaStyle(Message $message)
31+
{
32+
return isset($message['SigningCertUrl']);
33+
}
34+
35+
private static function convertLambdaMessage(Message $lambdaMessage)
36+
{
37+
$keyReplacements = [
38+
'SigningCertUrl' => 'SigningCertURL',
39+
'SubscribeUrl' => 'SubscribeURL',
40+
'UnsubscribeUrl' => 'UnsubscribeURL',
41+
];
42+
43+
$message = clone $lambdaMessage;
44+
foreach ($keyReplacements as $lambdaKey => $canonicalKey) {
45+
if (isset($message[$lambdaKey])) {
46+
$message[$canonicalKey] = $message[$lambdaKey];
47+
unset($message[$lambdaKey]);
48+
}
49+
}
50+
51+
return $message;
52+
}
53+
3054
/**
3155
* Constructs the Message Validator object and ensures that openssl is
3256
* installed.
@@ -55,6 +79,10 @@ public function __construct(
5579
*/
5680
public function validate(Message $message)
5781
{
82+
if (self::isLambdaStyle($message)) {
83+
$message = self::convertLambdaMessage($message);
84+
}
85+
5886
// Get the certificate.
5987
$this->validateUrl($message['SigningCertURL']);
6088
$certificate = call_user_func($this->certClient, $message['SigningCertURL']);

0 commit comments

Comments
 (0)