Skip to content

Commit c5df91e

Browse files
authored
Merge pull request #53 from iMattPro/fixes
Trivial updates
2 parents a928ae5 + a14a3b7 commit c5df91e

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ Testing push notifications necessitates user-to-user interactions to observe the
3737

3838
1. **User Account Setup:**
3939
- Create at least two distinct user accounts for testing purposes.
40-
- In each user account's notifications preferences, assign web push notifications and subscribe to them to receive Push Notifications.
40+
- In user1's account notifications preferences, assign web push notifications and subscribe to receive Push Notifications.
4141

4242
2. **Message, Quote, or Reply Interaction:**
43-
- Initiate a user-to-user interaction by performing one of the following actions using "User Account 1":
44-
- **Private Message:** Send a direct message from "User Account 1" to "User Account 2".
45-
- **Quote:** Quote a post or message authored by "User Account 2" using "User Account 1".
46-
- **Reply:** Respond to a post or message authored by "User Account 2" using "User Account 1".
43+
- Initiate a user-to-user interaction by performing one of the following actions using "User Account 2":
44+
- **Private Message:** Send a direct message from "User Account 2" to "User Account 1".
45+
- **Quote:** Quote a post or message authored by "User Account 1" using "User Account 2".
46+
- **Reply:** Respond to a post or message authored by "User Account 1" using "User Account 2".
4747

4848
3. **Observing Push Notifications:**
49-
- Once the interaction is performed from "User Account 1" to engage with "User Account 2," you promptly should see a notification for "User Account 2."
49+
- Once the interaction is performed from "User Account 2" to engage with "User Account 1," you promptly should see a notification for "User Account 1."
5050

5151
4. **Caveats for Local Testing**
5252
- Local testing of Push Notifications only works from a `localhost` address or if your local server has a secure SSL certificate.

notification/method/webpush.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,19 @@ protected function get_board_url()
495495
* @param string $endpoint
496496
*
497497
* @return void
498-
* @throws \Exception
499498
*/
500499
protected function set_endpoint_padding(\Minishlink\WebPush\WebPush $web_push, string $endpoint): void
501500
{
502501
if (strpos($endpoint, 'mozilla.com') || strpos($endpoint, 'mozaws.net'))
503502
{
504-
$web_push->setAutomaticPadding(self::MOZILLA_FALLBACK_PADDING);
503+
try
504+
{
505+
$web_push->setAutomaticPadding(self::MOZILLA_FALLBACK_PADDING);
506+
}
507+
catch (\Exception $e)
508+
{
509+
// This shouldn't happen since we won't pass padding length outside limits
510+
}
505511
}
506512
}
507513
}

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)