This commit is contained in:
ErickSkrauch 2023-11-20 02:16:44 +01:00
parent 574d03d02f
commit 2bc83f39cf
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
3 changed files with 43 additions and 46 deletions

View File

@ -11,4 +11,5 @@ class MojangApiRoute extends BasePage {
public function usernamesByUuid($uuid) { public function usernamesByUuid($uuid) {
$this->getActor()->sendGET("/api/mojang/profiles/{$uuid}/names"); $this->getActor()->sendGET("/api/mojang/profiles/{$uuid}/names");
} }
} }

View File

@ -11,8 +11,8 @@ final class MinecraftProfilesCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidByOneUsername(FunctionalTester $I, Example $url) : void { public function getUuidByOneUsername(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], ['Admin']); $I->sendPOST($case[0], ['Admin']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
[ [
@ -25,29 +25,27 @@ final class MinecraftProfilesCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByUsernames(FunctionalTester $I, Example $url) : void { public function getUuidsByUsernames(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], ['Admin', 'AccWithOldPassword', 'Notch']); $I->sendPOST($case[0], ['Admin', 'AccWithOldPassword', 'Notch']);
$this->validateFewValidUsernames($I); $this->validateFewValidUsernames($I);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByUsernamesWithPostString(FunctionalTester $I, Example $url) : void { public function getUuidsByUsernamesWithPostString(FunctionalTester $I, Example $case): void {
$I->sendPOST( $I->sendPOST(
$url[0], $case[0],
json_encode(['Admin', 'AccWithOldPassword', 'Notch']), json_encode(['Admin', 'AccWithOldPassword', 'Notch']),
); );
$this->validateFewValidUsernames($I); $this->validateFewValidUsernames($I);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByPartialNonexistentUsernames(FunctionalTester $I, Example $url) : void { public function getUuidsByPartialNonexistentUsernames(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], ['Admin', 'DeletedAccount', 'not-exists-user']); $I->sendPOST($case[0], ['Admin', 'DeletedAccount', 'not-exists-user']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
[ [
@ -59,28 +57,26 @@ final class MinecraftProfilesCest {
$I->cantSeeResponseJsonMatchesJsonPath('$.[?(@.name="not-exists-user")]'); $I->cantSeeResponseJsonMatchesJsonPath('$.[?(@.name="not-exists-user")]');
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passAllNonexistentUsernames(FunctionalTester $I, Example $url) : void { public function passAllNonexistentUsernames(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], ['not-exists-1', 'not-exists-2']); $I->sendPOST($case[0], ['not-exists-1', 'not-exists-2']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseEquals('[]'); $I->canSeeResponseEquals('[]');
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passTooManyUsernames(FunctionalTester $I, Example $url) : void { public function passTooManyUsernames(FunctionalTester $I, Example $case): void {
$usernames = []; $usernames = [];
for ($i = 0; $i < 150; $i++) { for ($i = 0; $i < 150; $i++) {
$usernames[] = random_bytes(10); $usernames[] = random_bytes(10);
} }
$I->sendPOST($url[0], $usernames); $I->sendPOST($case[0], $usernames);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
'error' => 'IllegalArgumentException', 'error' => 'IllegalArgumentException',
@ -88,12 +84,11 @@ final class MinecraftProfilesCest {
]); ]);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passEmptyUsername(FunctionalTester $I, Example $url) : void { public function passEmptyUsername(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], ['Admin', '']); $I->sendPOST($case[0], ['Admin', '']);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
'error' => 'IllegalArgumentException', 'error' => 'IllegalArgumentException',
@ -101,12 +96,11 @@ final class MinecraftProfilesCest {
]); ]);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passEmptyField(FunctionalTester $I, Example $url) : void { public function passEmptyField(FunctionalTester $I, Example $case): void {
$I->sendPOST($url[0], []); $I->sendPOST($case[0], []);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
'error' => 'IllegalArgumentException', 'error' => 'IllegalArgumentException',
@ -114,7 +108,7 @@ final class MinecraftProfilesCest {
]); ]);
} }
private function validateFewValidUsernames(FunctionalTester $I) : void { private function validateFewValidUsernames(FunctionalTester $I): void {
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -133,10 +127,10 @@ final class MinecraftProfilesCest {
]); ]);
} }
private function bulkProfilesEndpoints() : array { private function bulkProfilesEndpoints(): array {
return [ return [
["/api/authlib-injector/api/profiles/minecraft"], ['/api/authlib-injector/api/profiles/minecraft'],
["/api/authlib-injector/sessionserver/session/minecraft/profile/lookup/bulk/byname"] ['/api/authlib-injector/sessionserver/session/minecraft/profile/lookup/bulk/byname'],
]; ];
} }

View File

