Skip to content

Commit 3b5ee9c

Browse files
committed
Add tests for endpoint padding
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 759f85a commit 3b5ee9c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/notification/notification_method_webpush_test.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,47 @@ public function test_prune_notifications($notification_type, $post_data, $expect
651651
$this->assertCount(0, $cur_notifications, 'Assert that no notifications have been pruned');
652652
}
653653

654+
public function data_set_endpoint_padding(): array
655+
{
656+
return [
657+
[
658+
'foo.mozilla.com',
659+
webpush::MOZILLA_FALLBACK_PADDING
660+
],
661+
[
662+
'foo.mozaws.net',
663+
webpush::MOZILLA_FALLBACK_PADDING
664+
],
665+
[
666+
'foo.android.googleapis.com',
667+
\Minishlink\WebPush\Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH,
668+
],
669+
];
670+
}
671+
672+
/**
673+
* @dataProvider data_set_endpoint_padding
674+
*/
675+
public function test_set_endpoint_padding($endpoint, $expected_padding): void
676+
{
677+
$web_push_reflection = new \ReflectionMethod($this->notification_method_webpush, 'set_endpoint_padding');
678+
$web_push_reflection->setAccessible(true);
679+
680+
$auth = [
681+
'VAPID' => [
682+
'subject' => generate_board_url(),
683+
'publicKey' => $this->config['wpn_webpush_vapid_public'],
684+
'privateKey' => $this->config['wpn_webpush_vapid_private'],
685+
],
686+
];
687+
688+
$web_push = new \Minishlink\WebPush\WebPush($auth);
689+
690+
$this->assertEquals(\Minishlink\WebPush\Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH, $web_push->getAutomaticPadding());
691+
$web_push_reflection->invoke($this->notification_method_webpush, $web_push, $endpoint);
692+
$this->assertEquals($expected_padding, $web_push->getAutomaticPadding());
693+
}
694+
654695
protected function create_subscription_for_user($user_id, bool $invalidate_endpoint = false): array
655696
{
656697
$client = new \GuzzleHttp\Client();

0 commit comments

Comments
 (0)