mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Completely restored authorization_code grant for user side.
Reworked oauth_sessions table. Added extension to use MariaDB's JSON columns. Rewritten tests for authorization_code grant for client side. Deprecate some old shit. [skip ci]
This commit is contained in:
		
							
								
								
									
										112
									
								
								api/tests/functional/dev/applications/CreateClientCest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								api/tests/functional/dev/applications/CreateClientCest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
			
		||||
<?php
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace api\tests\functional\dev\applications;
 | 
			
		||||
 | 
			
		||||
use api\tests\_pages\OauthRoute;
 | 
			
		||||
use api\tests\FunctionalTester;
 | 
			
		||||
 | 
			
		||||
class CreateClientCest {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var OauthRoute
 | 
			
		||||
     */
 | 
			
		||||
    private $route;
 | 
			
		||||
 | 
			
		||||
    public function _before(FunctionalTester $I) {
 | 
			
		||||
        $this->route = new OauthRoute($I);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateApplicationWithWrongParams(FunctionalTester $I) {
 | 
			
		||||
        $I->amAuthenticated('admin');
 | 
			
		||||
 | 
			
		||||
        $this->route->createClient('application', []);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
            'success' => false,
 | 
			
		||||
            'errors' => [
 | 
			
		||||
                'name' => 'error.name_required',
 | 
			
		||||
                'redirectUri' => 'error.redirectUri_required',
 | 
			
		||||
            ],
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $this->route->createClient('application', [
 | 
			
		||||
            'name' => 'my test oauth client',
 | 
			
		||||
            'redirectUri' => 'localhost',
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
            'success' => false,
 | 
			
		||||
            'errors' => [
 | 
			
		||||
                'redirectUri' => 'error.redirectUri_invalid',
 | 
			
		||||
            ],
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateApplication(FunctionalTester $I) {
 | 
			
		||||
        $I->amAuthenticated('admin');
 | 
			
		||||
        $this->route->createClient('application', [
 | 
			
		||||
            'name' => 'My admin application',
 | 
			
		||||
            'description' => 'Application description.',
 | 
			
		||||
            'redirectUri' => 'http://some-site.com/oauth/ely',
 | 
			
		||||
            'websiteUrl' => 'http://some-site.com',
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseIsJson();
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'data' => [
 | 
			
		||||
                'clientId' => 'my-admin-application',
 | 
			
		||||
                'name' => 'My admin application',
 | 
			
		||||
                'description' => 'Application description.',
 | 
			
		||||
                'websiteUrl' => 'http://some-site.com',
 | 
			
		||||
                'countUsers' => 0,
 | 
			
		||||
                'redirectUri' => 'http://some-site.com/oauth/ely',
 | 
			
		||||
            ],
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseJsonMatchesJsonPath('$.data.clientSecret');
 | 
			
		||||
        $I->canSeeResponseJsonMatchesJsonPath('$.data.createdAt');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateMinecraftServer(FunctionalTester $I) {
 | 
			
		||||
        $I->amAuthenticated('admin');
 | 
			
		||||
        $this->route->createClient('minecraft-server', [
 | 
			
		||||
            'name' => 'My amazing server',
 | 
			
		||||
            'websiteUrl' => 'http://some-site.com',
 | 
			
		||||
            'minecraftServerIp' => 'hypixel.com:25565',
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseIsJson();
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'data' => [
 | 
			
		||||
                'clientId' => 'my-amazing-server',
 | 
			
		||||
                'name' => 'My amazing server',
 | 
			
		||||
                'websiteUrl' => 'http://some-site.com',
 | 
			
		||||
                'minecraftServerIp' => 'hypixel.com:25565',
 | 
			
		||||
            ],
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseJsonMatchesJsonPath('$.data.clientSecret');
 | 
			
		||||
        $I->canSeeResponseJsonMatchesJsonPath('$.data.createdAt');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCreateApplicationWithTheSameNameAsDeletedApp(FunctionalTester $I) {
 | 
			
		||||
        $I->wantTo('create application with the same name as the recently deleted application');
 | 
			
		||||
        $I->amAuthenticated('admin');
 | 
			
		||||
        $this->route->createClient('application', [
 | 
			
		||||
            'name' => 'Deleted OAuth Client',
 | 
			
		||||
            'description' => '',
 | 
			
		||||
            'redirectUri' => 'http://some-site.com/oauth/ely',
 | 
			
		||||
            'websiteUrl' => 'http://some-site.com',
 | 
			
		||||
        ]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseIsJson();
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'data' => [
 | 
			
		||||
                'clientId' => 'deleted-oauth-client1',
 | 
			
		||||
            ],
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user