@ -5,12 +5,13 @@ use api\tests\FunctionalTester;
use Codeception\Example; use Codeception\Example;
class UsernamesToUuidsCest { class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidByOneUsername(FunctionalTester $I, Example $url) : void { public function getUuidByOneUsername(FunctionalTester $I, Example $case): void {
$I->wantTo('get uuid by one username'); $I->wantTo('get uuid by one username');
$I->sendPost($url[0], ['Admin']); $I->sendPost($case[0], ['Admin']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -24,27 +25,27 @@ class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByUsernames(FunctionalTester $I, Example $url) : void { public function getUuidsByUsernames(FunctionalTester $I, Example $case): void {
$I->wantTo('get uuids by few usernames'); $I->wantTo('get uuids by few usernames');
$I->sendPost($url[0], ['Admin', 'AccWithOldPassword', 'Notch']); $I->sendPost($case[0], ['Admin', 'AccWithOldPassword', 'Notch']);
$this->validateFewValidUsernames($I); $this->validateFewValidUsernames($I);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByUsernamesWithPostString(FunctionalTester $I, Example $url) : void { public function getUuidsByUsernamesWithPostString(FunctionalTester $I, Example $case): void {
$I->wantTo('get uuids by few usernames'); $I->wantTo('get uuids by few usernames');
$I->sendPost($url[0], json_encode(['Admin', 'AccWithOldPassword', 'Notch'])); $I->sendPost($case[0], json_encode(['Admin', 'AccWithOldPassword', 'Notch']));
$this->validateFewValidUsernames($I); $this->validateFewValidUsernames($I);
} }
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function getUuidsByPartialNonexistentUsernames(FunctionalTester $I, Example $url) : void { public function getUuidsByPartialNonexistentUsernames(FunctionalTester $I, Example $case): void {
$I->wantTo('get uuids by few usernames and some nonexistent'); $I->wantTo('get uuids by few usernames and some nonexistent');
$I->sendPost($url[0], ['Admin', 'DeletedAccount', 'not-exists-user']); $I->sendPost($case[0], ['Admin', 'DeletedAccount', 'not-exists-user']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -60,9 +61,9 @@ class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passAllNonexistentUsernames(FunctionalTester $I, Example $url) : void { public function passAllNonexistentUsernames(FunctionalTester $I, Example $case): void {
$I->wantTo('get specific response when pass all nonexistent usernames'); $I->wantTo('get specific response when pass all nonexistent usernames');
$I->sendPost($url[0], ['not-exists-1', 'not-exists-2']); $I->sendPost($case[0], ['not-exists-1', 'not-exists-2']);
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([]); $I->canSeeResponseContainsJson([]);
@ -71,14 +72,14 @@ class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passTooManyUsernames(FunctionalTester $I, Example $url) : void { public function passTooManyUsernames(FunctionalTester $I, Example $case): void {
$I->wantTo('get specific response when pass too many usernames'); $I->wantTo('get specific response when pass too many usernames');
$usernames = []; $usernames = [];
for ($i = 0; $i < 150; $i++) { for ($i = 0; $i < 150; $i++) {
$usernames[] = random_bytes(10); $usernames[] = random_bytes(10);
} }
$I->sendPost($url[0], $usernames); $I->sendPost($case[0], $usernames);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -90,9 +91,9 @@ class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passEmptyUsername(FunctionalTester $I, Example $url) : void { public function passEmptyUsername(FunctionalTester $I, Example $case): void {
$I->wantTo('get specific response when pass empty username'); $I->wantTo('get specific response when pass empty username');
$I->sendPost($url[0], ['Admin', '']); $I->sendPost($case[0], ['Admin', '']);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -104,9 +105,9 @@ class UsernamesToUuidsCest {
/** /**
* @dataProvider bulkProfilesEndpoints * @dataProvider bulkProfilesEndpoints
*/ */
public function passEmptyField(FunctionalTester $I, Example $url) : void { public function passEmptyField(FunctionalTester $I, Example $case): void {
$I->wantTo('get response when pass empty array'); $I->wantTo('get response when pass empty array');
$I->sendPost($url[0], []); $I->sendPost($case[0], []);
$I->canSeeResponseCodeIs(400); $I->canSeeResponseCodeIs(400);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -115,7 +116,7 @@ class UsernamesToUuidsCest {
]); ]);
} }
private function validateFewValidUsernames(FunctionalTester $I) : void { private function validateFewValidUsernames(FunctionalTester $I): void {
$I->canSeeResponseCodeIs(200); $I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson(); $I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([ $I->canSeeResponseContainsJson([
@ -134,10 +135,11 @@ class UsernamesToUuidsCest {
]); ]);
} }
private function bulkProfilesEndpoints() : array { private function bulkProfilesEndpoints(): array {
return [ return [
["/api/authlib-injector/api/profiles/minecraft"], ['/api/authlib-injector/api/profiles/minecraft'],
["/api/authlib-injector/sessionserver/session/minecraft/profile/lookup/bulk/byname"] ['/api/authlib-injector/sessionserver/session/minecraft/profile/lookup/bulk/byname'],
]; ];
} }
} }