Skip to content

Commit a4bf323

Browse files
committed
User auth token must be provided if sending payload
+ fix JSON test
1 parent bd16be7 commit a4bf323

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/WebPush.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ private function prepareAndSend(array $notifications, $serverType)
195195
$endpoint = $notification->getEndpoint();
196196
$payload = $notification->getPayload();
197197
$userPublicKey = $notification->getUserPublicKey();
198+
$userAuthToken = $notification->getUserAuthToken();
198199

199-
if (isset($payload) && isset($userPublicKey) && ($this->payloadEncryptionSupport || $this->nativePayloadEncryptionSupport)) {
200-
$encrypted = Encryption::encrypt($payload, $userPublicKey, $notification->getUserAuthToken(), $this->nativePayloadEncryptionSupport);
200+
if (isset($payload) && isset($userPublicKey) && isset($userAuthToken) && ($this->payloadEncryptionSupport || $this->nativePayloadEncryptionSupport)) {
201+
$encrypted = Encryption::encrypt($payload, $userPublicKey, $userAuthToken, $this->nativePayloadEncryptionSupport);
201202

202203
$headers = array(
203204
'Content-Length' => strlen($encrypted['cipherText']),

tests/WebPushTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ public function notificationProvider()
4949
self::setUpBeforeClass(); // dirty hack of PHPUnit limitation
5050
return array(
5151
array(self::$endpoints['standard'], null, null, null),
52-
array(self::$endpoints['standard'], '{message: "Plop", tag: "general"}', self::$keys['standard'], self::$tokens['standard']),
53-
array(self::$endpoints['standard'], '{message: "Plop", tag: "general"}', self::$keys['standard'], null),
52+
array(self::$endpoints['standard'], '{"message":"Plop","tag":"general"}', self::$keys['standard'], self::$tokens['standard']),
5453
array(self::$endpoints['GCM'], null, null, null),
55-
array(self::$endpoints['GCM'], '{message: "Plop", tag: "general"}', self::$keys['GCM'], self::$tokens['GCM']),
56-
array(self::$endpoints['GCM'], '{message: "Plop", tag: "general"}', self::$keys['GCM'], null),
54+
array(self::$endpoints['GCM'], '{"message":"Plop","tag":"general"}', self::$keys['GCM'], self::$tokens['GCM']),
5755
);
5856
}
5957

@@ -74,7 +72,7 @@ public function testSendNotification($endpoint, $payload, $userPublicKey, $userA
7472

7573
public function testSendNotificationWithOldAPI()
7674
{
77-
$this->setExpectedException('ErrorException', 'The API has changed: sendNotification now takes the optional user auth token as parameter.');
75+
$this->setExpectedException('ErrorException', 'The API has changed: sendNotification now takes the user auth token as parameter.');
7876
$this->webPush->sendNotification(
7977
self::$endpoints['standard'],
8078
'test',

0 commit comments

Comments
 (0)