mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Merge pull request #46 from Octol1ttle/add-new-username-to-uuid-endpoint
update: add new username->UUID endpoint
This commit is contained in:
		@@ -48,6 +48,7 @@ return [
 | 
			
		||||
    'POST /mojang/profiles' => 'mojang/api/uuids-by-usernames',
 | 
			
		||||
    'GET /mojang/services/minecraft/profile' => 'mojang/services/profile',
 | 
			
		||||
    'POST /mojang/services/minecraft/profile/lookup/bulk/byname' => 'mojang/api/uuids-by-usernames',
 | 
			
		||||
    'GET /mojang/services/minecraft/profile/lookup/name/<username>' => 'mojang/api/uuid-by-username',
 | 
			
		||||
 | 
			
		||||
    // authlib-injector
 | 
			
		||||
    '/authlib-injector/authserver/<action>' => 'authserver/authentication/<action>',
 | 
			
		||||
@@ -56,4 +57,5 @@ return [
 | 
			
		||||
    '/authlib-injector/sessionserver/session/minecraft/profile/<uuid>' => 'session/session/profile',
 | 
			
		||||
    '/authlib-injector/api/profiles/minecraft' => 'mojang/api/uuids-by-usernames',
 | 
			
		||||
    '/authlib-injector/sessionserver/session/minecraft/profile/lookup/bulk/byname' => 'mojang/api/uuids-by-usernames',
 | 
			
		||||
    '/authlib-injector/minecraftservices/minecraft/profile/lookup/name/<username>' => 'mojang/api/uuid-by-username',
 | 
			
		||||
];
 | 
			
		||||
 
 | 
			
		||||
@@ -3,11 +3,6 @@ namespace api\tests\_pages;
 | 
			
		||||
 | 
			
		||||
class MojangApiRoute extends BasePage {
 | 
			
		||||
 | 
			
		||||
    public function usernameToUuid($username, $at = null): void {
 | 
			
		||||
        $params = $at === null ? [] : ['at' => $at];
 | 
			
		||||
        $this->getActor()->sendGET("/api/mojang/profiles/{$username}", $params);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function usernamesByUuid($uuid): void {
 | 
			
		||||
        $this->getActor()->sendGET("/api/mojang/profiles/{$uuid}/names");
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,24 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace api\tests\functional\mojang;
 | 
			
		||||
 | 
			
		||||
use api\tests\_pages\MojangApiRoute;
 | 
			
		||||
use api\tests\FunctionalTester;
 | 
			
		||||
use Codeception\Example;
 | 
			
		||||
 | 
			
		||||
class UsernameToUuidCest {
 | 
			
		||||
 | 
			
		||||
    private MojangApiRoute $route;
 | 
			
		||||
 | 
			
		||||
    public function _before(FunctionalTester $I): void {
 | 
			
		||||
        $this->route = new MojangApiRoute($I);
 | 
			
		||||
    public static function endpoints(): array {
 | 
			
		||||
        return [
 | 
			
		||||
            ['/api/mojang/profiles'],
 | 
			
		||||
            ['/api/mojang/services/minecraft/profile/lookup/name'],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidByUsername(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidByUsername(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get user uuid by his username');
 | 
			
		||||
        $this->route->usernameToUuid('Admin');
 | 
			
		||||
        $I->sendGET("{$url[0]}/Admin");
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseIsJson();
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
@@ -23,9 +27,12 @@ class UsernameToUuidCest {
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidByUsernameAtMoment(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidByUsernameAtMoment(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get user uuid by his username at fixed moment');
 | 
			
		||||
        $this->route->usernameToUuid('klik201', 1474404142);
 | 
			
		||||
        $I->sendGET("{$url[0]}/klik201", ['at' => 1474404142]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(200);
 | 
			
		||||
        $I->canSeeResponseIsJson();
 | 
			
		||||
        $I->canSeeResponseContainsJson([
 | 
			
		||||
@@ -34,37 +41,52 @@ class UsernameToUuidCest {
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidByUsernameAtWrongMoment(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidByUsernameAtWrongMoment(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get 204 if passed once used, but changed username at moment, when it was changed');
 | 
			
		||||
        $this->route->usernameToUuid('klik201', 1474404144);
 | 
			
		||||
        $I->sendGET("{$url[0]}/klik201", ['at' => 1474404144]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(204);
 | 
			
		||||
        $I->canSeeResponseEquals('');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidByUsernameWithoutMoment(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidByUsernameWithoutMoment(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get 204 if username not busy and not passed valid time mark, when it was busy');
 | 
			
		||||
        $this->route->usernameToUuid('klik201');
 | 
			
		||||
        $I->sendGET("{$url[0]}/klik201");
 | 
			
		||||
        $I->canSeeResponseCodeIs(204);
 | 
			
		||||
        $I->canSeeResponseEquals('');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidByWrongUsername(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidByWrongUsername(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get user uuid by some wrong username');
 | 
			
		||||
        $this->route->usernameToUuid('not-exists-user');
 | 
			
		||||
        $I->sendGET("{$url[0]}/not-exists-user");
 | 
			
		||||
        $I->canSeeResponseCodeIs(204);
 | 
			
		||||
        $I->canSeeResponseEquals('');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getUuidForDeletedAccount(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function getUuidForDeletedAccount(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get uuid for account that marked for deleting');
 | 
			
		||||
        $this->route->usernameToUuid('DeletedAccount');
 | 
			
		||||
        $I->sendGET("{$url[0]}/DeletedAccount");
 | 
			
		||||
        $I->canSeeResponseCodeIs(204);
 | 
			
		||||
        $I->canSeeResponseEquals('');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function nonPassedUsername(FunctionalTester $I): void {
 | 
			
		||||
    /**
 | 
			
		||||
     * @dataProvider endpoints
 | 
			
		||||
     */
 | 
			
		||||
    public function nonPassedUsername(FunctionalTester $I, Example $url): void {
 | 
			
		||||
        $I->wantTo('get 404 on not passed username');
 | 
			
		||||
        $this->route->usernameToUuid('');
 | 
			
		||||
        $I->sendGET($url[0]);
 | 
			
		||||
        $I->canSeeResponseCodeIs(404);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user