mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-18 10:52:27 +00:00
3513c642dd
Creates a new push-subscription-manager group and an associated right, manage-all-push-subscriptions. The purpose of this is to allow privileged accounts to purge expired subscriptions from the database on behalf of other users. A user with this right will be permitted to delete any subscription from the DB based on the token alone. For all other users, deletion requests will be limited to those associated with the requesting user's central ID. This right will be granted to a bot account on Metawiki associated with the Wikimedia push notifications service, and the push notifications service account will make push subscription delete requests to the API for subscriptions for which vendor APIs return bad subscription responses. Additionally, the providertoken parameter to ApiPushSubscriptionDelete is updated to allow multiple providertoken values. Bug: T259148 Change-Id: Ia6c17588ee94e6be74e5e3a75eb33e38f172fc93
86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
|
|
use EchoPush\Utils;
|
|
|
|
/**
|
|
* @group medium
|
|
* @group API
|
|
* @group Database
|
|
* @covers \EchoPush\Api\ApiEchoPushSubscriptionsCreate
|
|
*/
|
|
class ApiEchoPushSubscriptionsCreateTest extends ApiTestCase {
|
|
|
|
/** @var User */
|
|
private $user;
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
$this->setMwGlobals( [
|
|
'wgEchoEnablePush' => true,
|
|
'wgEchoPushMaxSubscriptionsPerUser' => 2
|
|
] );
|
|
$this->tablesUsed[] = 'echo_push_subscription';
|
|
$this->tablesUsed[] = 'echo_push_provider';
|
|
$this->user = $this->getTestUser()->getUser();
|
|
$this->createTestData();
|
|
}
|
|
|
|
public function testApiCreateSubscription(): void {
|
|
// Before max subscriptions reached
|
|
$params = [
|
|
'action' => 'echopushsubscriptions',
|
|
'command' => 'create',
|
|
'provider' => 'fcm',
|
|
'providertoken' => 'ABC123',
|
|
];
|
|
$result = $this->doApiRequestWithToken( $params, null, $this->user );
|
|
$this->assertEquals( 'Success', $result[0]['create']['result'] );
|
|
|
|
// After max subscriptions reached
|
|
$params['providertoken'] = 'DEF456';
|
|
$this->expectException( ApiUsageException::class );
|
|
$this->doApiRequestWithToken( $params, null, $this->user );
|
|
}
|
|
|
|
public function testApiCreateSubscriptionTokenExists(): void {
|
|
$params = [
|
|
'action' => 'echopushsubscriptions',
|
|
'command' => 'create',
|
|
'provider' => 'fcm',
|
|
'providertoken' => 'XYZ789',
|
|
];
|
|
$this->expectException( ApiUsageException::class );
|
|
$this->doApiRequestWithToken( $params, null, $this->user );
|
|
}
|
|
|
|
public function testApiCreateApnsSubscriptionWithTopic(): void {
|
|
$params = [
|
|
'action' => 'echopushsubscriptions',
|
|
'command' => 'create',
|
|
'provider' => 'apns',
|
|
'providertoken' => 'ABC123',
|
|
'topic' => 'test',
|
|
];
|
|
$result = $this->doApiRequestWithToken( $params, null, $this->user );
|
|
$this->assertEquals( 'Success', $result[0]['create']['result'] );
|
|
}
|
|
|
|
public function testApiCreateApnsSubscriptionWithoutTopic(): void {
|
|
$params = [
|
|
'action' => 'echopushsubscriptions',
|
|
'command' => 'create',
|
|
'provider' => 'apns',
|
|
'providertoken' => 'DEF456',
|
|
];
|
|
$this->expectException( ApiUsageException::class );
|
|
$this->doApiRequestWithToken( $params, null, $this->user );
|
|
}
|
|
|
|
private function createTestData(): void {
|
|
$subscriptionManager = EchoServices::getInstance()->getPushSubscriptionManager();
|
|
$userId = Utils::getPushUserId( $this->user );
|
|
$subscriptionManager->create( 'fcm', 'XYZ789', $userId );
|
|
}
|
|
|
|
}
|