Skip to content

Commit

Permalink
fix(push): Make testing the push server easier
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 10, 2024
1 parent 2881c0c commit 79f3c56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ protected function sendNotificationsToProxies(): void {
return;
}

$subscriptionAwareServer = rtrim($this->config->getAppValue(Application::APP_ID, 'subscription_aware_server', 'https://push-notifications.nextcloud.com'), '/');
if ($subscriptionAwareServer === 'https://push-notifications.nextcloud.com') {
$subscriptionKey = $this->config->getAppValue('support', 'subscription_key');
} else {
$subscriptionKey = $this->config->getSystemValueString('instanceid');
}

$client = $this->clientService->newClient();
foreach ($pushNotifications as $proxyServer => $notifications) {
try {
Expand All @@ -431,11 +438,8 @@ protected function sendNotificationsToProxies(): void {
],
];

if ($proxyServer === 'https://push-notifications.nextcloud.com') {
$subscriptionKey = $this->config->getAppValue('support', 'subscription_key');
if ($subscriptionKey) {
$requestData['headers']['X-Nextcloud-Subscription-Key'] = $subscriptionKey;
}
if ($subscriptionKey !== '' && $proxyServer === $subscriptionAwareServer) {
$requestData['headers']['X-Nextcloud-Subscription-Key'] = $subscriptionKey;
}

$response = $client->post($proxyServer . '/notifications', $requestData);
Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/PushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ public function testPushToDeviceSending(bool $isDebug): void {
->with('debug', false)
->willReturn($isDebug);

$this->config
->method('getAppValue')
->willReturnMap([
['notifications', 'subscription_aware_server', 'https://push-notifications.nextcloud.com', 'https://push-notifications.nextcloud.com'],
['support', 'subscription_key', '', ''],
]);

$this->l10nFactory
->method('getUserLanguage')
->with($user)
Expand Down Expand Up @@ -759,6 +766,13 @@ public function testPushToDeviceTalkNotification(array $deviceTypes, bool $isTal
->with('has_internet_connection', true)
->willReturn(true);

$this->config
->method('getAppValue')
->willReturnMap([
['notifications', 'subscription_aware_server', 'https://push-notifications.nextcloud.com', 'https://push-notifications.nextcloud.com'],
['support', 'subscription_key', '', ''],
]);

$this->notificationManager->method('isFairUseOfFreePushService')
->willReturn(true);

Expand Down

0 comments on commit 79f3c56

Please sign in to comment.