Skip to content

Commit 83ee6c9

Browse files
committed
make sure the record size is <= 4078 bytes
1 parent 88f8dbf commit 83ee6c9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/WebPush.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function sendNotification($endpoint, $payload = null, $userPublicKey = nu
8282
throw new \ErrorException('The API has changed: sendNotification now takes the optional user auth token as parameter.');
8383
}
8484

85+
if(isset($payload) && strlen($payload) > 4078) {
86+
throw new \ErrorException('Size of payload must not be greater than 4078 octets.');
87+
}
88+
8589
// sort notification by server type
8690
$type = $this->sortEndpoint($endpoint);
8791
$this->notificationsByServerType[$type][] = new Notification($endpoint, $payload, $userPublicKey, $userAuthToken);

tests/WebPushTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public function testSendNotificationWithOldAPI()
8383
);
8484
}
8585

86+
public function testSendNotificationWithTooBigPayload()
87+
{
88+
$this->setExpectedException('ErrorException', 'Size of payload must not be greater than 4078 octets.');
89+
$this->webPush->sendNotification(
90+
$this->endpoints['standard'],
91+
str_repeat('test', 1020),
92+
$this->keys['standard'],
93+
null,
94+
true
95+
);
96+
}
97+
8698
public function testSendNotifications()
8799
{
88100
foreach($this->endpoints as $endpoint) {

0 commit comments

Comments
 (0)