Skip to content

Commit

Permalink
fix(push): Use fallback keys that look like a real one
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>

[skip ci]
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Oct 21, 2024
1 parent aa17c3e commit 43b51e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Security\ISecureRandom;
use OCP\UserStatus\IManager as IUserStatusManager;
use OCP\UserStatus\IUserStatus;
use OCP\Util;
Expand Down Expand Up @@ -474,7 +475,11 @@ protected function sendNotificationsToProxies(): void {
if ($subscriptionAwareServer === 'https://push-notifications.nextcloud.com') {
$subscriptionKey = $this->config->getAppValue('support', 'subscription_key');
} else {
$subscriptionKey = $this->config->getSystemValueString('instanceid');
$subscriptionKey = $this->config->getAppValue(Application::APP_ID, 'push_subscription_key');
if ($subscriptionKey === '') {
$subscriptionKey = $this->createPushSubscriptionKey();
$this->config->setAppValue(Application::APP_ID, 'push_subscription_key', $subscriptionKey);
}
}

$client = $this->clientService->newClient();
Expand Down Expand Up @@ -781,4 +786,9 @@ protected function deletePushTokenByDeviceIdentifier(string $deviceIdentifier):
protected function createFakeUserObject(string $userId): IUser {
return new FakeUser($userId);
}

protected function createPushSubscriptionKey(): string {
$key = $this->random->generate(25, ISecureRandom::CHAR_ALPHANUMERIC);
return implode('-', str_split($key, 5));
}
}
3 changes: 3 additions & 0 deletions tests/Unit/PushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\L10N\IFactory;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Security\ISecureRandom;
use OCP\UserStatus\IManager as IUserStatusManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -78,6 +79,7 @@ protected function setUp(): void {
$this->userStatusManager = $this->createMock(IUserStatusManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->cacheFactory->method('createDistributed')
Expand All @@ -103,6 +105,7 @@ protected function getPush(array $methods = []) {
$this->userStatusManager,
$this->l10nFactory,
$this->timeFactory,
$this->random,
$this->logger,
])
->setMethods($methods)
Expand Down

0 comments on commit 43b51e9

Please sign in to comment.