mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Merge branch 'authorized_clients_management'
This commit is contained in:
40
api/tests/functional/accounts/GetAuthorizedClientsCest.php
Normal file
40
api/tests/functional/accounts/GetAuthorizedClientsCest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\functional\accounts;
|
||||
|
||||
use api\tests\FunctionalTester;
|
||||
|
||||
class GetAuthorizedClientsCest {
|
||||
|
||||
public function testGet(FunctionalTester $I) {
|
||||
$id = $I->amAuthenticated('admin');
|
||||
$I->sendGET("/api/v1/accounts/{$id}/oauth2/authorized");
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
[
|
||||
'id' => 'test1',
|
||||
'name' => 'Test1',
|
||||
'description' => 'Some description',
|
||||
'scopes' => ['minecraft_server_session', 'obtain_own_account_info'],
|
||||
'authorizedAt' => 1479944472,
|
||||
'lastUsedAt' => 1479944472,
|
||||
],
|
||||
]);
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.[?(@.id="tlauncher")]');
|
||||
}
|
||||
|
||||
public function testGetForNotOwnIdentity(FunctionalTester $I) {
|
||||
$I->amAuthenticated('admin');
|
||||
$I->sendGET('/api/v1/accounts/2/oauth2/authorized');
|
||||
$I->canSeeResponseCodeIs(403);
|
||||
$I->canSeeResponseContainsJson([
|
||||
'name' => 'Forbidden',
|
||||
'message' => 'You are not allowed to perform this action.',
|
||||
'code' => 0,
|
||||
'status' => 403,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
45
api/tests/functional/accounts/RevokeAuthorizedClientCest.php
Normal file
45
api/tests/functional/accounts/RevokeAuthorizedClientCest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\functional\accounts;
|
||||
|
||||
use api\tests\FunctionalTester;
|
||||
|
||||
class RevokeAuthorizedClientCest {
|
||||
|
||||
public function testRevokeAuthorizedClient(FunctionalTester $I) {
|
||||
$id = $I->amAuthenticated('admin');
|
||||
$I->sendDELETE("/api/v1/accounts/{$id}/oauth2/authorized/test1");
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$I->sendGET("/api/v1/accounts/{$id}/oauth2/authorized");
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.[?(@.id="test1")]');
|
||||
}
|
||||
|
||||
public function testRevokeAlreadyRevokedClient(FunctionalTester $I) {
|
||||
$id = $I->amAuthenticated('admin');
|
||||
$I->sendDELETE("/api/v1/accounts/{$id}/oauth2/authorized/tlauncher");
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testRevokeForNotOwnIdentity(FunctionalTester $I) {
|
||||
$I->amAuthenticated('admin');
|
||||
$I->sendDELETE('/api/v1/accounts/2/oauth2/authorized/test1');
|
||||
$I->canSeeResponseCodeIs(403);
|
||||
$I->canSeeResponseContainsJson([
|
||||
'name' => 'Forbidden',
|
||||
'message' => 'You are not allowed to perform this action.',
|
||||
'code' => 0,
|
||||
'status' => 403,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,9 @@ namespace api\tests\unit\modules\accounts\models;
|
||||
|
||||
use api\modules\accounts\models\DeleteAccountForm;
|
||||
use api\tests\unit\TestCase;
|
||||
use Codeception\Util\ReflectionHelper;
|
||||
use common\models\Account;
|
||||
use common\notifications\AccountEditNotification;
|
||||
use common\tasks\CreateWebHooksDeliveries;
|
||||
use common\tasks\DeleteAccount;
|
||||
use common\tests\fixtures\AccountFixture;
|
||||
@@ -46,7 +48,12 @@ class DeleteAccountFormTest extends TestCase {
|
||||
->method('push')
|
||||
->withConsecutive(
|
||||
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
||||
$this->assertSame($account->id, $task->payloads['id']);
|
||||
/** @var AccountEditNotification $notification */
|
||||
$notification = ReflectionHelper::readPrivateProperty($task, 'notification');
|
||||
$this->assertInstanceOf(AccountEditNotification::class, $notification);
|
||||
$this->assertSame($account->id, $notification->getPayloads()['id']);
|
||||
$this->assertTrue($notification->getPayloads()['isDeleted']);
|
||||
|
||||
return true;
|
||||
})],
|
||||
[$this->callback(function(DeleteAccount $task) use ($account): bool {
|
||||
|
||||
@@ -5,7 +5,9 @@ namespace api\tests\unit\modules\accounts\models;
|
||||
|
||||
use api\modules\accounts\models\RestoreAccountForm;
|
||||
use api\tests\unit\TestCase;
|
||||
use Codeception\Util\ReflectionHelper;
|
||||
use common\models\Account;
|
||||
use common\notifications\AccountEditNotification;
|
||||
use common\tasks\CreateWebHooksDeliveries;
|
||||
use common\tests\fixtures\AccountFixture;
|
||||
use Yii;
|
||||
@@ -39,7 +41,12 @@ class RestoreAccountFormTest extends TestCase {
|
||||
->method('push')
|
||||
->withConsecutive(
|
||||
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
||||
$this->assertSame($account->id, $task->payloads['id']);
|
||||
/** @var AccountEditNotification $notification */
|
||||
$notification = ReflectionHelper::readPrivateProperty($task, 'notification');
|
||||
$this->assertInstanceOf(AccountEditNotification::class, $notification);
|
||||
$this->assertSame($account->id, $notification->getPayloads()['id']);
|
||||
$this->assertFalse($notification->getPayloads()['isDeleted']);
|
||||
|
||||
return true;
|
||||
})],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user