Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(push): Make testing the push server easier
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Oct 22, 2024
commit 4c672dbc75a8ca85e95632c3ee370051a5a232b3
14 changes: 9 additions & 5 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,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 @@ -491,11 +498,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 @@ -513,6 +513,13 @@ public function testPushToDeviceSending($isDebug) {
->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 @@ -821,6 +828,13 @@ public function testPushToDeviceTalkNotification(array $deviceTypes, $isTalkNoti
->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